Hello Thomas, Use the below code for setting SL and TP:
if(OrderCloseTime() == 0 && OrderStopLoss() == 0) { double StopLoss = NormalizePrice(OrderOpenPrice() / ( 1 + SL_prozent/100)); double TakeProfit = NormalizePrice(OrderOpenPrice() * ( 1 + TP_prozent/100)); bool OrderAngepasst = OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss ,TakeProfit,0,Orange); if(!OrderAngepasst) Print("Error by OrderModify : ",GetLastError()); else Print("Order modified successfully."); }This will fix your problem.
Hi all,
In my EA it will open a buy or sell order according to the conditon. If an order is opened, then I will add the SL and TP order by using the ModifyOrder as follow ( here is a buy order for example):
There is no any problem by backtesting. But by paper trade or real trade, I notice only the TP order is set. The ST order not. Here is what I get from the "Experts":
One can see the SL order was set successfully first:
And then the TP order was also set successfully. But the SL order was clean. At the end, only the TP order is set.
Where did I do wrong?
Thanks Gyunay and Petr, I will have a try.
If you modify together SL and TP from the first time you may not have the same problem.
This is not true. I've restarted my EA many times and everytime the same.
Hello Thomas, Use the below code for setting SL and TP:
This will fix your problem.Hi Gyunay,
How about the following?
if(OrderCloseTime() == 0 && OrderStopLoss() == 0 && OrderTakeProfit() == 0){ ... ... } or if(OrderCloseTime() == 0 && (OrderStopLoss() == 0 || OrderTakeProfit() == 0)){ ... ... }
Hi again,
It will be better to use this one:
if(OrderCloseTime() == 0 && (OrderStopLoss() == 0 || OrderTakeProfit() == 0)){ ... ... }You will guarantee that even one of the SL or TP is 0 the code will run and you will set the missing value for SL or TP.
Hi again,
It will be better to use this one:
You will guarantee that even one of the SL or TP is 0 the code will run and you will set the missing value for SL or TP.Many thanks!
Many thanks!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
In my EA it will open a buy or sell order according to the conditon. If an order is opened, then I will add the SL and TP order by using the ModifyOrder as follow ( here is a buy order for example):
There is no any problem by backtesting. But by paper trade or real trade, I notice only the TP order is set. The ST order not. Here is what I get from the "Experts":
One can see the SL order was set successfully first:
And then the TP order was also set successfully. But the SL order was clean. At the end, only the TP order is set.
Where did I do wrong?