First thing. Revisit your usage if Static variables. Static Variables are only initalised once. This means second time
you call the function it will hve the value it finished with last time you called the function.. This is a bug.
Secondly, how about you
output the value Month(). Could this be the current month? Ie April right now and not be related to the month your testing
in backtester?
- www.mql5.com
First thing. Revisit your usage if Static variables. Static Variables are only initalised once. This means second
time you call the function it will hve the value it finished with last time you called the function.. This is a bug.
Secondly, how
about you output the value Month(). Could this be the current month? Ie April right now and not be related to the
month your testing in backtester?
Regarding static variables.
- The idea of static variable is understood. Indeed it is initialized only once. So, the first time it runs it has zero value.
- While it keeps running it checks if the initialized variable value currentMonth has changed.
- If it changed it means I must go inside the else clause. I zero the return variable, currentYear and currentMonth.
- Next time it runs it will be with the month correct and should account for the profits in history for the new month.
Maybe the problem is the acquisition of time data;
The MQL4 documentation says
During testing in the Strategy Tester, TimeCurrent() is simulated according to historical data.
The Month and Year instructions work as expected. I outputed the value of the variables in a log file. But maybe the speed of strategy tester is faster then desired. There are many cases when I backtest a EA at highest speed that after the test stops the console output is still receiving instructions and printing things finishing after sometime. Maybe this could be happening with some instructions as well.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I read articles about it here at this forum, one in particular is this one (https://www.mql5.com/en/forum/154009). But so far it is not calculating as expected during Strategy Tester.
My goal is to create a method to account the profits accrued during the time the EA is running and check if the the target goal of profitability is or not achieved month by month.
My problem is that I have Closed Orders with profits in mu history, with the Magic Number correct and within the current month and year but when I select it and try to get the OrderProfits I get ZERO.
Is there any better way to do that?
Is this method working the way it should?
Thanks a lot