Download MetaTrader 5

global initialization failed!!!!!!!

To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
HELLAS
69
HELLAS 2014.03.27 13:55 

If anyone could help...I run an expert advisor for 4 chart pairs, and for running it for the 5th, after loading succesfully, i have global initialization failed, and then removed...

I would appreciate at least a guidance what to look for..

Thanks...

Alain Verleyen
Moderator
30745
Alain Verleyen 2014.03.27 14:02  
HELLAS:

If anyone could help...I run an expert advisor for 4 chart pairs, and for running it for the 5th, after loading succesfully, i have global initialization failed, and then removed...

I would appreciate at least a guidance what to look for..

Thanks...

Seems you have a problem during initialization. Check your code. You can post the relevant code if you need help.
HELLAS
69
HELLAS 2014.03.27 14:49  
angevoyageur:
Seems you have a problem during initialization. Check your code. You can post the relevant code if you need help.


Thanks for replying..

The thing is that my code works fine for 4 charts(pairs), but when i try to run it for one more this happens.

And the code is kind of huge, so i dont know if it ll help you..

Ian Venner
2584
Ian Venner 2014.03.27 15:42  
It might not be the code. My terminal crashed when I was dragging terminal windows around, it partly recovered but said global initialization failed. I had to restart the terminal. I have never seen that error before build 625 and there has been more than one report of it during this past week or so.
HELLAS
69
HELLAS 2014.03.27 16:04  
SDC:
It might not be the code. My terminal crashed when I was dragging terminal windows around, it partly recovered but said global initialization failed. I had to restart the terminal. I have never seen that error before build 625 and there has been more than one report of it during this past week or so.
When u restarted the terminal all was good?? Because i did restarted few times, but i had the same results. The fact is that i cant find any specific documentation that gives any help on the topic...
Ian Venner
2584
Ian Venner 2014.03.28 02:34  
Yes it was all good when I restarted it.
Jeff Irick
263
Jeff Irick 2014.04.25 10:32  

Folks, I know this thread is about a month old now but I think this is a MetaTrader problem rather than a code problem. I've had this happening to me randomly on an indicator I'm working on. Sometimes it happens if I look at or change the properties of the indicator, sometimes it happens if I shut down and restart the terminal and sometimes it just happens spontaneously. It is definitely some kind of initialization problem. The reason I'm sure of this is that I have a set of buttons that I create for viewing MAs on different time frames than the one you're currently on. In all cases, when it fails the TF buttons are still on the chart but the indicator has been removed. Naturally, the buttons no longer do anything. In order to get things back on track I have to delete the buttons manually and put the indicator back on the chart. It works fine for awhile and then BOOM! It's dead again. No rhyme or reason as to why. I don't think the problem is our code. I think it's something screwed up with MT4. I'm running v625, by the way. If I come up with anything to circumvent this, I'll post it.

Prof

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.25 10:58  
Show us the code. Just to make sure you code is not the culprit. Else, MetaQuotes will be laughing at you.
Keith Watford
Moderator
9624
Keith Watford 2014.04.29 19:37  

I had this "global initialization failed" as well

It happened when I changed the chart time-frame

I can't see any reason for it and have been unable to replicate it.

The odd thing is that the last 2 blocks of code in init create objects and these were created on the chart.

As deinit was not called, they were not deleted.

