Pending order Stop Loss changes when it fills
-
Everything else works perfectly, so no clue if this is a bug or I coded it wrong, but when I have two pending orders (a buy pending order for group 1 and a buy pending order for group 2), I set their SL as different variables and they are correct when I look at MT4. Both of the buy pending orders have different fill prices, and different SLs, which are correct in MT4. When the group 1 order fills, it has the right price and right SL, but when the group 2 order fills later (because it is at a different price), the price is right, but the SL for the group 2 order changes to match the SL for the group 1 order. There are no adjustments to the SL for either filled orders for many days after after they fill, so I cannot figure out why the group 2 SL seems to change to the group 1 SL. (Same thing happens with sell pending orders, meaning a second sell pending order will fill but change to match the SL of the first sell pending order).
I saw a similar post about this (https://fxdreema.com/forum/topic/16217/position-created-block-with-failure/22) but I don't know if it was fixed.
Any ideas?
-
Share your project to see what's happening and why.
-




-
Everything is organized by group (1, 2, 3, and 4.) 21H is for group 1 and 52H is for group 2. The only thing I could think of is that the SL variable wasn't updating because it was an "order created" and not a "trade created", but ether one separately or together (as shown) don't fix the issue. I'm stumped.
-
Share a link rather than pictures, I assume under the switched off blocks nothing happens?
-
correct, the switched on/off blocks just dictate when a pending order can be created (and only happens once a day) so it shouldn't have any affect on the SL for a pending order that fills. sent you a link to the project and just bought your book! can't wait to read it.
-
Are you connecting your buy/sell now blocks to the grey output dot of those pending order blocks for any special reason?
-
Hi @l-andorrà ! Yes, because if for some reason the pending order is created too close to the current price or there is an error, it might not be allowed to be created, in which case I want it to open a buy/sell now market order.
-
If this helps..

-
@MTAB Good for you!

-
ok, I even tried to modify the stop loss AFTER the trade was executed, save it to the SL variable and it still has the same stop loss as the original (first) trade! It's driving me nuts!


-
@fxDreema Can you please help and see if this is a bug?
-
Add your latest shared project
-
Add a shared project not just pictures, and correct your block ID numbers, blocks will activate with the lowest number first, but flow in a line regardless of the next numbers
-
Below is a link to the latest version trying to correct the SL issue. Am I correct in assuming that the block ID order shouldn't matter in this case, because one is the order created (pending order), and one is a trade created (trade filled)? The issue doesn't seem to be a problem when I run a back test, but I'm fairly sure this was an issue before the custom code was included.
-
When you have a large number of blocks it is hard to ascertain the problem, create a test project with a few blocks, and then the problem can be seen
-
That’s good advice, thanks! I will say that for this project, only the launcher and manager areas affect the SL. The change in SL appears to happen the moment the pending order from group 2 fills, if that helps.
-
Ok but there are still about 130 blocks that could interfere, so limit this, and the only blocks that could interfere would be minimal. When I create a EA, I still test 1 section before adding the next. It takes longer but if there's a problem it can only be with the last few blocks I added.
-
That makes sense. This is the most basic aspect of the project. You can probably even ignore the manager blocks, but basically it just creates a pending trade for each group 1-4, stores their variables, deletes them each day if they don't hit, and repeat. Once a pending order does hit, it should be managed accordingly, but the issue is that the SL from group 1 and group 2 are different when they are both pending orders, and even once group 1 fills...and when group 2 fills, it doesn't use the stop loss it had when it was a pending order and instead changes to match the SL from group 1. Would anything in this simplified project make that happen?
-
There is still a vast amount of blocks, knuckle this section down to more like 10, and then the problem can be easily identified