Invalid Price

 

BuyStop Error

Anybody help. i have a BUYLIMIT placed. when EA modify the order it reach me the above error "INVALID PRICE". attached JPEG message display my Ticket#, New BUYLIMIT, ctrade, CURRENT BID price. this is a 2days headache whats wrong of my BUYLIMIT price. I ask anybody to give me a any idea for this matter. thanks a lot in advanced.

 
Michael Quinatadcan Macasil Macasil :

Anybody help. i have a BUYLIMIT placed. when EA modify the order it reach me the above error "INVALID PRICE". attached JPEG message display my Ticket#, New BUYLIMIT, ctrade, CURRENT BID price. this is a 2days headache whats wrong of my BUYLIMIT price. I ask anybody to give me a any idea for this matter. thanks a lot in advanced.

Where is your code? Are you normalizing the price?

 
Vladimir Karputov:

Where is your code? Are you normalizing the price?

void OnTick()
  {
   pB=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
  }
void andriodTradingSell()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      int ticket=(int)OrderGetTicket(i);
      if(ticket>0)
        {
         if(OrderGetString(ORDER_SYMBOL)==ChartSymbol())
           {
            if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_LIMIT)
              {
               trade.OrderModify(OrderGetTicket(i)
                                 ,pB+5*_Point
                                 ,pB+setSL*_Point
                                 ,pB-setTP*_Point,ORDER_TIME_DAY,0,0);
               }
           }
        }
     }
  }

2021.04.09 06:56:47.718 AT210409 (GOLD,M15)

CTrade::OrderSend: modify #387560891 at 

1754.73 (sl: 1753.73 tp: 1764.78) [invalid price]


2021.04.09 08:05:49.279 Trades '62114140': failed modify order #387560891 

buy limit 0.01 GOLD at 

1712.00000 sl: 0.00000 tp: 0.00000 expiration: gtc -> 

1754.98000, sl: 1753.60000 tp: 1765.03000 expiration: day [Invalid price]


2021.04.09 08:38:47.767 AT210409 (GOLD,M15)

CTrade::OrderSend: modify #387560891 at 

1754.51 (sl: 1752.81 tp: 1764.56) [invalid price]


2021.04.09 09:35:00.421 Trades '62114140': failed modify order #387583943 

sell limit 0.01 GOLD at 

1774.00000 sl: 0.00000 tp: 0.00000 expiration: day -> 

1755.53000, sl: 1757.56000 tp: 1745.48000 expiration: day [Invalid price]


2021.04.09 09:35:00.421 AT210409 (GOLD,M15) 387583943

2021.04.09 09:35:00.421 AT210409 (GOLD,M15) 1755.48

2021.04.09 09:35:00.421 AT210409 (GOLD,M15) CTrade::OrderSend: modify #387583943 at 1755.53 (sl: 1757.56 tp: 1745.48) [invalid price]

***above text from my save notepad 

**your knowledge  help me to improve my Learning about MT5. thanks and im waiting your early reply.

 
Try using NormalizeDouble on your price/sl/tp values.

If in doubt, printf them to the journal and see what you are passing in.

And you might want to do an OrderSelect() for reliability....

https://www.mql5.com/de/docs/trading/orderselect

 

This is the correct way to round order prices

void andriodTradingSell()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      int ticket=(int)OrderGetTicket(i);
      if(ticket>0)
        {
         if(OrderGetString(ORDER_SYMBOL)==ChartSymbol())
           {
            if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_LIMIT)
              {              
               pB=SymbolInfoDouble(_Symbol,SYMBOL_BID);
               trade.OrderModify(OrderGetTicket(i)
                                 ,NormalizeDouble(pB+5*_Point,_Digits)
                                 ,NormalizeDouble(pB+setSL*_Point,_Digits)                                 
                                 ,NormalizeDouble(pB-setTP*_Point,_Digits),ORDER_TIME_DAY,0,0);
               }
           }
        }
     }
  }
 
amrali:

This is the correct way to round order prices

I cannot stress this enough, obviously.


My suggestion: RTFM. - It states precisly why you need to do an OrderSelect() before you rely on data given by OrderGet*().


https://www.mql5.com/en/docs/trading/orderselect


Function OrderSelect() copies data about an order into the program environment, and further calls of OrderGetDouble()OrderGetInteger()OrderGetString() return the earlier copied data.

Documentation on MQL5: Trade Functions / OrderSelect
Documentation on MQL5: Trade Functions / OrderSelect
  • www.mql5.com
OrderSelect - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
I always round off prices using the CSymbolInfo :: NormalizePrice method
Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / NormalizePrice
Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / NormalizePrice
  • www.mql5.com
NormalizePrice(double) - CSymbolInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Michael Quinatadcan Macasil Macasil:

Anybody help. i have a BUYLIMIT placed. when EA modify the order it reach me the above error "INVALID PRICE". attached JPEG message display my Ticket#, New BUYLIMIT, ctrade, CURRENT BID price. this is a 2days headache whats wrong of my BUYLIMIT price. I ask anybody to give me a any idea for this matter. thanks a lot in advanced.

According to this:


the price of the buy-limit has to be less than the actual price and SL and TP must not be to close to limit price. Print all the relevant prices and specifications and check it. Gold is different that than normal Forex.

 
Vladimir Karputov:
I always round off prices using the CSymbolInfo :: NormalizePrice method
Thanks Vladimir. Good point. 
 
Carl Schreiber:

According to this:


the price of the buy-limit has to be less than the actual price and SL and TP must not be to close to limit price. Print all the relevant prices and specifications and check it. Gold is different that than normal Forex.


Refering to: "Gold is different that than normal Forex. "

This is not always true. - There are brokers that have the calculations set to forex for gold. XAUUSD

 
Guys, your ideas and knowledge regarding my concern are much appreciated. I didn't experienced any problems regarding INVALID PRICE from one broker but the other broker I had. From your post, I'll try to improve my skills. Quoted above " the price of the buy-limit has to be less than the actual price and SL and TP must not be to close to limit price. ", I didn't violate that rule. " This is the correct way to round order prices" ok thanks. " I always round off prices using the CSymbolInfo :: NormalizePrice method" thanks, I'll try this one. I'll send feedback this Monday after Asia market.

My last concern

the invalid price maybe came from what?

Reason: