Codice: Seleziona tutto
void TrailingStop(double e_trailingstop,double e_trailingstep){
Comment("ts");
for (int i= OrdersTotal()-1; i >=0; i --){
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
if(OrderSymbol()==Symbol()&& OrderMagicNumber()== nMagic)
{
Print("SELECT ORDER ERROR # ", GetLastError());
return;
}
if (OrderType() == OP_BUY)
if ((Bid - OrderOpenPrice()) > (e_trailingstop * Point))
if (OrderStopLoss() < Bid - (e_trailingstop + e_trailingstep - 1) * Point) {
if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask - e_trailingstop * Point, OrderTakeProfit(), 0, clrGreen))
return;
}
if (OrderType()==OP_SELL)
if ((OrderOpenPrice() - Ask) > (e_trailingstop * Point))
if (OrderStopLoss() > Ask + (e_trailingstop + e_trailingstep - 1) * Point || OrderStopLoss()==0) {
if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask + e_trailingstop * Point, OrderTakeProfit(), 0, clrGreen))
return;
}
}
}