TS : trailing stop
BE : break even
2014.12.27 00:15:53.291 2013.04.16 18:25 PBD_EA_test EURUSD,H4: modify #23 buy 0.10 EURUSD at 1.30751 sl: 1.31388 tp: 1.32710 ok
There is Errors appear on the Strategy Tester journal , I didn’t understand them ,
The image :
Nested "if" statement is a bad coding practice, which leads to error and lost of time, as in your case.
if(OrderStopLoss()<Bid - TrailAmount*pips) result=OrderModify( OrderTicket(), OrderOpenPrice(), Bid - TrailAmount*pips, OrderTakeProfit(), 0, CLR_NONE ); if (!result) <==== this 'if' is not inside the previous one Alert("Buy Order Modify Error n° ", GetLastError());
Your last if can be executed even if there is no error. This last 'if' statement is not even inside your loop.
It should be:
if(OrderStopLoss()<Bid-TrailAmount*pips) { result=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailAmount*pips,OrderTakeProfit(),0,CLR_NONE); if(!result) Alert("Buy Order Modify Error n° ",GetLastError()); }
Or better :
for(int b=OrdersTotal()-1; b>=0; b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==magicNumber && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>WhenToTrail*pips && OrderStopLoss()<Bid-TrailAmount*pips) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailAmount*pips,OrderTakeProfit(),0,CLR_NONE)) Alert("Buy Order Modify Error n° ",GetLastError()); } } if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>WhenToTrail*pips && (OrderStopLoss()>Ask+TrailAmount*pips || OrderStopLoss()==0)) { if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailAmount*pips,OrderTakeProfit(),0,CLR_NONE)) Alert("Sell Order Modify Error n° ",GetLastError()); } } } }
Nested "if" statement is a bad coding practice, which leads to error and lost of time, as in your case.
Your last if can be executed even if there is no error. This last 'if' statement is not even inside your loop.
It should be:
Or better :
The BE errors fixed , but the TS errors did not , look at the image :
an OrderSend error also :)
what do you think the problem is ?
Error 1 means you are trying to change the current Stoploss with the same value. See this topic to understand why.
Error 130 means your stoploss are too close to market price (Bid/Ask).
Error 1 means you are trying to change the current Stoploss with the same value. See this topic to understand why.
Error 130 means your stoploss are too close to market price (Bid/Ask).
Thanks Mr.Alain
Errors fixed by organizing the code ,add 0.5 pips to the TrailAmount and WhenToTrail , adjust the SL and TP if they are too close to the market .
Should we always adjust the slippage ? for the 5 digits broker .
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
There is Errors appear on the Strategy Tester journal , I didn’t understand them ,
The image :
And this is the code of the trailing stop function
Some help to solve this problem