int OnInit()
  {
//--- indicator buffers mapping
      IndicatorBuffers(4);

      //---- drawing settings
      SetIndexArrow(0,250);
      SetIndexArrow(1,250);

      SetIndexStyle(0,DRAW_NONE);
      SetIndexDrawBegin(0,i-1);
      SetIndexBuffer(0,CTFresistancetBuffer);
      SetIndexLabel(0,"Resistance");

      SetIndexStyle(1,DRAW_NONE);
      SetIndexDrawBegin(1,i-1);
      SetIndexBuffer(1,CTFsupportBuffer);
      SetIndexLabel(1,"Support");

      SetIndexBuffer(2,HTFresistancetBuffer,INDICATOR_CALCULATIONS);
      SetIndexBuffer(3,HTFsupportBuffer,INDICATOR_CALCULATIONS);

      switch(S_R_TimeFrame)
        {
         case M5:
            SRPeriod=PERIOD_M5;
            break;
         case M15:
            SRPeriod=PERIOD_M15;
            break;
         case M30:
            SRPeriod=PERIOD_M30;
            break;
         case H1:
            SRPeriod=PERIOD_H1;
            break;
         case H4:
            SRPeriod=PERIOD_H4;
            break;
         case Daily:
            SRPeriod=PERIOD_D1;
            break;
         case Weekly:
            SRPeriod=PERIOD_W1;
            break;
         case Monthly:
            SRPeriod=PERIOD_MN1;
            break;
         case Current_Chart:
            SRPeriod=PERIOD_CURRENT;
            break;
        }
        
      if(Digits==3 || Digits==5)
         NewPip=Point*10;
      else
         NewPip=Point;
      
      string obj_name = "TDR_ARROW" ;
      ObjectCreate(obj_name, OBJ_LABEL, 0, 0, 0);
      ObjectSet(obj_name, OBJPROP_CORNER, 1);
      ObjectSet(obj_name, OBJPROP_XDISTANCE,  30);
      ObjectSet(obj_name, OBJPROP_YDISTANCE,  30);
      ObjectSetText(obj_name, CharToStr(243), 30, "Wingdings", clrBlue);
      
      obj_name = "TDR_LINE" ;
      ObjectCreate(obj_name, OBJ_TREND, 0, 0, 0);
      ObjectSetInteger(0,obj_name,OBJPROP_WIDTH,LineWidth+1);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                         |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

   for(i=ObjectsTotal()-1;i>=0;i--)
     {
      string ObName=ObjectName(i);
      if(StringFind(ObName,"TDR",0)!=-1)
         ObjectDelete(ObName);
     }

   return;
  }
//+------------------------------------------------------------------+
Jeff Irick
263
Jeff Irick 2014.05.02 08:29  

My problem seems to have been using init() and deinit() instead of the new OnInit() and OnDeinit(). Things seem to be working after I switched to the new calls. MetaQuotes better not be laughing at me. I seem to recall having read somewhere in the voluminous list of changes that the old calls were still compatible with MQL4. As a matter of fact, I have another indicator that still uses them and creates a number of label objects with no hiccups. I'm likely to change that just to be on the safe side since I plan to offer both indicators for sale when I'm ready.

Anyway, the problem appears to have been that deinit() wasn't being called when the indicator de-initialized so the objects weren't being deleted as they should have been. The initialization failed because the objects still existed. I was doing error checking on everything but the object creation failure wasn't being reported. Apparently, it blew and gave me MQL's error before ever hitting my error handling code.

GumRai, you might try using SubStr instead of StringFind. It shouldn't matter but I've found that MQL can be squirrely sometimes. Are you sure OnDeinit() wasn't called? The thing that clued me into my problem was putting an Alert statement in my deinit() method and noticing that it was never called. You might also try wrapping your deletion code with error handling code to see what it might be doing.

Prof

Alain Verleyen
Moderator
30745
Alain Verleyen 2014.05.02 09:09  
ProfessorMetal:

My problem seems to have been using init() and deinit() instead of the new OnInit() and OnDeinit(). Things seem to be working after I switched to the new calls. MetaQuotes better not be laughing at me. I seem to recall having read somewhere in the voluminous list of changes that the old calls were still compatible with MQL4. As a matter of fact, I have another indicator that still uses them and creates a number of label objects with no hiccups. I'm likely to change that just to be on the safe side since I plan to offer both indicators for sale when I'm ready.

Anyway, the problem appears to have been that deinit() wasn't being called when the indicator de-initialized so the objects weren't being deleted as they should have been. The initialization failed because the objects still existed. I was doing error checking on everything but the object creation failure wasn't being reported. Apparently, it blew and gave me MQL's error before ever hitting my error handling code.

GumRai, you might try using SubStr instead of StringFind. It shouldn't matter but I've found that MQL can be squirrely sometimes. Are you sure OnDeinit() wasn't called? The thing that clued me into my problem was putting an Alert statement in my deinit() method and noticing that it was never called. You might also try wrapping your deletion code with error handling code to see what it might be doing.

Prof

Can you post an example code to reproduce your issue ?
1234567
To add comments, please log in or register