Download MetaTrader 5
To add comments, please log in or register
Make profit on MQL5 services. It's easy!
maindoor
120
maindoor 2014.06.01 02:53 

Hi,

I have the following code for a oneshot timer:

int OnInit()
{
   if (EventSetTimer(3) == false) {
      int lastError = GetLastError();
      Print("Timer init Failed: ", ErrorDescription(lastError));
   }
   return(INIT_SUCCEEDED);
}

void OnTimer()
{
   Print("Handling Timer");
   EventKillTimer();

}

I get "Timer init Failed: internal error".

Am I doing anything wrong ? Why would a simple EventSetTimer fail ?

Brian Nichols
7
Brian Nichols 2014.06.01 04:46  

The following code works for me (created using MT4 indicator wizard with your code pasted into it minus ErrorDescription()) so there doesn't appear to be anything wrong with the code itself.  Unfortunately not familiar enough with MQL & MT to say what might cause it to fail, but invariably when something doesn't make sense it's time to revisit assumptions.

 

#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
//--- input parameters
input int      Delay = 3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if (EventSetTimer(3) == false) {
      int lastError = GetLastError();
      Print("Timer init Failed: ", lastError);
   }
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   Print("Handling Timer");
   EventKillTimer();
//---
   
  }
//+------------------------------------------------------------------+
Alain Verleyen
Moderator
28524
Alain Verleyen 2014.06.01 11:09  
maindoor:

Hi,

I have the following code for a oneshot timer:

I get "Timer init Failed: internal error".

Am I doing anything wrong ? Why would a simple EventSetTimer fail ?




Are you this code in a script ?
maindoor
120
maindoor 2014.06.01 11:36  
angevoyageur:

Are you this code in a script ?

No, In an expert Advisor.

Sometimes the timer works and most of the times it doesn't.

Ian Venner
2583
Ian Venner 2014.06.01 13:32  
I tried it in an EA and an indicator OnTimer works fine in both. Have you tried upgrading to the latest build 654 ?
maindoor
120
maindoor 2014.06.05 12:08  
SDC:
I tried it in an EA and an indicator OnTimer works fine in both. Have you tried upgrading to the latest build 654 ?

I am demo'ing with oanda and the latest they have is build 646.

I'm still at the same level, works sometimes but doesn't work most of the time.

I'm on virtualbox with host win7 and guest win-xp. mt4 is installed on win-xp.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.06.05 13:01  
Why not just installed it on Win 7 directly? No need to use Win Xp.
Ian Venner
2583
Ian Venner 2014.06.05 14:35  
maindoor:

I am demo'ing with oanda and the latest they have is build 646.

I'm still at the same level, works sometimes but doesn't work most of the time.

I'm on virtualbox with host win7 and guest win-xp. mt4 is installed on win-xp.

You can still upgrade if make a second account on your terminal to MQ demo server 443
/
To add comments, please log in or register