Code For Trailing Loss

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

for(int cnt=0;cnt<OrdersTotal();cnt++) // TakeProfit Trailling Stop

{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==magic
)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(OrderOpenPrice()-Bid>point*TrailingStop)
{
if(OrderTakeProfit()>Bid+point*TrailingStop)
{

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid+TrailingStop*point,0
,Green);
return(0);
}
}
}
}
else if(OrderType() == OP_SELL)
{
if(TrailingStop>0)
{
if((Ask-OrderOpenPrice())>(point*TrailingStop))
{
if((OrderTakeProfit()<(Ask-point*TrailingStop)))
{

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask-
point*TrailingStop,0,Red);
return(0);
}
}
}
}
}
}

You might also like