老周 发表于 2017-3-27 14:34:31

移动止损功能

该函数执行移动止损功能。

for(i = 0; i < OrdersTotal(); i++)
{ // 1
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
// Trail Long / Buy
if ( (OrderType() == OP_BUY) && (OrderMagicNumber() == magic) )
{ // 2
if ( (OrderClosePrice() - OrderOpenPrice()) > (TrailingStop*Point) )
{ // 3
if ( OrderStopLoss() < (OrderClosePrice() - TrailingStop*Point) )
{ // 4
OrderModify(OrderTicket(),
OrderOpenPrice(),
OrderClosePrice() - TrailingStop*Point,
OrderTakeProfit(),
Orchid);
} // 4
} // 3
} // 2
// Trail Short / Sell
if ( (OrderType() == OP_SELL) && (OrderMagicNumber() == magic) )
{ // 2
if ( (OrderOpenPrice() - OrderClosePrice()) > (TrailingStop*Point) )
{ // 3
if ( (OrderStopLoss() > (OrderClosePrice() + TrailingStop*Point)) ||
(OrderStopLoss() == 0) )
{ // 4
OrderModify(OrderTicket(),
OrderOpenPrice(),
OrderClosePrice() + TrailingStop*Point,
OrderTakeProfit(),
Orchid);
} // 4
} // 3
} // 2
} // 1
//+- End of trading control -----------------------------------------------------------------+
} // B if (UserAcceptsAllLiability == true)
return(0);
} // A init start()

页: [1]
查看完整版本: 移动止损功能