Download MetaTrader 5
To add comments, please log in or register
Interested in MetaTrader 5 features? Learn more about them!
faustf
84
faustf 2016.06.06 15:48 

hi  guy  how  to  kill the  timer ???


i study a script 


//+------------------------------------------------------------------+
//|                                                    TimerTest.mq4 |
//|                                       Copyright 2014, aforexpert. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, aforexpert."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| expert include                                                   |
//+------------------------------------------------------------------+
#include <stdlib.mqh>

//--- input parameters
input ushort   seconds=10;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   if(!EventSetTimer(seconds))
     {
      int error=GetLastError();
      PrintFormat("EventSetTimer FAILED: #%d[%s]", error, ErrorDescription(error));
     }
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   Print("OnTimer  dopo 10 eccomi ");
  }
//+------------------------------------------------------------------+


i  test  in my demo and  i see after 10 second  write  somthing , and  do this in loop , how  is possible  kill this loop ?? , i think i must  use  the  funcion 

void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }


but  how  execute  them ???


thankz  at  all :)

Fernando Carreiro
1438
Fernando Carreiro 2016.06.06 16:02  

Is it not obvious? Use the function "EventKillTimer()" from within the "OnTick()" or "OnTimer()" to disable future Timer events! However, you will also have to SET the timer from within the "OnTick()" event as well, instead of in the "OnInit()", even thou I suspect that it may also work even if the timer was SET in the "OnInit()" event. Please see the documentation.

whroeder1
13596
whroeder1 2016.06.06 16:07  
faustf: hi  guy  how  to  kill the  timer ???
Perhaps you should read the manual, like the page where you learned how to start the timer (2nd paragraph from the bottom.)
faustf
84
faustf 2016.06.06 16:39  

FMIC   thankz  so much  , it was not so obvious as it seemed,  but  your explanation  it was excellent   , thankz  again



/
To add comments, please log in or register