execute function timer

 

How to call a function after each 45 second?

Period of call function = 45 second

 
fatbody: How to call a function after each 45 second? Period of call function = 45 second
Read about the OnTimer() Event Handler: https://www.mql5.com/en/docs/basis/function/events
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
Language Basics / Functions / Event Handling Functions - Reference on algorithmic/automated trading language for MetaTrader 5
 
fatbody:

How to call a function after each 45 second?

Period of call function = 45 second


Hi fatbody,

I created it for you, and I hope you can try this :)

input int interval=45; //--Interval in seconds

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(interval);

   //-- if you want to use milliseconds then you can use :
   //-- EventSetMillisecondTimer(interval);
   //-- and interval is 1000 for each 1 second.
   //-- Example for 0.5 second, then you set interval is 500

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   //--- destroy timer
   EventKillTimer();

  }

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {

    //--do something here ...

  }

Good luck.

Reason: