Newbie Coder--Trying to code in a trailing stop loss--somewhat lost New comment marth tanaka 2018.06.21 19:45 Hey, so this is what I have so far:void OnTick(void) { openedpositions=OrdersTotal(); if ((openedpositions > 0)) { int totalorders = OrdersTotal(); for(int i=0;i<totalorders;i++) // scan all orders and positions. .. { OrderSelect(i, SELECT_BY_POS); if ( OrderSymbol()==Symbol() && OrderMagicNumber() == uniqueGridMagic) // only look if mygrid and symbol. .. { int type = OrderType(); if(OrderType()==OP_BUY) { if (Bid-OrderOpenPrice()>TrailingStop*Point && OrderStopLoss()<Bid-TrailingStop*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,0,0,Green); } } if(OrderType()==OP_SELL) { if(OrderOpenPrice()-Ask>TrailingStop*Point && OrderStopLoss()>Ask+TrailingStop*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,0,0, Red); } } } } } }Basically, I'm trying to have it scan all open orders every tick and modify them, if they have not been modified already, like this:1. start with static stoploss of 25 pips2. at 5 pips profit move stoploss to entry price3. at 8 pips profit move stoploss 4 pips behind 8 pips profit (current price)So I think I have it able to scan all orders, correct me if Im doing it wrong, but I am totally lost on how to incorporate the stop loss like so. Any ideas guys? Much appreciated Objects - Charts - MetaTrader 5 for Android Basic Principles - Trading Operations Objects - Chart - MetaTrader 5 for iPhone GrumpyDuckMan 2018.06.22 06:17 #1 hello friend, Do you get any warning? such as "return value of 'OrderModify' should be checked" New comment
So I think I have it able to scan all orders, correct me if Im doing it wrong, but I am totally lost on how to incorporate the stop loss like so. Any ideas guys? Much appreciated