one to one coaching

Add Trailing Stop Code

Default Add a trailing stop

At the bottom of your EA, add this function :

Code:

void MoveTrailingStop()
{
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits))||(OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Green);
return(0);
}
}
}
else
{
if(TrailingStop>0)
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}

Somewhere in your EA, after conditions,in start somewhere , add this :

Code:

if(TrailingStop>0)MoveTrailingStop();

Finally, at the top of the EA add this :

Code:

extern int TrailingStop=0;
extern int TrailingStep=0;
 
one to one coaching
Top