Trapping an Abnormal termination/timeout message - page 2

 
jacques366: So now the question is why is it occurring at that special moment? Stopping the terminal may change something that is causing this While loop not to end correctly  ?
It is not "occurring at that special moment" Your code is broken: it is an infinite loop, no matter when you call it. You don't want to answer my question and learn why!
 

If the terminal crashes it can be found in the event viewer (EVENTVWR) error Terminal.exe APPLICATION_HANG but if the terminal re initializes due to the watchdog timer overflow then there will not be an error in the operating system logs.

Earlier in some of the older terminal builds if your EA was going bad it would freeze and reinitialize and again load the EA that caused the problem causing an infinite loop of freezes, and it was hard to recover from this but it has been changed so that it does not happen anymore.

A simple debug print at every step along the way should identify the problem.
 
whroeder1:
It is not "occurring at that special moment" Your code is broken: it is an infinite loop, no matter when you call it. You don't want to answer my question and learn why!
What infinite loop ? Checking ">0" or "!=-1" should not change anything. And if error there is it (to use >0) the consequence will be to exit the loop not an infinite loop.
 
whroeder1:

No, if the terminal is stopping, then start will not be called.

You must find your infinite loop and fix it. If any of your loops/sleeps/web requests take any longer then 3 seconds your code will be terminated.

 
whroeder1:

  1. Absolutely does.
  2. Answer the question what does it return when there are no more?
  3. What does ChartNext return when you use that value??

Absolutely does what ? Please explain how the above code could be an infinite loop.

I already answered the question 2 and 3, it's -1, which is below 0, so the loop will exit.

 
You're too quick.  I was still editing, and realized you were correct and deleted the post. The problem must be elsewhere.
 
whroeder1:
You're too quick.  I was still editing, and realized you were correct and deleted the post. The problem must be elsewhere.
Ok no problem.
 

Sorry whroeder1. I did in fact answered your questions but the message was not sent. When I realized that I rewrote it quickly before going and forgot that part. Sorry.

I was saying that of course I've read the instructions manual, even before having the idea to create this thread.   

  1. It is. That is what "shutdown by timeout" means. , yes you're right but my vision of the problem at the time I wrote the first post is explain by this sentence I wrote afterward:  'This is occurring at the time I stop the terminal. (I first thought the loop was running and was stopped by my intervention but it's not the case).'
  2. What does ChartNext - Chart Operations - MQL4 Reference return when there are no more charts, and what are you checking for? :  I think you've got your answer on that point now, it has also be clarified by Alain.
 
jacques366:

Sorry whroeder1. I did in fact answered your questions but the message was not sent. When I realized that I rewrote it quickly before going and forgot that part. Sorry.

I was saying that of course I've read the instructions manual, even before having the idea to create this thread.   

  1. It is. That is what "shutdown by timeout" means. , yes you're right but my vision of the problem at the time I wrote the first post is explain by this sentence I wrote afterward:  'This is occurring at the time I stop the terminal. (I first thought the loop was running and was stopped by my intervention but it's not the case).'
  2. What does ChartNext - Chart Operations - MQL4 Reference return when there are no more charts, and what are you checking for? :  I think you've got your answer on that point now, it has also be clarified by Alain.

It would be nice to have an answer Jacques :

Forum on trading, automated trading systems and testing trading strategies

Trapping an Abnormal termination/timeout message

Alain Verleyen, 2016.12.08 15:35

It's difficult to answer without knowing the context where this code is used. In which event handler ? Is it nested deeply in other functions call ?

At first I can't see a reason. Can you provide a test code which we could use to reproduce the issue ?


 
Alain Verleyen:

It would be nice to have an answer Jacques :


Hi Alain, 

The code is used in a function called within the Start() function.

The program is stopping in between the two WriteTraceFile, I have the first Write in the file but not the second. This only when I stop the program buy shutting down the platform (should be the same when switching to another time frame) , and not always.

It's a bit senseless to provide a piece of code as it's part of a complex program and not just a few lines of code.

I am proceeding step by step to localize where this Timeout is coming from (on which instruction).

Here is the code: The code causing the error for now is in comments just to be sure it's coming from those lines and I've added the test on the hard coded pairs instead. This code has ran Friday on one account and from the market opening on 2 other accounts ( I usually have many errors occurring per day). Until now there was no Timeout. I am waiting 1 or 2 days of trading and I will let you know if the Timeout has disappeared for good...

(Also those lines suspected to create the error have been recently added and the instructions ChartFirst, ChartNext never used before. It makes sense to consider those lines to be in cause but, as I've recently made a few other changes in the program, lets be sure and see how it goes)


       // checking if the chart is open (not foreign trading with no instance running on the instrument) (needed in WritePositionFile( ))
       chartOpen = false;
       long currChart = ChartFirst();
   WriteTraceFile("--- LoadOrdersTables  checking if the chart is open");
      //i = 1;   // added because this While search was a never ending loop causing timeout >>  IT IS THE SAME WITH THAT i !!!
      //while(currChart>0  &&  i < 15)
      //    {if (ChartSymbol(currChart) == OOrderSymbol[curOrder])           // see here
      //        {chartOpen = true;
      //         break;
      //        }
      //     currChart=ChartNext(currChart);
      //     i++;
      //    }  
   if (   OOrderSymbol[curOrder] == "EURUSD"
       || OOrderSymbol[curOrder] == "GBPUSD"
       || OOrderSymbol[curOrder] == "USDCHF"
       || OOrderSymbol[curOrder] == "AUDUSD"
       || OOrderSymbol[curOrder] == "USDJPY"
       || OOrderSymbol[curOrder] == "GBPJPY"
       || OOrderSymbol[curOrder] == "USDCAD"
      )
      {     chartOpen = true;
      }      
      
   WriteTraceFile("--- LoadOrdersTables  checking if the chart is open  End i="+i);