getting error "Invalid Price Length 13" when placing an order

 

please check my code below

MqlTradeCheckResult m_check_result;
MqlTradeRequest request;
request.price = 132.628;
if(!OrderCheck(request,m_check_result)){
 return false   
}

return OrderSend(request, result);

OrderCheck is failing and returning false  because the price value is wrong. The request.price which i set exactly to 132.628 it getting displayed wrong with a lot of decimals points as shown in attached image  

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Request Check Result Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Request Check Result Structure
  • www.mql5.com
Request Check Result Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Your topic has been moved to the section: Expert Advisors and Automated Trading — In the future, please consider which section is most appropriate for your query.

Improperly formatted code edited by moderator. In future, please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
ansar9h: please check my code below. OrderCheck is failing and returning false  because the price value is wrong. The request.price which i set exactly to 132.628 it getting displayed wrong with a lot of decimals points as shown in attached image  

Is that all your code for the request?

What about the rest of the request data — order type, filling type, volume, etc.?

Is this a pending order or a market order?

If it is a market order it will most likely fail, because for market orders (which opens a position) ...

  • A buy order opens at the Ask price
  • A sell order opens at the Bid price
 

check attached screenshot of the whole MqlTradeRequest object

 
ansar9h #: check attached screenshot of the whole MqlTradeRequest object
  1. Show code, not screenshots.
  2. What are the error code and trade result code?
  3. Also show log output where both Ask and Bid prices are displayed.
 

not sure if whole code will help but here is it

double TAKE_PROFIT_RATIO = 2;

bool placeSellOrderAt(double entryPrice, double stopLossPrice){
   float takeProfitPrice= entryPrice - (stopLossPrice - entryPrice) * TAKE_PROFIT_RATIO; // Specify the take profit level
 
   MqlTradeRequest request;
   ZeroMemory(request);
   request.action = TRADE_ACTION_PENDING;
   request.type = ORDER_TYPE_SELL_LIMIT;
   request.symbol = _Symbol;
   request.volume = calcLots(risk_amount, stopLossPrice-entryPrice);;
   request.price = entryPrice;
   request.sl = stopLossPrice;
   request.tp = takeProfitPrice;
   request.expiration = expiration;
   request.type_time=ORDER_TIME_SPECIFIED;

   MqlTradeResult result;
   MqlTradeCheckResult m_check_result;

   if(!OrderCheck(request,m_check_result)){
        return false;
    }
   return OrderSend(request, result);
}


double calcLots (double riskMoney, double slDistance){
       double ticksize = SymbolInfoDouble (_Symbol, SYMBOL_TRADE_TICK_SIZE); 
       double tickvalue = SymbolInfoDouble (_Symbol, SYMBOL_TRADE_TICK_VALUE); 
       double lotstep = SymbolInfoDouble (_Symbol, SYMBOL_VOLUME_STEP);

       if(ticksize == 0 || tickvalue == 0 || lotstep==0){ return 0; }

       double moneyLotstep = (slDistance / ticksize) * tickvalue * lotstep;
       if (moneyLotstep == 0) return 0; 
       double lots = MathFloor(riskMoney/moneyLotstep) * lotstep;
      return lots;
}

 
ansar9h #:not sure if whole code will help but here is it
  • Where are you checking the Stops Level Freeze Level versus the current Ask/Bid prices?
  • Where are you aligning prices to the tick size?
  • What is the error code and trade result code?
  • Also show log output of the attempted trade, resulting errors and Ask/Bid prices at the time (Journal and Experts log).
  • You should use the OrderCalcProfit function to calculate the volume.
  • You should also check for maximum and minimum limits of volume.
  •  

    Also consider applying these checks ...

    Articles

    The checks a trading robot must pass before publication in the Market

    MetaQuotes, 2016.08.01 09:30

    Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
     

    this is the log from journal

    2023.06.17 23:56:49.942 2022.06.07 23:25:00   failed sell limit 3.08 USDJPY at 132.628 sl: 132.671 tp: 132.542 [Invalid price]


     

    ansar9h #: this is the log from journal

    2023.06.17 23:56:49.942 2022.06.07 23:25:00   failed sell limit 3.08 USDJPY at 132.628 sl: 132.671 tp: 132.542 [Invalid price]

    And the rest of the information?

    Your code is not checking the error code nor the trade result code. Please check and report it to the log.

    Your code is not checking Stops Level Freeze Level. Please check it and report Ask/Bid prices to the log too.

    Please follow-up on my other points too ...

    Forum on trading, automated trading systems and testing trading strategies

    getting error "Invalid Price Length 13" when placing an order

    Fernando Carreiro, 2023.06.17 22:51

  • Where are you checking the Stops Level versus the current Ask/Bid prices?
  • Where are you aligning prices to the tick size?
  • What is the error code and trade result code?
  • Also show log output of the attempted trade, resulting errors and Ask/Bid prices at the time (Journal and Experts log).
  • You should use the OrderCalcProfit function to calculate the volume.
  • You should also check for maximum and minimum limits of volume.
  •  

    Also pay attention to the following ... courtesy of Vladimir Karputov