I'm stumped. The trailing stop does not do anything with orders other than stick with the initial StopLoss and TakeProfit when the order was initiated.
Can any please spot anything that I have wrong?
Can any please spot anything that I have wrong?
PHP Code
int total=OrdersTotal();
for(int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber || OrderType()!=OP_BUY && OrderType()!=OP_SELL) continue;
{
if(OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
{
if(Bid-OrderOpenPrice() >= TrailingStop*Point*10)
{
if(OrderStopLoss() < Bid-(TrailingStop*Point*10))
{
buy_TP=NormalizeDouble(Ask+(TakeProfit*Point*10), Digits);
buy_TS=NormalizeDouble(Bid-(TrailingStop*Point*10), Digits);
OrderModify(OrderTicket(),Ask,buy_TS,OrderTakeProfit(),MagicNumber,Blue);
}
}
}
else if(OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
{
if(OrderOpenPrice()-Ask >= TrailingStop*Point*10)
{
if(Ask+(TrailingStop*Point*10) < OrderStopLoss())
{
sell_TP=NormalizeDouble(Bid-(TakeProfit*Point*10), Digits);
sell_TS=NormalizeDouble(Ask+(TrailingStop*Point*10), Digits);
OrderModify(OrderTicket(),Bid,sell_TS,OrderTakeProfit(),MagicNumber,Red);
}
}
}
//+-------------------------Using this for Initial Orders---------------------------------+
// Long Entry
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,NULL,0,0,Blue);
if(ticket>0)
{
OrderSelect(ticket,SELECT_BY_TICKET);
buy_TP=NormalizeDouble(Ask+(TakeProfit*Point*10), Digits);
buy_TS=NormalizeDouble(Bid-(StopLoss*Point*10), Digits);
OrderModify(ticket,OrderOpenPrice(),buy_TS,buy_TP,0,Blue); // IBFX to add SL and TP
}
// Short Entry
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,NULL,0,0,Red);
if(ticket>0)
{
OrderSelect(ticket,SELECT_BY_TICKET);
sell_TP=NormalizeDouble(Bid-(TakeProfit*Point*10), Digits);
sell_TS=NormalizeDouble(Ask+(StopLoss*Point*10), Digits);
OrderModify(ticket,OrderOpenPrice(),sell_TS,sell_TP,0,Red); // IBFX to add SL and TP
}