老周 发表于 2017-3-27 14:40:25

持仓订单的移动止损

函数执行持仓订单的移动止损功能。

extern int Magic = 20080829;
extern color clModify = Silver;
extern int TrailingStart = 30;
extern int TrailingSize = 30;
void TrailPositions()
{
int cnt = OrdersTotal();
for (int i=0; i<cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == OP_BUY)
{
if (Bid-OrderOpenPrice() > TrailingStart*Point)
{
if (OrderStopLoss() < Bid - (TrailingSize+1)*Point)
{
OrderModify(OrderTicket(),
OrderOpenPrice(),
Bid-TrailingSize*Point,
OrderTakeProfit(), 0, clModify);
}
}
}
if (type == OP_SELL)
{
if (OrderOpenPrice()-Ask > TrailingStart*Point)
{
if (OrderStopLoss() > Ask + (TrailingSize+1)*Point || OrderStopLoss() == 0)
{
OrderModify(OrderTicket(),
OrderOpenPrice(),
Ask+TrailingSize*Point,
OrderTakeProfit(), 0, clModify);
}
}
}
}
}

sale 发表于 2019-10-20 17:16:16

fdjhtrsjtrkkzyrkstylkytdltdu

WUXIAODONG 发表于 2019-10-28 13:19:26

sale 发表于 2019-10-20 17:16
fdjhtrsjtrkkzyrkstylkytdltdu

13265656JJJH
页: [1]
查看完整版本: 持仓订单的移动止损