EA is skipping some trades during backtesting.

 

Hello, I am new to MQL5 and may be missing something, that is why I need your help. I have simple EA that checks the performance of the indicator and it seems to work fine, but I found that it has ignored indicator conditions and hasn't opened trades several times. Can't seem to find the reason for such behavior. in the screenshot below I have marked two skipped signals with red lines. On other places with similar conditions there is no problem and trades were placed. Can you help me find the reason?  


https://www.mql5.com/en/charts/17771680/eurusd-d1-ftmo-s-r-missing-trades-in-backtesting

Chart EURUSD, D1, 2023.06.19 07:45 UTC, FTMO S.R.O., MetaTrader 5, Demo
Chart EURUSD, D1, 2023.06.19 07:45 UTC, FTMO S.R.O., MetaTrader 5, Demo
  • www.mql5.com
Chart EURUSD, D1, FTMO S.R.O.: Missing trades in backtesting
Files:
 

You should learn to debug your own code.

Either use the built-in debugger in MetaEditor, or track values by printing them out to the Experts log.

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...
 
Fernando Carreiro #:

You should learn to debug your own code.

Either use the built-in debugger in MetaEditor, or track values by printing them out to the Experts log.

Thank you for your reply. Following your advice I tried to create some sort of tracking for values and discovered something. to get last three bar values of an indicator I've used CopyBuffer function and when I printed values of each bar I noticed that values inside the buffer are not the exactly the same as indicator has given on that date. For example : If Values from indicator for three days were :

DATE 26.07.2022 27.07.2022 28.07.2022 
Indicator value on that date 1,00251 0,99975  0,99810
Buffer[0] 1,00218159 (should be data from 26.07.2022)* small difference but different value  1.00001608 (should be data from 27.07.2022)* not the same as it should be  0,99811960 (should be data from 28.07.2022)
Buffer[1]
1,00498193 (should be data from 25.07.2022) 1,00250768 (should be data from 26.07.2022)*now it is correct value  0,99975155 (should be data from 27.07.2022)* now it is correct as it should be
Buffer[2]
1,00684566 ( should be data from 24.07.2022) 1,00498193( should be data from 25.07.2022)  1,00250768 (should be data from 26.07.2022)

as you can see on the table above on 27th of july indicator gave one value but buffer registered another ( as later I calculated it is interpolated value from 26th and 28th of July) but on the bar of 28th  buffer value representing previous day value is showing what indicator showed on that day correctly. I can't understand why.

 
I think I found the issue with backtesting behaivor it is my fault. Buffer[0] getting values at the market opening first tick, while buffer[1] and buffer[2] are filled with bar close values.