bool Traling()
{
if(TrailingStop>0) {
for(int i=OrdersTotal()-1; i>=0; i--) {
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol()) continue;
if(OrderMagicNumber()!=Magic) continue;
if(OrderType()==OP_BUY && Bid-OrderOpenPrice() >= TrailingStart*Point) {
if(OrderStopLoss() <= Bid-(TrailingStop+TrailingStep)*Point) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*Point,Digits),OrderTakeProfit(),0,Green)) {
Print("OrderModify error ",GetLastError());
}
}
}
if(OrderType()==OP_SELL && OrderOpenPrice()-Ask >= TrailingStart*Point) {
if(OrderStopLoss() >= Ask+(TrailingStop+TrailingStep)*Point || OrderStopLoss()==0) {
if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*Point,Digits),OrderTakeProfit(),0,Green)) {
Print("OrderModify error ",GetLastError());
}
}
}
}
}
return(true);
}