Strange Behaviour of a working Indicator .. What to do? How to recognize? - page 2

 

While I was shopping both perfectly working indicators Mom and Sma suddenly stop working:


There is nothing in the journal log, excerpt that Sma was installed at 9:00 and at 19: a ping failed (Chart is GMT my pc has GMT+1):

2017.08.04 19:34:10.011 '1111208386': ping failed
2017.08.04 09:14:15.550 Custom indicator Test_OOP_Sma EURUSD,H1: loaded successfully

Before the 17:00-bar (since installation) and again right after I opened the setup box and pressed OK both indicators show this image on the chart:


 

I solved the problem.

Occasionally mt4 (and mt5?) sets the variable prev_calculated (of OnCalculate(..)) to 0.

So to keep the objects clean and lean I had to do (for indicators):

int PrevCalc;

OnInit() {
   PrevCalc = 0;
   ..
}

int OnCalculate(..) {
   if ( PrevCalc > prev_calculated ) { // perv_calc dropped :(
      OnDeinit(REASON_RECOMPILE);
      OnInit();
   }
   PrevCalc = prev_calculated;
   ...
}
Hopefully I will not be caught in an endless loop :(
 
Carl Schreiber:

I solved the problem.

Occasionally mt4 (and mt5?) sets the variable prev_calculated (of OnCalculate(..)) to 0.

Normal behaviour when there is a chart refresh, chart shifted or whaetever reason.

So to keep the objects clean and lean I had to do (for indicators):

Hopefully I will not be caught in an endless loop :(

Seems to me a bad idea to call directly OnDeinit() and OnInit() from OnCalculate(), you are preparing future headache.

I can't propose something else though as I don't understand your problem from the snippets of code you posted.

 
Alain Verleyen:

Normal behaviour when there is a chart refresh, chart shifted or whaetever reason.

Seems to me a bad idea to call directly OnDeinit() and OnInit() from OnCalculate(), you are preparing future headache.

I can't propose something else though as I don't understand your problem from the snippets of code you posted.

As you said "whatever reason" which means you'll never know or can control it :(


Seems to me a bad idea to call directly OnDeinit() and OnInit() from OnCalculate(), you are preparing future headache.

Well I have two options:

  1. Write a couple of functions with a lot of code to manage that only for indicators and only sometimes the time[b] is not actual but "quite old", which means that a lot of data has to be recalculated e.g. in case the quotes from the server have been changed or missing quotes were added ..
  2. Get rid of everything (DeInit()) and rebuild the data from the scratch.

The second option seems to me the better one.

 
Carl Schreiber:

As you said "whatever reason" which means you'll never know or can control it :(


Well I have two options:

  1. Write a couple of functions with a lot of code to manage that only for indicators and only sometimes the time[b] is not actual but "quite old", which means that a lot of data has to be recalculated e.g. in case the quotes from the server have been changed or missing quotes were added ..
  2. Get rid of everything (DeInit()) and rebuild the data from the scratch.

The second option seems to me the better one.

As you wish.

But you don't have to control it. Either prev_calculated is =0 that means you have to rebuild all (if needed), or it's prev_calculated=rates_total (more or less) and you just have to update 1 or a few candles.

If you can't deal with that, your architecture is seriously flawed. Only my opinion and it's always possible I misunderstood your issue.

Reason: