Changing chart period on tick with ChartSetSymbolPeriod

 
Is it possible to change chart period with an expert advisor  on tick?I'm using this code  but having issues. Can one help?
void  0ntick()

if (adx0>5)
{
move_to_a_different_TF();
}

..
 my function

 void move_to_a_different_TF()
{
   
   //;
   ChartSetSymbolPeriod(0, NULL, PERIOD_H1);
}
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Chart Timeframes - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Please help
 
Peter Kaiza: Is it possible to change chart period with an expert advisor on tick?

Yes, but ... "The symbol/period change leads to the re-initialization of the Expert Advisor attached to a chart."

Peter Kaiza: I'm using this code but having issues. Can one help?

Then describe in detail what issues you are having. We can't help if you don't tell us what they are.

Also, when providing sample code, please make sure that it compiles or that at least a proper structure is presented. Otherwise we don't know if the problem is the lack of properly structured code or something else.

 
Peter Kaiza: Is it possible to change chart period with an expert advisor  on tick?I'm using this code  but having issues. Can one help?
Peter Kaiza #: Please help

Help you with what? You haven't stated a problem.

"but having issues" 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

 

void OnTick()                      
{
if ( fmod(TimeLocal(),10)>5)
{
move_to_a_different_TF_1();
}
else
{
move_to_a_different_TF_2();
}
}

void move_to_a_different_TF_1()
{
   ChartSetSymbolPeriod(0, NULL, PERIOD_H1);
}
void move_to_a_different_TF_2()
{
   ChartSetSymbolPeriod(0, NULL, PERIOD_M1);
}



Your code works perfectly
<but market will be closed soon and there will be no ticks>
<<use Tester then or function OnTimer() instead of OnTick()>>

Reason: