هذا مثال
كود PHP:
void TrailingStopFlex15()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
double takeprofit = OrderTakeProfit();
double trailingstop = Low[1];
if (OrderType() == OP_BUY )
{
if (OrderStopLoss() < Low[1]-(TrailingGap15*PipValue*Point))
{
if (NewTakeProfit15 != 0) takeprofit = Ask+(NewTakeProfit15*PipValue*Point + trailingstop);
bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Low[1]-(TrailingGap15*PipValue*Point), takeprofit, OrderExpiration(), White);
if (ret1 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
if (OrderType() == OP_SELL)
{
if (OrderStopLoss() > High[1]+(TrailingGap15*PipValue*Point))
{
if (NewTakeProfit15 != 0) takeprofit = Bid-(NewTakeProfit15*PipValue*Point + trailingstop);
bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(),High[1]+(TrailingGap15*PipValue*Point), takeprofit, OrderExpiration(), White);
if (ret2 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}