Here's a routine that I am testing. It seems that the sell side stop is trailing on step one only, and the buy stop is not trailing whatsoever. I'm not sure if there is something wrong with the logic or syntax. What is the problem here?
*********
int step1 = 9, step2 = 18, step3 = 27;
for (int i = 0; i <= 0; i++) //scan all orders & positions...
{
OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
{
if ((OrderSymbol() != Symbol()) && ((OrderMagicNumber() != magic + buy_id) || (OrderMagicNumber() != magic + sell_id))) continue;
{
if (OrderType() <= OP_SELL)
{
if ((short < (OrderOpenPrice() - step1 * Point)) && (short > (OrderOpenPrice() - step2 * Point)))
{
OrderModify (OrderTicket(), short, short + step1 * Point, OrderTakeProfit(), 0, Gold);
} else
if ((short < (OrderOpenPrice() - step2 * Point)) && (short > (OrderOpenPrice() - step3 * Point)))
{
OrderModify (OrderTicket(), short, short + step1 * Point, OrderTakeProfit(), 0, Tomato);
} else
if (short < (OrderOpenPrice() - step3 * Point))
{
OrderModify (OrderTicket(), short, short + step1 * Point, OrderTakeProfit(), 0, Coral);
}
} else
if (OrderType() >= OP_BUY)
{
if ((long > (OrderOpenPrice() + step1 * Point)) && (long < (OrderOpenPrice() + step2 * Point)))
{
OrderModify (OrderTicket(), long, long - step1 * Point, OrderTakeProfit(), 0, Gold);
} else
if ((long > (OrderOpenPrice() + step2 * Point)) && (long < (OrderOpenPrice() + step3 * Point)))
{
OrderModify (OrderTicket(), long, long - step1 * Point, OrderTakeProfit(), 0, Tomato);
} else
if (long > (OrderOpenPrice() + step3 * Point))
{
OrderModify (OrderTicket(), long, long - step1 * Point, OrderTakeProfit(), 0, Coral);
}
}
}
}
}
*********
*********
int step1 = 9, step2 = 18, step3 = 27;
for (int i = 0; i <= 0; i++) //scan all orders & positions...
{
OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
{
if ((OrderSymbol() != Symbol()) && ((OrderMagicNumber() != magic + buy_id) || (OrderMagicNumber() != magic + sell_id))) continue;
{
if (OrderType() <= OP_SELL)
{
if ((short < (OrderOpenPrice() - step1 * Point)) && (short > (OrderOpenPrice() - step2 * Point)))
{
OrderModify (OrderTicket(), short, short + step1 * Point, OrderTakeProfit(), 0, Gold);
} else
if ((short < (OrderOpenPrice() - step2 * Point)) && (short > (OrderOpenPrice() - step3 * Point)))
{
OrderModify (OrderTicket(), short, short + step1 * Point, OrderTakeProfit(), 0, Tomato);
} else
if (short < (OrderOpenPrice() - step3 * Point))
{
OrderModify (OrderTicket(), short, short + step1 * Point, OrderTakeProfit(), 0, Coral);
}
} else
if (OrderType() >= OP_BUY)
{
if ((long > (OrderOpenPrice() + step1 * Point)) && (long < (OrderOpenPrice() + step2 * Point)))
{
OrderModify (OrderTicket(), long, long - step1 * Point, OrderTakeProfit(), 0, Gold);
} else
if ((long > (OrderOpenPrice() + step2 * Point)) && (long < (OrderOpenPrice() + step3 * Point)))
{
OrderModify (OrderTicket(), long, long - step1 * Point, OrderTakeProfit(), 0, Tomato);
} else
if (long > (OrderOpenPrice() + step3 * Point))
{
OrderModify (OrderTicket(), long, long - step1 * Point, OrderTakeProfit(), 0, Coral);
}
}
}
}
}
*********