Invalid Price by strategy tester.

 

Hlw , i am using buy limit and sell limit for market orders. I am using the following code to return if the price difference is less than spread and stop level. It works fine for sell limits but for buy limit there is error{Invalid price}.

    if(entryh1 - bid  < (stopLevel + spread) * _Point){      
      Print("Price is too near the execution level");  
      return;
       }    

    if(MathAbs(ask - entryl1) < (stopLevel + spread) * _Point){ 
      Print("Price is too near the execution level");     
      return;
       }    

entryh1 is sell limit which works fine, but entry l1 which is buy limit shows error. Thank you in advance for your response.

 
Abhishek Yadav:

Hlw , i am using buy limit and sell limit for market orders. I am using the following code to return if the price difference is less than spread and stop level. It works fine for sell limits but for buy limit there is error{Invalid price}.

entryh1 is sell limit which works fine, but entry l1 which is buy limit shows error. Thank you in advance for your response.

  1. What you showed is not the relevant code.
  2. What is written in the logs?
  3. Use this to check the right place of the prices for stop, limit, sl, and tp:

 
Carl Schreiber #:
  1. What you showed is not the relevant code.
  2. What is written in the logs?
  3. Use this to check the right place of the prices for stop, limit, sl, and tp:

Hey, thnks for where to put buy and sell limit, i have done the same. The thing is for buy limit the tp price becomes smaller than entry price. Isn't this error for [Invalid SL]. I am getting it for INVALID PRICE. Also i added the code for the case where tp is smallar than entry price but it doesn't work.

   
    if(tp > 0 && tp < entryl1 ){
      Print("Tp distance is too close.");
     return;
     }   //
    if(tp > 0 && tp < entryl2 ){
      Print("Tp distance is too close.");
     return;
     }   //
    if(tp > 0 && tp < entryl3 ){
      Print("Tp distance is too close.");
     return;
     }   //
    if(tp > 0 && tp < entryl4 ){  // 
      Print("Tp distance is too close.");
     return;
     }   //
Files:
Capture.JPG  36 kb
 
Abhishek Yadav #:

Hey, thnks for where to put buy and sell limit, i have done the same. The thing is for buy limit the tp price becomes smaller than entry price. Isn't this error for [Invalid SL]. I am getting it for INVALID PRICE. Also i added the code for the case where tp is smallar than entry price but it doesn't work.

Carl Schreiber #:
  1. What you showed is not the relevant code.
  2. What is written in the logs?
  3. Use this to check the right place of the prices for stop, limit, sl, and tp:

test on EURUSD,H1 (netting)
 2020.04.01 00:05:30   failed buy limit 1 EURUSD at 1.11048 sl: 1.08951 tp: 1.10349 [Invalid price]
 2020.04.02 00:05:05   failed buy limit 1 EURUSD at 1.10366 sl: 1.08117 tp: 1.09616 [Invalid price]
 2020.04.03 00:05:04   failed buy limit 1 EURUSD at 1.09378 sl: 1.06948 tp: 1.08568 [Invalid price]
 2020.04.07 00:05:12   failed buy limit 1 EURUSD at 1.08290 sl: 1.07181 tp: 1.07920 [Invalid price]
 2020.04.08 00:05:03   failed buy limit 1 EURUSD at 1.09688 sl: 1.07337 tp: 1.08904 [Invalid price]
 2020.04.10 00:05:30   failed buy limit 1 EURUSD at 1.09893 sl: 1.08068 tp: 1.09285 [Invalid price]
 2020.04.15 00:05:30   failed buy limit 1 EURUSD at 1.10284 sl: 1.08827 tp: 1.09798 [Invalid price]
 2020.04.16 00:05:05   failed buy limit 1 EURUSD at 1.09806 sl: 1.07587 tp: 1.09066 [Invalid price]
 2020.04.17 00:05:03   failed buy limit 1 EURUSD at 1.08906 sl: 1.07347 tp: 1.08386 [Invalid price]
 2020.04.23 00:05:06   failed buy limit 1 EURUSD at 1.08679 sl: 1.07328 tp: 1.08229 [Invalid price]
 
If it says invalid price the prices of your order aren't correct - print all(!) prices in this case and compare them with the image above!
 
Carl Schreiber #:
If it says invalid price the prices of your order aren't correct - print all(!) prices in this case and compare them with the image above!

Thank You so much. I printed all the values and found i was placing buy limits at wrong level. This was a lot helpful.

 

Here are some hints what to do to detect errors in one owns program:

Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug
Error Handling and Logging in MQL5:  https://www.mql5.com/en/articles/2041
Tracing, Debugging and Structural Analysis of Source Code, scroll down to: "Launching and Debuggin": https://www.mql5.com/en/articles/272

Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
Reason: