Invalid Price (sometimes) - Buy Stop

 

Hi all,

I've scoured the forums for days but am unable to find a solution to this. Im trying to make an EA which will place a buystop on gold ( with no TP or SL ).

               MqlTick latestAsk;

               SymbolInfoTick(symbol, latestAsk);
      
               logger.log("Latest Ask price before placing buy stop is : " + DoubleToString(latestAsk.ask));
               double orderPrice = latestAsk.ask + 10 * SymbolInfoDouble("XAUUSD",SYMBOL_POINT); // set order price 1 pip above the asking.
               
               logger.log(orderPrice + " is the price of the order");

               // Place buy stop a few pips above the ask price , placing it at the closed price WILL not work if the spread is large
               // The price also needs to be normalized to the tick size (?)
               tradeManager.BuyStop(0.01, orderPrice,
                                    "XAUUSD", 0, 0,
                                    ORDER_TIME_GTC,0, comment);

               // Check trade result for the buystop here too
               tradeManager.Result(resultToCheck);
               
               
               logger.log( SymbolInfoInteger(symbol ,SYMBOL_TRADE_STOPS_LEVEL) + " is the symbol trade stops level");
               logger.log( SymbolInfoInteger(symbol , SYMBOL_TRADE_FREEZE_LEVEL) + " is the symbol trade freeze level");
               logger.log( latestAsk.ask + 10 * SymbolInfoDouble(symbol,SYMBOL_POINT) - latestAsk.ask  + " is OpenPrice - Ask" );
               logger.log(resultToCheck.retcode + " is the retcode for the buystop ");
               logger.log("Latest Ask price before placing buy stop is : " + DoubleToString(latestAsk.ask));
               logger.log("Latest Bid price before placing buy stop is : " + DoubleToString(latestAsk.bid));
               logger.log("Latest last price before placing buy stop is : " + DoubleToString(latestAsk.last));

Doing all this returns this in the logs :



I am aware of the trade freeze levels - but it looks like 0 for my broker. Additionally, this error does not happen every time, only sometimes. One more thing is that would it have to have anything to do with the last price?

Let me know of any things to check/direction - otherwise a solution in my mind is to have a while loop to get the EA to place an order until it fails ( but I rather not do this )

Thanks all!

 
Normalize your prices to tick size, always.