Sometimes i get the INVALID PRICE error

To add comments, please log in or register
Leonardo Fernandez
46
Leonardo Fernandez  

I`ve been able to make my EA work, it should trade haramis, but it`s not trading all of them, sometimes i get the INVALID PRICE error


Could someone help me please?



The code places a buystop and a sellstop order at the high and low of the harami


void OnTick()
  {
  
    CopyRates(Symbol(), Period (), 0, 3, rates);
    
    double maxCurrent = rates[1].high;
    double minCurrent = rates[1].low;
    
    double maxPrev = rates[2].high;
    double minPrev = rates[2].low;
    
    double newHigh = rates[0].high;
    double newLow = rates[0].low;
    
    
    if(maxPrev > maxCurrent && minPrev < minCurrent) 
    
    
    {
    
      
    if(OrdersTotal()==0 && PositionsTotal()==0) 
    
    
    {
      
      
    if(maxCurrent < newHigh && minCurrent < newLow)
    {
   
           
         trade.BuyStop(5, maxCurrent + 0.00010, _Symbol, minCurrent + 0.00010, maxCurrent+ 0.00110, 0, 0, "");
  
}
else

     if(maxCurrent > newHigh && minCurrent > newLow)

           {  trade.SellStop(5, minCurrent - 0.00010, _Symbol, maxCurrent + 0.00010, minCurrent - 0.00110, 0, 0, "");
           
            }
            
           }
       }
         
   }
William Roeder
21807
William Roeder  
Leonardo Fernandez: sometimes i get the INVALID PRICE error … The code places a buystop and a sellstop order at the high and low of the harami
  1. You enter the trade, get stopped out, then try to open the same trade again. What do you expect?
  2. Try opening only at the start of a new bar.
Leonardo Fernandez
46
Leonardo Fernandez  
William Roeder:
  1. You enter the trade, get stopped out, then try to open the same trade again. What do you expect?
  2. Try opening only at the start of a new bar.

Thank you for replying,


Could you please point me a direction of how i could do that? I am fairly new to mql5

William Roeder
21807
William Roeder  
Use this and you will find "new bar."
Leonardo Fernandez
46
Leonardo Fernandez  
William Roeder:
Use this and you will find "new bar."

    I have at least 25 tabs open trying to find an answer, i am struggling to do that, i though that maybe someone could point a direction, maybe point out i got a line of code wrong or if it was a big code than just tell me what i should study, to find the answer of a question first it need to be already asked and none of the answers i found were able to satisfy what i needed to know.

    I came here because i wanted to know what i need to study to solve my problem, no need to be rude.


   I cant understand why the EA works fine for some candles and sometimes it just dont for others even though they follow the same rules.

Alain Verleyen
40325
Alain Verleyen  
Leonardo Fernandez:

    I have at least 25 tabs open trying to find an answer, i am struggling to do that, i though that maybe someone could point a direction, maybe point out i got a line of code wrong or if it was a big code than just tell me what i should study, to find the answer of a question first it need to be already asked and none of the answers i found were able to satisfy what i needed to know.

    I came here because i wanted to know what i need to study to solve my problem, no need to be rude.


   I cant understand why the EA works fine for some candles and sometimes it just dont for others even though they follow the same rules.

Because you don't your check prices against the market. There are rules to follow about open/stoploss/takeprofit.

See here (mql4 link but it works the same (usually) with mql5).

Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Tables below show calculation values that limit the conduction of trades when opening, closing, placing, deleting or modifying orders. To get the minimum distance to StopLevel and freezing distance FreezeLevel the MarketInfo() function should be called. Requirements. Correct prices used when performing trade operations. Order Type Open Price...
WindmillMQL
164
WindmillMQL  
Leonardo Fernandez:

I`ve been able to make my EA work, it should trade haramis, but it`s not trading all of them, sometimes i get the INVALID PRICE error


Could someone help me please?



The code places a buystop and a sellstop order at the high and low of the harami


I notice that you do calculations with doubles before arriving at a price which you submit. Sometimes these calculations result in rounding errors. For example you get a value like 1.23000001. If you submit such a value you will get an error. In those cases you have to round the resulting value to the nearest valid price before submitting it.
To add comments, please log in or register