ChartSetSymbolPeriod on Strategy Tester for different time frames

 

Hi everyone!


I've been working on a price action EA and I would like to optimize on strategy tester different timeframes (i.e. from PERIOD_M1 to PERIOD_D1) but I cannot make it works.

I created a input variable for timeframe in the Input Variables

input ENUM_TIMEFRAMES TempoGrafico;

and tested it on every test event (OnTester, OnTesterInit, OnTesterPass and OnTesterDeinit) with the code beneath 

ChartSetSymbolPeriod(ChartID(),Symbol(),TempoGrafico);

...none of them work!


If I use the code above on the OnInit() event it works, but with this I just can force the EA to use the timeframe inputed, it is not actually what I need.

Has anybody any idea to help?

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
  1. elieserra: but I cannot make it works.

    “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  2. Stop trying to change the chart in the tester. Just read the prices of the period you want.

 
William Roeder #:
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  2. Stop trying to change the chart in the tester. Just read the prices of the period you want.

Sorry but when I say "it does not work" I mean it does not change timeframe on the tester. 

Actually what I'm trying to do is to use the time frame as a parameter so that I can optimize it with the others EA parameters.

 
You are misinterpreting the usage of OnTester, OnTesterInit, OnTesterPass and OnTesterDeinit

OnTester is called after a successful run of the EA in the tester.

OnTesterInit, OnTesterPass and OnTesterDeinit are run within a special instance created and have nothing to do with the EA itself.

It is run separately, next to the EA instances being tested and is used to receive the results from the tested EAs.

Read the docs here:


 
Dominik Christian Egert #:
You are misinterpreting the usage of OnTester, OnTesterInit, OnTesterPass and OnTesterDeinit

OnTester is called after a successful run of the EA in the tester.

OnTesterInit, OnTesterPass and OnTesterDeinit are run within a special instance created and have nothing to do with the EA itself.

It is run separately, next to the EA instances being tested and is used to receive the results from the tested EAs.

Read the docs here:


tks friend! I'll check it out
 
elieserra #:
tks friend! I'll check it out
Hi Eliserra,

I have come across the same problem.

Were you able to figure out how you can do it?

Thanks.
 
Abhishek Jiyani #: Hi Eliserra, I have come across the same problem. Were you able to figure out how you can do it? Thanks.

I suggest then that you read the thread from beginning to end again.

And in the case that your issue is different to the OP's, then describe it in detail.

 
Fernando Carreiro #:

I suggest then that you read the thread from beginning to end again.

And in the case that your issue is different to the OP's, then describe it in detail.

I have an EA and when I do a back test, i manually select the time frame and run the back test. in the end, I want to run this EA on all Time frames.

How do I make this EA run on all Time frames from my code?
 
Abhishek Jiyani # I want to run this EA on all Time frames.

How do I make this EA run on all Time frames from my code?

You don't; it runs on the tester's timeframe. You have it trade all timeframes. Timeseries and Indicators Access

 
William Roeder #:

You don't; it runs on the tester's timeframe. You have it trade all timeframes. Timeseries and Indicators Access


Thank You for the response.

I still did not get you.

If you could explain with an example or a testable solution, it would be helpful. 

Thanks.

 
Abhishek Jiyani #: If you could explain with an example or a testable solution, it would be helpful.
Not compiled, not tested, just typed.
input int Magic=20221109;
#define MAGIC_END (Magic+ST_COUNT)
void OnTick(){
   for(int iPos=PositionsTotal()-1; iPos>=0; --iPos) if(
      PositionGetSymbol(iPos) == _Symbol
   ){
      int mn   = PositionGetInteger(POSITION_MAGIC);
      if(Magic <= mn && mn < MAGIC_END){
         Standard_TF tf = mn - Magic;
         trail_position(period[tf]);
         return;
      }
   }
   // No open positions.
   for(Standard_TF tf=ST_FIRST; tf <= ST_COUNT; ++tf){
      int mn = Magic + tf;
      if(open(period[tf], mn) ) break;
   }
}
bool open(ENUM_TIMEFRAMES period, int mn){
   while(!download_history(period)) Sleep(5);
   if(is_new_bar(period)){
      double c1=iClose(_Symbol, period, 1);
      double c2=iClose(_Symbol, period, 2);
      if(c1 > c2) return Buy(mn);
   }
   return false;
}
Not compiled, not tested, just typed.
          detecting a new bar without removing ability to detect tick in multiple timeframe - Easy Trading Strategy - MQL4 programming forum #8 (2021.08)
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)
Reason: