Problems with the strategy tester

 

Hi guys, I'm new here.

 amax[0] = iHigh(0,PERIOD_M1,0);

   amax[1] = iHigh(0,PERIOD_M1,1);

   amax[2] = iHigh(0,PERIOD_M1,2);

   amin[0] = iLow(0,PERIOD_M1,0);

   amin[1] = iLow(0,PERIOD_M1,1);

   amin[2] = iLow(0,PERIOD_M1,2);

....


I have an array like this, and after more rows. Now if I put this code OnInit() it works, it returns the values of last three bars and i can compare and do operations with the single values. But if I move the same code in OnTick() (I think on live markets it will be still working) on strategy tester it continues to return the last three bars of the whole chart. But I would like it will return the values like it would be on real time. The bar is testing and the previous ones. For example value 0 is relative to 12 hours ago, the moment is testing...is there a way to fix?

 
florenceale:

Hi guys, I'm new here.


I have an array like this, and after more rows. Now if I put this code OnInit() it works, it returns the values of last three bars and i can compare and do operations with the single values. But if I move the same code in OnTick() (I think on live markets it will be still working) on strategy tester it continues to return the last three bars of the whole chart. But I would like it will return the values like it would be on real time. The bar is testing and the previous ones. For example value 0 is relative to 12 hours ago, the moment is testing...is there a way to fix?


MT4 or MT5?

And what is your testing method (OHLC/Open prices/Real ticks... )?  If you want real time, test on real ticks, or generated ticks. Other mehtods work on full bars only.

Lastly but less likely your logic can be the issue.

 
 amax[0] = iHigh(0,PERIOD_M1,0);
  1. Zero is not a valid symbol name. Use _Symbol
  2. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
             Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
    On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
             Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
 
florenceale:

I have an array like this, and after more rows. Now if I put this code OnInit() it works, it returns the values of last three bars and i can compare and do operations with the single values. But if I move the same code in OnTick() (I think on live markets it will be still working) on strategy tester it continues to return the last three bars of the whole chart. But I would like it will return the values like it would be on real time. The bar is testing and the previous ones. For example value 0 is relative to 12 hours ago, the moment is testing...is there a way to fix?

You should not use periods other than the period selected in the tester settings. And to request timeseries for current period you should specify 0 in the second parameter, so the following should work:

double H1 = iHigh(NULL, 0, 1);
double L1 = iLow(NULL, 0, 1);

Using NULL instead the current symbol and 0 instead of current period is perfectly well and conform to the documentation.

 
Stanislav Korotky:

You should not use periods other than the period selected in the tester settings. And to request timeseries for current period you should specify 0 in the second parameter, so the following should work:

Using NULL instead the current symbol and 0 instead of current period is perfectly well and conform to the documentation.

Am I misunderstanding your post?

In the Strategy Tester, you CAN use different time-frames (I do it all the time), but you just have to handle the 4066/4073 errors as @whroeder1 pointed out.

Or did you just mean that it is a better practice to code only for current time-frame, but not necessarily a limitation?

 
Fernando Carreiro:

In the Strategy Tester, you CAN use different time-frames (I do it all the time), but you just have to handle the 4066/4073 errors as @whroeder1 pointed out.

Or did you just mean that it is a better practice to code only for current time-frame, but not necessarily a limitation?

Probably your last sentence is most close to what I mean. I find it "strange" to run the tester on any higher timeframe and request bars from lower ones (which M1 surely is).

 
Stanislav Korotky: Probably your last sentence is most close to what I mean. I find it "strange" to run the tester on any higher timeframe and request bars from lower ones (which M1 surely is).

Well, there can be several justifiable reasons (at least two in my case):

  1. When the strategy is Muti-Time-frame. For example, the "3 Ducks Strategy" that places orders on M5 Chart, but uses conditions of the H1 and H4 to define the entry rules. EDIT: I have also used it for a strategy on H1 that requires a breakdown on M1 bars to define and filter the H1 entry. So it can be used both for top-down or bottom-up, multi-time-frame strategies.
  2. Another, is when one wants to test a strategy against multiple Time-frames, and instead of manually testing each one, we can use an "extern"/"input" variable to select the reference time-frame and can thus use Optimisation passes (with different variations of other parameters) to test each time-frame in various situations.
  3. There may be others reasons too.

So, I cannot agree that it is a "better practice", because it really depends on the situation.

Maybe for beginners it might be a good idea to help get them on the right track, but that is as far as I would take it - a recommendation until they are familiar with coding and testing, but not necessarily as a "better practice" rule.

 
Fernando Carreiro:

Well, there can be several justifiable reasons (at least two in my case):

  1. When the strategy is Muti-Time-frame. For example, the "3 Ducks Strategy" that places orders on M5 Chart, but uses conditions of the H1 and H4 to define the entry rules. EDIT: I have also used it for a strategy on H1 that requires a breakdown on M1 bars to define and filter the H1 entry. So it can be used both for top-down or bottom-up, multi-time-frame strategies.
  2. Another, is when one wants to test a strategy against multiple Time-frames, and instead of manually testing each one, we can use an "extern"/"input" variable to select the reference time-frame and can thus use Optimisation passes (with different variations of other parameters) to test each time-frame in various situations.
  3. There may be others reasons too.

So, I cannot agree that it is a "better practice", because it really depends on the situation.

Maybe for beginners it might be a good idea to help get them on the right track, but that is as far as I would take it - a recommendation until they are familiar with coding and testing, but not necessarily as a "better practice" rule.

I'd prefer to discuss the matter only after the original poster share with us what was the cause of his problem. From my experience, usage of timeframes other than selected timeframe in the tester can potentially lead to some unexpected results under some conditions. So a developer should be indeed very familiar with the coding and testing to keep an eye on this.

 
Stanislav Korotky: From my experience, usage of timeframes other than selected timeframe in the tester can potentially lead to some unexpected results under some conditions.

Of course it can, therefor I provided the solution in #2.2