Download MetaTrader 5

execute function timer

To add comments, please log in or register
fatbody
81
fatbody  

How to call a function after each 45 second?

Period of call function = 45 second

Fernando Carreiro
3588
Fernando Carreiro  
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
Yohana Parmi
3495
Yohana Parmi  
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.

To add comments, please log in or register