That can be achieved with "OnTimer".
Try this one.
#property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0 //--- input parameters input int Interval = 10; //seconds //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping EventSetTimer(Interval); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); Comment(""); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double& price[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- Comment("\r\n\r\n" + TimeToString(TimeCurrent(), TIME_MINUTES | TIME_SECONDS) + " This will tick every 10 seconds"); //--- } //+------------------------------------------------------------------+
Naguisa Unada:
That can be achieved with "OnTimer".
Try this one.
It worked with me , many thanks
Sabil Yudifera:
Sleep (10);
https://docs.mql4.com/common/sleep
I see that's a good idea.
But it's "Sleep (10000)" instead of "Sleep (10)" because it's milliseconds.
Hi gurus, what if i want my EA to start only at 11am for example.
I tried doing this, but it doesnt seem to work. it is not responding.
Appreciate if you can point out what am i missing? Thanks!
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { datetime StartTime = D'11:15'; //--- create timer if(TimeLocal()==StartTime) { EventSetTimer(15); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); } //+------------------------------------------------------------------+ //| OnTimer | //+------------------------------------------------------------------+ void OnTimer() { Comment("\r\n\r\n" + TimeToString(TimeLocal(), TIME_MINUTES | TIME_SECONDS) + " This will tick every 10 seconds");
Nagisa Unada:
That can be achieved with "OnTimer".
Try this one.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How to run a code every 10 seconds in MQL5
this can be done in a programming language like Javascript
where 10000 milli-seconds equals to 10 seconds
how to achieve this in MQL5 ?