Loop in script every 15 min

 

Hello, 


I have a script: for making screenshots. I want to run it automatically instead of clicking on the script. Does anyone know how I can change this script so it will run every 15 min? 

Thanks in advance. 


void OnStart()
{
   //--
   // if(TimeCurrent() >= D'2018.12.15'){
   //    MessageBox("Testing Period is finished!");
   //    return ;
   // }
   //--
   long chartId = ChartFirst();
   while(chartId != -1)
   {
      string fileName = ChartSymbol(chartId) + "-M" + string(ChartPeriod(chartId))  + ".png" ;
      int width  = 1871;(int) ChartGetInteger(chartId, CHART_WIDTH_IN_PIXELS);
      int height = 871;(int) ChartGetInteger(chartId, CHART_HEIGHT_IN_PIXELS);
        ChartScreenShot( chartId, fileName, width, height );
  
 
      //--
      chartId = ChartNext(chartId);
   }
}
//+------------------------------------------------------------------+
 
dMartijn Rikkert:

Hello, 


I have a script: for making screenshots. I want to run it automatically instead of clicking on the script. Does anyone know how I can change this script so it will run every 15 min? 

Thanks in advance. 


int OnStart(void)
  {
     if(!EventSetTimer(15 * PeriodSeconds(PERIOD_M1)))
       {
         Print("error setting timer : ",GetLastError());
         return(-1);
       } 
     return(0);    
  }

And in OnTimer all logic


void OnTimer(void)
  {
   //--
   // if(TimeCurrent() >= D'2018.12.15'){
   //    MessageBox("Testing Period is finished!");
   //    return ;
   // }
   //--
   long chartId = ChartFirst();
   while(chartId != -1)
   {
      string fileName = ChartSymbol(chartId) + "-M" + string(ChartPeriod(chartId))  + ".png" ;
      int width  = 1871;(int) ChartGetInteger(chartId, CHART_WIDTH_IN_PIXELS);
      int height = 871;(int) ChartGetInteger(chartId, CHART_HEIGHT_IN_PIXELS);
        ChartScreenShot( chartId, fileName, width, height );
  
 
      //--
      chartId = ChartNext(chartId);
   }
 }
did not try and did not compile

** sorry, of course OnStart and not OnInit. Updated source

 
Amir Yacoby:

And in OnTimer all logic


did not try and did not compile

** sorry, of course OnStart and not OnInit. Updated source

The script is still removing and itself

 
You have to make an ea and unse ontimer function