MT4 hangs, doesn't call start() again

 

Hi,

I’m facing an ugly problem here:

after a few iterations the start() function of my indicator doesn’t come back again after the return() call, i.e. MT4 hangs in a loop, eating up CPU, without calling start() again.

I wonder if somehow I destroyed the function call stack?

What do you suggest that I should mainly look for to find the cause?

I’ve been debugging the whole week already. It’s 72 pages of code.

I’m not using any DLL calls, just plane MQL.

Thanx.

 
You are not returning from start. You need to fix your code. Get dbgView and add Log calls at the start and return of every function and track down your infinite loop.
 

I'm logging debug information already.

I can't see an indefinite loop.

The last thing I see in the log file is when I call return() in the last line of start().

From there start() is never triggered again.

It must be somethimg else.

 
Logging where/how? You can NOT use Print/Alert because you are hanging the GUI thread, the output will not be written.
 

I know, I'm using my own PrintDebug() function with FileWrite(), FileFlush.

 

Do you think, my way of printing debug information is sufficient?

 
mt4forum:

I'm logging debug information already.

I can't see an indefinite loop.

The last thing I see in the log file is when I call return() in the last line of start().

From there start() is never triggered again.

It must be somethimg else.


Do you print something to the log as the first line of start() ?
 

Yes, I'm logging the first line and the last line.

Can I be sure, that my way of logging does not miss any log information?

 
mt4forum:

Yes, I'm logging the first line and the last line.

Can I be sure, that my way of logging does not miss any log information?

If you aren't sure just use a standard Print() and check the log file not just the expert tab . . . we haven't seen your way of logging.

Do you use any Indicators via iCustom() calls ? if you do maybe they are taking the CPU cycles . . .
 

Here's my log function:

void PrintDebug(int F, string DebugStr1, string DS2 = "", string DS3 = "", string DS4 = "", string DS5 = "", string DS6 = "", string DS7 = "", 
   string DS8 = "", string DS9 = "", string DS10 = "", string DS11 = "", string DS12 = "", string DS13 = "", string DS14 = "", string DS15 = "", 
   string DS16 = "", string DS17 = "", string DS18 = "", string DS19 = "", string DS20 = "")
{
   FileWrite(F, CommonIdentStr() + Blank + DebugStr1 + DS2 + DS3 + DS4 + DS5 + DS6 + DS7 + DS8 + DS9 + DS10 
               + DS11 + DS12 +DS13 + DS14 + DS15 + DS16 + DS17 + DS18 + DS19 + DS20);
   FileFlush(F);
}

And here's my start function:

int start()
  {     
   int TFInd;
   int k;  
   
   if (CheckDebug(DebugStart, 2))
      {
         DebugStr = "DebugStart: " + "begin: " + " InitialGapFound: " + BoolToString(InitialGapFound);
         PrintDebug(DebugFile, DebugStr);
      }
   
   if (InitialGapFound)        
      {                                             
         if (TimeLocal() >= LastInitialGapCloseCheck + HistoryDownloadCheckInterval)                                  // zzz
            {
               LastInitialGapCloseCheck = TimeLocal();
               
               if (InitialHistoryGapClosed())
                  {
                     if (CheckDebug(DebugStart, 2))
                        {
                           DebugStr =  "DebugStart: " + " InitialHistoryGapClosed ";
                           PrintDebug(DebugFile, DebugStr);
                        }
                  
                     ReInit = true;
                     InitialGapFound = false;

                     MyInit();
                  }        
            }

         if (CheckDebug(DebugStart, 2))
            {
               DebugStr = "DebugStart: " + " last return in InitialGapFound";
               PrintDebug(DebugFile, DebugStr);
            } 
            
         return(OK);
      
      }  // if InitialGapFound

   if (CheckDebug(DebugStart, 2))
      {
         DebugStr = "DebugStart (): last return: ";
         
         PrintDebug(DebugFile, DebugStr);
      } 
 
              
   return(0);
  }

I am logging the begin of start and the end.

The function CheckDebug() does not have any influence, since it always returns true.

The following is the log file generated.

You can see that the last entry is "DebugStart: last return in InitialGapFound", which is the last statement executed in the start() function.

The next entry in the log file should be "DebugStart: begin: ...", the first statement of the start() function.

But start() is never triggered again. Instead MT4 hangs in a loop.

I can't see any loop in my program logic. I'm not using DLLs, no iCustom, ...

2013.11.15 12:33:14 Test reduced 0: USDJPY M15 Debug Init() begin:
2013.11.15 12:33:14 Test reduced 0: USDJPY M15 DebugMyInit begin:
2013.11.15 12:33:14 Test reduced 0: USDJPY M15 Debug Init() return:
2013.11.15 12:33:14 Test reduced 0: USDJPY M15 DebugStart: begin: InitialGapFound: True
2013.11.15 12:33:14 Test reduced 0: USDJPY M15 DebugStart: last return in InitialGapFound
2013.11.15 12:33:15 Test reduced 395052: USDJPY M15 DebugStart: begin: InitialGapFound: True
2013.11.15 12:33:15 Test reduced 395052: USDJPY M15 DebugStart: last return in InitialGapFound
2013.11.15 12:33:16 Test reduced 395052: USDJPY M15 DebugStart: begin: InitialGapFound: True
2013.11.15 12:33:16 Test reduced 395052: USDJPY M15 DebugStart: InitialHistoryGapClosed
2013.11.15 12:33:16 Test reduced 395052: USDJPY M15 DebugMyInit begin:
2013.11.15 12:33:16 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 1 nach CreateHistory()
2013.11.15 12:33:17 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 2 nach CreateHistory()
2013.11.15 12:33:18 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 3 nach CreateHistory()
2013.11.15 12:33:19 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 4 nach CreateHistory()
2013.11.15 12:33:20 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 5 nach CreateHistory()
2013.11.15 12:33:21 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 6 nach CreateHistory()
2013.11.15 12:33:22 Test reduced 395052: USDJPY M15 DebugMyInit InitialMyInitCalls: 0 IndexCount: 7 nach CreateHistory()
2013.11.15 12:33:22 Test reduced 395052: USDJPY M15 DebugMyInit return InitialMyInitCalls: 0 IndexCount: 8
2013.11.15 12:33:22 Test reduced 395052: USDJPY M15 DebugStart: last return in InitialGapFound

 
mt4forum:

Here's my log function:

And here's my start function:

I am logging the begin of start and the end.

The function CheckDebug() does not have any influence, since it always returns true.

The following is the log file generated.

You can see that the last entry is "DebugStart: last return in InitialGapFound", which is the last statement executed in the start() function.

The next entry in the log file should be "DebugStart: begin: ...", the first statement of the start() function.

But start() is never triggered again. Instead MT4 hangs in a loop.


What is OK in . . .

      return(OK);


Lets assume your debugging is causing the issue, please add the following after the variable declarations in start() run and report back showing the log and your log excerpt as above . . .

int start()
  {     
   int TFInd;
   int k;  
   
   Print("start():  started . . .");  // <-----  add this line here
   
   if (CheckDebug(DebugStart, 2))