Modifying a buy/sell stop
6 replies
huangwh88
7 years ago #116411
Hello,
Lets say I have a buy stop at the highest high of the past 10 periods. If the order is not triggered after the latest period, how do i modify the buy stop to account for the change in the 10 period lookback window?
tomas262
7 years ago #141822
Hello,
to modify a stop order you would cancel it using the “close position” function and then re-open a new order
huangwh88
7 years ago #141834
Hello,
to modify a stop order you would cancel it using the “close position” function and then re-open a new order
Hi Tomas,
Every time the buy stop of highest(10) is not triggered I want to adjust the entry price so that the highest high is updated. I tried this:
IF:
pending order exists(1000) is True
THEN:
close position, magic number 1000
Enter at stop, highest(10), magic number 1000
There is an error because there are 2 orders with magic number 1000. The rule that created the original buy stop also uses magic number 1000. Do I need a different magic number every time I modify a buy stop, even though the orders are actually the same?
tomas262
7 years ago #141849
Hello,
ok, we need to use a function to modify and order price. I will make an example for this and attach
tomas262
7 years ago #141870
You can add this function into EA Wizard CustomFunctions.mq4 placed in Wizard \ Code
void modifyPendingOrder(int orderMagicNumber, double newPO) { bool found = false; for (int cc = OrdersTotal() - 1; cc >= 0; cc--) { if (!OrderSelect(cc, SELECT_BY_POS) ) continue; if(OrderMagicNumber() == orderMagicNumber && OrderSymbol() == Symbol()) { found = true; Verbose("Moving PO for order with Magic Number: ", orderMagicNumber,", ticket: ", OrderTicket(), ", new PO: ", newPO); tmpRet = OrderModify(OrderTicket(), newPO, 0, 0, 0); } } if(!found) { Verbose("Moving PO - order with Magic Number: ", orderMagicNumber, " wasn't found"); } }
Then the order price can be modified as shown in the example attached
huangwh88
7 years ago #141966
You can add this function into EA Wizard CustomFunctions.mq4 placed in Wizard \ Code
void modifyPendingOrder(int orderMagicNumber, double newPO) { bool found = false; for (int cc = OrdersTotal() - 1; cc >= 0; cc--) { if (!OrderSelect(cc, SELECT_BY_POS) ) continue; if(OrderMagicNumber() == orderMagicNumber && OrderSymbol() == Symbol()) { found = true; Verbose("Moving PO for order with Magic Number: ", orderMagicNumber,", ticket: ", OrderTicket(), ", new PO: ", newPO); tmpRet = OrderModify(OrderTicket(), newPO, 0, 0, 0); } } if(!found) { Verbose("Moving PO - order with Magic Number: ", orderMagicNumber, " wasn't found"); } }Then the order price can be modified as shown in the example attached
Hi Tomas, Thank you for your wonderful help.
I wish to add in an IF condition that needs to be satisfied before the pending order can be shifted according to the above code. If this condition is not satisfied, the pending order is deleted. Is there a way to add in this order deletion without creating another IF/THEN rule?
tomas262
7 years ago #141990
Hello,
yes, you can add additional conditions into the modify tab and create another tab for deleting the pending order (using “Close position” function to delete it)
Viewing 6 replies - 1 through 6 (of 6 total)