Code going into Unknown state

 

Hello guys,

I am getting very peculier behaviour from my code. The following snippet is where the problem occurs:

if (OrderCloseTime()!=0) return (true);
type = OrderType();
success = false;
lots = NormalizeCloseLotSize(OrderSymbol(),percentClose*OrderLots()/100);
Print("Lots to close = " + lots);

if (type==OP_BUY)
{
   for(i=0; i<20; i++)
   {
          RefreshRates();
          if (OrderClose(OrderTicket(), lots,MarketInfo(OrderSymbol(),MODE_BID),Slippage*PointFactor)) 
          {
                 success = true;
                 break;
          }
          Sleep(1000);
   }
}

This code has been working perfectly for the past few weeks but today something really strange happened. In my logs, the last statement that got printed was "Lots to close =". I didn't get anything in the journal logs against OrderClose command so it seems that the the ocntrol never got to OrderClose Statement. After a couple of minutes, when i figured out there was an issue, i removed the EA from the chart and it closed with the following messages:

11:29:50 EA AUDUSD,H1: shutdown by timeout

11:29:53 EA AUDUSD,H1: terminated by timeout

11:29:53 EA AUDUSD,H1: deinitialized 

My start  function uses a while loop with IsStopped().

 

Can anyone shed light on what might have happened here? I would really appreciate any positive feedback.

 

Thanks.

Umer

 
Master.Aurora: My start  function uses a while loop with IsStopped().
  1. Your order close loop does not.
  2. If it doesn't work for the first or second time, why do you think it would work the 20th?
  3. Why doesn't it work? You have no idea! What are Function return values ? How do I use them ? - MQL4 forum
 
WHRoeder:
  1. Your order close loop does not.
  2. If it doesn't work for the first or second time, why do you think it would work the 20th?
  3. Why doesn't it work? You have no idea! What are Function return values ? How do I use them ? - MQL4 forum

1. I did not understand what you mean? You mean the close loop doesnt exit?

2. The trade context may be busy or there mught be network issues. I have tested my EA on around 20 different brokers and some are really problematic. Thus the 20 time retry was added.

3. I am quie experienced with MQL4, and i had read that article when i first started development on MQL4 :) My code had all sorts of logging in place in the testing phase. But now that it had been working perfectly and we had gone live with this i had to trim down logging statements. 

 

Thanks for your response.

Best Regards,

Umer 

 
Master.Aurora:

3. I am quie experienced with MQL4, and i had read that article when i first started development on MQL4 :) My code had all sorts of logging in place in the testing phase. But now that it had been working perfectly and we had gone live with this i had to trim down logging statements.

Why ? ?  just turn them Off when you don't need them and On when you do need them,  there is minute overhead in checking a bool.
 
RaptorUK:
Why ? ?  just turn them Off when you don't need them and On when you do need them,  there is minute overhead in checking a bool.


Haha i absolutely agree with you on this. BUT, the issue is not with the overead, its with the statements that get printed on a client's system. The system runs 24/5. Being a dev i really do not have any issues but the clients start complaining.

I guess i would need to put those statements back in and hope to find out the issue.

Thanks Anyways. 

 

Master.Aurora:

1. I did not understand what you mean? You mean the close loop doesnt exit?

BUT, the issue is not with the overead, its with the statements that get printed on a client's system

  1. Your close loop will not exit for 20 * (1000ms plus however long orderClose takes)= 20 seconds. An EA must exit within 2 seconds when shut down. Your loop doesn't use IsStopped().
  2. What part of turning them OFF was not clear?
 
Master.Aurora:


Haha i absolutely agree with you on this. BUT, the issue is not with the overead, its with the statements that get printed on a client's system. The system runs 24/5. Being a dev i really do not have any issues but the clients start complaining.

I guess i would need to put those statements back in and hope to find out the issue.

Thanks Anyways. 

Don't tell your Client to turn On the Debugging statements and they won't get a log full of them . . .
Reason: