Why am I getting an Error 4051? - page 2

 
Ernst Van Der Merwe:

Error 130 may be due to a lack of braces after OrderSelect()

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         Print ("Real Ticket: ",OrderTicket());
         if (OrderMagicNumber()==MagicNumberLong)
            if (OrderSymbol()==Symbol())
               if (OrderType()==OP_BUY)
               {
                  if(Ask-OrderTakeProfit()>Trail*Point)
                     TrailingStop(OrderTicket());
                    
                  oldticketnumber = OrderTicket();
                  if (oldticketnumber > buyticketnumber)
                     buyticketnumber = oldticketnumber;     //Sets buyticketnumber to newest order
               }
         }
      }
I thought about that as well but it has to do with the minimum distance to SL and TP. I use the highest high and lowest low of the last x candles on a 1M chart. Sometimes the price range is just too small. I temporarily solved it by setting a fixed number of pips.
 
datas_brother:
I thought about that as well but it has to do with the minimum distance to SL and TP. I use the highest high and lowest low of the last x candles on a 1M chart. Sometimes the price range is just too small. I temporarily solved it by setting a fixed number of pips.

Rather than guess, try using  

SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL)

https://book.mql4.com/appendix/limits 

Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
 
honest_knave:

Rather than guess, try using  

SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL)

https://book.mql4.com/appendix/limits 

Thanks! I'll do that.



The last time I did any programming Ronald Reagan was president. It's taking me a bit to get back in to it. I appreciate the help.
Reason: