I can't follow your logic. Good luck.
for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==magic && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if(Bid-Point*ts>OrderOpenPrice() && Bid-Point*ts>OrderStopLoss()) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*ts,OrderTakeProfit(),0); } } else if(OrderType()==OP_SELL) { if(Ask+Point*ts<OrderOpenPrice() && Ask+Point*ts<OrderStopLoss()) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*ts,OrderTakeProfit(),0); }
- OrderSelect return value must be tested.
- Are you filtering for orders with certain magic number OR with chart symbol?
- Your trailing stop may and may not work because the return(0) will skip the rest of your orders.
- The condition test for the while loop is simply wrong.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My trailing stop only works for sell order but not for buy order.
here's the code:
if I change while(Bid-OrderStopLoss()>Bid-Point*ts) to while Bid-OrderStopLoss()<Bid-Point*ts), it works both ways (for sell and buy orders), but I got huge loss as the result.
How can this be?
thanks.
note: I use "while" since without it the trailing stop will move up and down as the price moves and I usually end up with losses.