init() gets called once at the start of the EA . . . where is start() ?
You don't seem to be setting err to the value of the last error ? is this a copy and paste bodge of code ?
more info
OrderOpenPrice()=1.38509
OrderStopLoss()=1.38498
Bid was around =1.378xx
int init() { tf=Period(); pair=Symbol(); err=GetLastError(); spread=GetInfo(); total=OrdersTotal(); if (Digits == 5 || Digits == 3) { // Adjust for five (5) digit brokers. pips2double = Point*10; pips2point = 10; Digits.pips = 1; } else { pips2double = Point; pips2point = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl return(0); //end of init() }
int start() { MoveTrailingProfit(); /* following logics */ return(0); }
int MoveTrailingProfit() { double SL_BUY=NormalizeDouble(Bid-TrailingProfit*pips2double,Digits); double SL_SELL=NormalizeDouble(Ask+TrailingProfit*pips2double,Digits); for (int cnt=total-1; cnt>=0; cnt--) { if ( OrderSelect(cnt, SELECT_BY_POS) // select Only my orders with && OrderMagicNumber() == Magic // my magic number && OrderSymbol() == Symbol() // and my pair. ) { if(OrderType()==OP_BUY) //and is buy order { if(OrderStopLoss()>=OrderOpenPrice()) //meaning already scaled once { if(NormalizeDouble(OrderStopLoss(),Digits)<SL_BUY) { Print(pair,", ",TimeFrameToString(tf), ", ",OrderTicket()," BUY TrailingProfit Activated."); if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL_BUY,OrderTakeProfit(),0,Yellow)) Print(pair,", ",TimeFrameToString(tf), ", ",OrderTicket()," BUY TrailingProfit err=", err,", ",SL_BUY); } } } if(OrderType()==OP_SELL) { if(OrderStopLoss()<=OrderOpenPrice()) //meaning already scaled once { if(NormalizeDouble(OrderStopLoss(),Digits)>SL_SELL) { Print(pair,", ",TimeFrameToString(tf),", ",OrderTicket(), " SELL TrailingProfit Activated."); if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL_BUY,OrderTakeProfit(),0,Yellow)) Print(pair,", ",TimeFrameToString(tf), ", ",OrderTicket()," SELL TrailingProfit err=", err,", ",SL_SELL); } } } } } return(0); }
oh, I see your point,
code modified and now the err=130
May I know what may cause it to return error=130? many thanks!
Ah . . your code makes sense now . . .
Did you mean to use SL_BUY for your OrderModify for Buys and Sells ?
I'll repeat the same advice I gave yesterday to someone else . . .
"If you want to find errors you need INFORMATION . . how do you get it ? ADD Print statements . . . print all your variables, when something isn't working you can check your variable values to see if they are right or wrong . . then you have info and you can find where your issue is."
Did you mean to use SL_BUY for your OrderModify for Buys and Sells ?
I'll repeat the same advice I gave yesterday to someone else . . .
"If you want to find errors you need INFORMATION . . how do you get it ? ADD Print statements . . . print all your variables, when something isn't working you can check your variable values to see if they are right or wrong . . then you have info and you can find where your issue is."
OMG, big mistake, thanks RaptorUK!!!!

- 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, I am getting errors showing
"EAName EURUSD, M30: EURUSD, M30, ticket# SELL TrailingProfit err=0, 1.3804"
and it appears that the EA is not modifying the SL for the selected ticket
Could anyone please advise what seems to be the problem, many thanks!!!