this is the other part for MoveTrailingProfit
int MoveTrailingProfit() { total=OrdersTotal(); double SL_BUY=NormalizeDouble(Bid-TrailingProfit*pips2double,Digits); //Ask will be tighter 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) //ToDo { //Print(lazy,OrderTicket()," BUY TrailingProfit Activated."); if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL_BUY,0/*OrderTakeProfit()*/,0,TPColor)) Alert(lazy,OrderTicket()," BUY TrailingProfit err=", GetLastError(),", ",SL_BUY); } } } if(OrderType()==OP_SELL) { if(OrderStopLoss()<=OrderOpenPrice()) //meaning already scaled once { if(NormalizeDouble(OrderStopLoss(),Digits)>SL_SELL) { //Print(lazy,OrderTicket(), " SELL TrailingProfit Activated."); if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL_SELL,0/*OrderTakeProfit()*/,0,TPColor)) Alert(lazy,OrderTicket()," SELL TrailingProfit err=", GetLastError(),", ",SL_SELL); } } } } } return(0); }
Can you explain what this line of code is meant to do ?
if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Black))
and what it does when you call it the next time for the same Order ?
the Alert shows funny digits for SL, and I cannot understand why it fails
sorry for the stupid mistake and I shall correct my code
thanks for your time
sorry for the stupid mistake and I shall correct my code
thanks for your time
Your Alert uses SL+ to output the SL value . . . not aware of the use of the + in that situation, what does it do ?
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL_BUY,0/*OrderTakeProfit()*/,0,TPColor))
Can you explain what this line of code is meant to do ?
and what it does when you call it the next time for the same Order ?
if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Black))is this not move SL to BEP?
Forgot to ask, what is the reason when MoveTrailingProfit() function also returns error=1
All you need to do is something like this . . .
if (SL_Sell > OrderStopLoss()) // do the order modify . . . .
is this not move SL to BEP?
oh, that is the reason for error=1, thanks for the explanation
I truly appreciate your reply as I am learning something every time
- 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 struggling with my first EA and I am getting error=1 when calling function (take profit/modify SL/scale out)
Attached is the code for taking profit/scale out
the Alert shows funny digits for SL, and I cannot understand why it fails
It appear to be some major issues I need to learn with my code, any advise is greatly appreciated