Scripts and chart change - page 2

 
Ovo:

Not sure (I never tried) if the static int i=0; keeps its value after the reinit. Can you confirm?

Yes it does - so the EventSetTimer works like a continuous loop with 3 second (as above) delay.
 
sd59:
Yes it does - so the EventSetTimer works like a continuous loop with 3 second (as above) delay.
And what is your expectation (how it should behave)? I cannot see you killed or rescheduled the timer elsewhere except the init and deinit.
 
Ovo:
And what is your expectation (how it should behave)? I cannot see you killed or rescheduled the timer elsewhere except the init and deinit.

Yes as that is what is recommended in the documentation. So descriptively I want it to change charts every 3 seconds (say) for a specified number of charts i.e from 5M to H4 (5 charts) - at each change I have other code to calculate stuff and print results/parameters.

After it has finished scrolling through all charts I want it to stop until another specified time - let's say 5 minutes later. So 5 minutes later it will perform the same tasks.

At the moment the way the code is written it continuously scrolls through charts every 3 seconds.

 
sd59:

Yes as that is what is recommended in the documentation. So descriptively I want it to change charts every 3 seconds (say) for a specified number of charts i.e from 5M to H4 (5 charts) - at each change I have other code to calculate stuff and print results/parameters.

After it has finished scrolling through all charts I want it to stop until another specified time - let's say 5 minutes later. So 5 minutes later it will perform the same tasks.

At the moment the way the code is written it continuously scrolls through charts every 3 seconds.

OK, it is clear now. You may change the timer period any time. In this case right after the timeframe change, something like:

   ChartSetSymbolPeriod(0,NULL,tf[i]);   
   if(i==ArraySize(tf)-1) {
      EventSetTimer(5*60);
   }

 In case you expect the 3-second interval to be reached likely during init (all indicators on the chart would init), use rather a static variable in init() for the new schedule decision.

 
Ovo:

OK, it is clear now. You may change the timer period any time. In this case right after the timeframe change, something like:

 In case you expect the 3-second interval to be reached likely during init (all indicators on the chart would init), use rather a static variable in init() for the new schedule decision.

 

It seems the program ignores the second EventSetTimer() command. The chart change is still 3 seconds from the original in the init() function.

This is what should happen:

change to M1 chart: do calcs.....after 3 seconds

change to M15 chart: do calcs...after 3seconds

change to H4 chart: do calcs......stop chart change process for 5 minutes

resume the 3 second chart change process...then stop again for 5 minutes etc;

 
sd59: It seems the program ignores the second EventSetTimer() command.
So turn it off, then set it. If it works, tell the service desk.
 
sd59:

It seems the program ignores the second EventSetTimer() command. The chart change is still 3 seconds from the original in the init() function.

This is what should happen:

change to M1 chart: do calcs.....after 3 seconds

change to M15 chart: do calcs...after 3seconds

change to H4 chart: do calcs......stop chart change process for 5 minutes

resume the 3 second chart change process...then stop again for 5 minutes etc;

Well, it is the way I do it, setting the next timer delay in the OnTimer() multiple times. There must be some other reason.
 
WHRoeder:
So turn it off, then set it. If it works, tell the service desk.

Couldn't get the Timer() to work.

This did though.

int tf[3] = {PERIOD_M1,PERIOD_M15,PERIOD_H4};
static int j=0;

int OnInit()
{
 if(GlobalVariableGet("cnt")< ArraySize(tf))
 {
  Sleep(3000);
 }else {GlobalVariableSet("cnt",0);Sleep(20*1000);j=0;}
 Print(GlobalVariableGet("cnt"));

  
return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
 int cnt = GlobalVariableGet("cnt");
 ChartSetSymbolPeriod(0,NULL,tf[cnt]);
 
 .
 .
 SOME CALCS
 .
 .    
 GlobalVariableSet("cnt",j++);
  
}
  
 
sd59:

Couldn't get the Timer() to work.

This did though.

I tested your code, and I realized they changed (or fixed) behaviour of the ChartSetSymbolPeriod(0,NULL,...).

Last time I checked it interrupted current method to initialize the entire chart, and now it seems to finish the OnTimer() first before it runs OnDeinit & OnInit() couple. In that case, setting the long timer delay was overwritten back in the OnInit() rather than the other way round.
 
Ovo:

I tested your code, and I realized they changed (or fixed) behaviour of the ChartSetSymbolPeriod(0,NULL,...).

Last time I checked it interrupted current method to initialize the entire chart, and now it seems to finish the OnTimer() first before it runs OnDeinit & OnInit() couple. In that case, setting the long timer delay was overwritten back in the OnInit() rather than the other way round.

 

If I run the code below it shows that the ChartSetSymbolPeriod() function is out of sync with the displayed chart Period().

int tf[3] = {PERIOD_M1,PERIOD_M15,PERIOD_H4};

int OnInit()
  {
//--- create timer
   EventSetTimer(3);
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   static int i=0;
   ChartSetSymbolPeriod(0,NULL,tf[i]);   
   Print("Chart Period = ","  ",Period(),"  ","Display Chart = ",tf[i]); 
   i++;
   if(i>=3) { i=0; };
  }
//+------------------------------------------------------------------+


If I change the chart symbol I would have expected it to show under Period()!!

Am I doing something wrong here?