Can you see any problem with this trailing stop code? Thank you
if (OrderSelect(OrdersTotal()-1,SELECT_BY_POS)==true)
{
Ticket=OrderTicket(); // Number of selected order
Tip =OrderType(); // Type of selected order
Price =OrderOpenPrice(); // Price of selected order
SL =OrderStopLoss(); // SL of selected order
TP =OrderTakeProfit(); // TP of selected order
Lot =OrderLots(); // Amount of lots of selected order
if ( Tip==0 ) // Buy order
{
if(SL<Bid-10*Point*TrailingStop)
{
bool Mod=OrderModify(Ticket,Price,Bid-10*Point*TrailingStop,TP,0);
}
}
}
- Are you adjusting for a 5 digit brokers? change all 10*point to pips2dbl
//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
if(SL<Bid-10*Point*TrailingStop)
Current SL will always be rounded to a Point. Your calculation will not be. Trydouble newSL = Bid-Pips2dbl*TrailingStop; if(newSL-SL>Point)
- Are you adjusting for a 5 digit brokers? change all 10*point to pips2dbl
- Current SL will always be rounded to a Point. Your calculation will not be. Try
Thank you WHRoeder.
Yes, the broker I am using is 5 digits. I have changed my code, but "Error occurred 0" are still there........
if (Tip==0) { double newSL = Bid-10*Point*TrailingStop; if(newSL-SL>Point) { bool Mod=OrderModify(Ticket,Price,newSL,TP,0); } }
I assume it is OrderModify Error 0. This simply means that there was an instruction to modify a TP or SL which was already the same as the new SL or TP. The order was therefore not modified.
There is probably a breakdown in the logic leading to the ordermodify command. Not having the full code, it is impossible to tell where the error lies but I would suspect that rounding of your doubles could be an issue which is why it 'appears' to ignore your if(newSL-SL>Point) condition.
Apart from cluttering your terminal and harddrive with errors, the bug is harmless and your EA should still function normally regardless.

- 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 Pros,
When I test my trailing stop program, the " error occured 0" appears many times in the journal.
Could anybody tell me how to avoid it?
Thanks a lot