does anybody know the answer?
thank you
1) One of my input variables is SimTimeFrame (input ENUM_TIMEFRAMES SimTimeFrame );
2) In the tab "Settings" I set the time frame to "M1", and set Modeling to "Every tick based on real ticks"
3) I run the optimization with "Custom max."
4) In the tab "Optimization Results" I select one of the results with SimTimeFrame = PERIOD_M10 (for example), with a Profit of value X1, and run it by double clicking on it;
5) In the tab "Backtest" I get a "Total Net Profit" of value X1 as well.
So far so good. Now comes the finding:
6) In the tab "Settings," if I change the time frame to any other different to the original "M1" that I used to run the optimization, then I don't get the same profit of value X1 in the Backtest when running the same combinations of input variable from the Optimization Results table.
In the EA code, I only use SimTimeFrame when needed (e.g., PeriodSeconds(SimTimeFrame), etc.)
Questions:
Q1) How can I avoid having different results depending on the time frame chosen in the Settings tab?
Q2) What am I doing wrong? Can this be fixed?
thank you
2 & 6) Obviously, your code is depending and referencing the current time-frame in its calculations, and when you change it in the settings, it affects the calculations and operations causing the results to be different.
Q1) If you want your EA to only use the referenced time-frame in the "SimTimeFrame" input, then you have to make sure that your code is only using that and not the current time-frame in its calculations.
In conclusion, your program is only doing what you programmed it to do. If you need help with your code, then you will have to show all the relevant code.
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Thank you Fernando, you always helping.
As I wrote initially after point 6), I use the input variable SimTimeFrame every time I need to use the time frame for any calculation or any indicator I call (for instance iMA, iRSI, iATR, etc.). I don't use PERIOD_CURRENT, or _Period, or such.
I use SimTimeFrame sprinkled in multiple lines of my muti-file EA code. Here are some example lines:
Line 48: input ENUM_TIMEFRAMES SimTimeFrame = PERIOD_M5; Line 268: g_FixedRiskMoney.Init(GetPointer(g_symbol),SimTimeFrame, g_symbol.Point()); Line 294: ChartSetSymbolPeriod(0,g_symbolName,SimTimeFrame); Line 465: h_ATR=iATR(g_symbolName,SimTimeFrame, MathMax(3,atr_period)); Line 235: g_maxBarsAllowed=(int)MaxDaysOpen*24*3600/PeriodSeconds(SimTimeFrame); Line 299: g_time_lastLocalCloseMin = iTime(g_symbolName,SimTimeFrame,0); Line 300: g_time_lastLocalCloseMax = iTime(g_symbolName,SimTimeFrame,0); Line 301: startingDate = iTime(g_symbolName,SimTimeFrame,0); Line 400: Print("===: OnInit, PeriodSeconds(SimTimeFrame)=", PeriodSeconds(SimTimeFrame)); Line 411: string st=EnumToString(SimTimeFrame);
Obviously, these lines do not help much, because they are using the correct SimTimeFrame. They are not the lines (or the lack of lines) that are causing the problem. I search my entire code and there are no reference to other time frame but SimTimeFrame;
I also tried using the CExpertBase variable g_Expert which I initialize like this:
CSymbolInfo g_symbol; // symbol info object CExpertBase g_Expert; . . . // in OnInit(): g_symbolPoint= g_symbol.Point(); if(!g_Expert.Init(&g_symbol,SimTimeFrame,g_symbolPoint)) { //--- failed printf(__FUNCTION__+": error initializing expertBase"); return(INIT_FAILED); }
but I got the same behavior. I tried using the CExpert class, but it was complaining about the time frame Period() being different to SimTimeFrame during the initialization
You may state that, but the results state otherwise. Somewhere in your code is something that does depend on the current time-frame. What that is, only you will be able to find out by analysing and debugging your code.
However, I do not see any code in your sample for detecting the start of a new bar. Could the problem be there?
ChartSetSymbolPeriod(0,g_symbolName,SimTimeFrame);
Please note, that using that function to change the current symbol or timeframe can cause the EA to restart, so I would not recommend using it, unless your code properly handles that situation.
Personally, I do not use the Standard Library because I simply do not trust it. So, I cannot say if it is the cause or not.
You may state that, but the results state otherwise. Somewhere in your code is something that does depend on the current time-frame. What that is, only you will be able to find out by analysing and debugging your code.
However, I do not see any code in your sample for detecting the start of a new bar. Could the problem be there?
Please note, that using that function to change the current symbol or timeframe can cause the EA to restart, so I would not recommend using it, unless your code properly handles that situation.
Personally, I do not use the Standard Library because I simply do not trust it. So, I cannot say if it is the cause or not.
thank you, Fernando.
The ChartSymbolPeriod function is not the problem. I commented it and I get the same behavior.
I double checked the start-of-a-new-bar code, and there is nothing there either.
I don't use the CExpert nor the CExpertBase; I just tried them to see if I could resolved the issue, but they didn't help.
I will keep debugging the code until I find the issue, then I will post what was causing the problem.
I don't use the CExpert nor the CExpertBase; I just tried them to see if I could resolved the issue, but they didn't help. I will keep debugging the code until I find the issue, then I will post what was causing the problem.
I would suggest attaching your full code so that we can have a look and see if can spot the problem.
If you are not comfortable showing it in public, then you can send it to me in private for review.
However, do that only if you are willing to accept my answers here in the forum in the spirit of open collaboration.
Fernando,
Thank you for your offer to debug it.
I wouldn't be comfortable revealing the multiple strategies and algorithms I have developed over the years.
I would get back once I resolve this.
thank you
Fernando,
Thank you for your offer to debug it.
I wouldn't be comfortable revealing the multiple strategies and algorithms I have developed over the years.
I would get back once I resolve this.
thank you
Thank you, Yashar.
I tried all four ways (HLOC, open, tick, real ticks) all have the same behavior in my case.
I keep debugging.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
1) One of my input variables is SimTimeFrame (input ENUM_TIMEFRAMES SimTimeFrame );
2) In the tab "Settings" I set the time frame to "M1", and set Modeling to "Every tick based on real ticks"
3) I run the optimization with "Custom max."
4) In the tab "Optimization Results" I select one of the results with SimTimeFrame = PERIOD_M10 (for example), with a Profit of value X1, and run it by double clicking on it;
5) In the tab "Backtest" I get a "Total Net Profit" of value X1 as well.
So far so good. Now comes the finding:
6) In the tab "Settings," if I change the time frame to any other different to the original "M1" that I used to run the optimization, then I don't get the same profit of value X1 in the Backtest when running the same combinations of input variable from the Optimization Results table.
In the EA code, I only use SimTimeFrame when needed (e.g., PeriodSeconds(SimTimeFrame), etc.)
Questions:
Q1) How can I avoid having different results depending on the time frame chosen in the Settings tab?
Q2) What am I doing wrong? Can this be fixed?
thank you