Download MetaTrader 5
To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
nickrich
25
nickrich 2016.02.10 12:21 

Hello, everyone. Ich have coded this here:

for(int i=0;i<OrdersTotal();i++)
     {
      bool select = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);              //Iteration through every trade
      if(OrderMagicNumber()==1 && OrderSymbol()==Symbol())                 //if Trade==BUY
        {
         if(Close[1]>OrderStopLoss()+atr && Close[1]>OrderOpenPrice()+atr) //is the price already greater than the opening price+ATR,
           {                                                               // and than the stoploss+ATR?
            bool order = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()+atr-0.0005,5),0,0,clrAquamarine);
            if(!order){Alert(GetLastError());}
           }
         else
           {
            return;
           }
        }
}


The problem is that the stoploss keeps moving on every tick. I know it is because of the "-0.0005", but I would like to keep that margin. What could I do to set the stoploss at that level, but prevent it from moving on every tick?

Thank you very much in advance.

Keith Watford
Moderator
8028
Keith Watford 2016.02.10 12:59  
     if(OrderMagicNumber()==1 && OrderSymbol()==Symbol())                 //if Trade==BUY

There is no check for whether the trade is a BUY.

     if(Close[1]>OrderStopLoss()+atr && Close[1]>OrderOpenPrice()+atr)

 Why are you using Close[1]? I think that you should be using OrderClosePrice().

 

For a BUY, you should be checking that the new SL is higher than the current SL, lower for a SELL. 

/
To add comments, please log in or register