Re-initialization of an indicator - page 2

 
angevoyageur:

It's always a good idea to check values, but

period can't be 0.

Ah,  good point, I always use brackets to make this kind of stuff clear,  it makes me lazy (efficient) though and I miss stuff like this . . .   

I wonder if the period is greater than the number of Bars available it will cause the issue  . . . 

 

Sorry, should have made this more clear:

the code I posted is just some random, not doing anything piece of code, that I simply wrote to show you the error.

In my EA, there are way more checks (enough bars, Period reasonable, Terminal connected, ...)


Here, my idea was just to show the most simple code, that allows to reproduce my memory troubles, to let others check, if they get it too.



Clock

 

Hi,

The below code suggests that the removal of indicator fails producing error 4014 ("System function is not allowed to call") , so maybe that is causing excessive memory usage:

//+------------------------------------------------------------------+
//|                                                       TestEA.mq5 |
//+------------------------------------------------------------------+
int         h_atr;
datetime    lastbar;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   h_atr=iATR(_Symbol,_Period,100);
   if(h_atr==INVALID_HANDLE){return -1;}
   MathSrand(10);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   datetime now[1];
   if(CopyTime(_Symbol,_Period,0,1,now)<1){return;}
   if(now[0]==lastbar){return;}
   lastbar=now[0];

   int period=(int)MathFloor(MathRand()/1000+50);
   if(h_atr!=INVALID_HANDLE)
     {
      if(!IndicatorRelease(h_atr))
      Print("IndicatorRelease() failed. Error ",GetLastError());
     }
   h_atr=iATR(_Symbol,_Period,period);

  }
//+------------------------------------------------------------------+
 

Oh! Never thought about checking the outcome of the IndicatorRelease function.

So now I know what might cause the memory usage. The question is: why can't I release it?

Thanks for the input!

Documentation on MQL5: Timeseries and Indicators Access / IndicatorRelease
Documentation on MQL5: Timeseries and Indicators Access / IndicatorRelease
  • www.mql5.com
Timeseries and Indicators Access / IndicatorRelease - Documentation on MQL5
 
Clock:

Oh! Never thought about checking the outcome of the IndicatorRelease function.

So now I know what might cause the memory usage. The question is: why can't I release it?

Thanks for the input!

You have to read the replies when you post a question then

Forum

Re-initialization of an indicator

angevoyageur, 2013.07.03 13:57

This approach seems correct, but you have to check the returned value of IndicatorRelease(). If you need more help you have to provide some snippets of codes that reproduce your issue AND compiles.
Anyway this isn't the problem, the memory issue is still there even when IndicatorRelease properly checked.
 

Well, you got me. I have to admit, that I didn't really get that hint of yours. Guess that's caused by my lacking english skills...

However, why do you say that this is not the problem? Of course checking the returned value does not solve the memory issue, but it raises the question: why can't the handle be released? And would I have the same issues, if it was released properly (probabaly not?). But then again: little to no idea, how I will find the source of this newly found problem...

 
Clock:

Well, you got me. I have to admit, that I didn't really get that hint of yours. Guess that's caused by my lacking english skills...

However, why do you say that this is not the problem? Of course checking the returned value does not solve the memory issue, but it raises the question: why can't the handle be released? And would I have the same issues, if it was released properly (probabaly not?). But then again: little to no idea, how I will find the source of this newly found problem...

I mean there is a bug, checking the returned value is useful but that doesn't resolve the bug and I get this problem also when the handle is always released. No answer from the Service Desk ?
Files:
test.mq5  2 kb
 
No reaction yet. Don't know what that means. Either they didn't even read it yet, haven't started working, or are currently working on it. Some kind of status of request would be nice...
 

Does anybody have any hints, on why IndicatorRelease might fail? Not just in this example, but overall.

Started to use that check in different places, and more often than not, I get a fail...

 

What I didn't check yet, and what makes it even funnier, is that this code works flawlessly.

//+------------------------------------------------------------------+
//|                                                       TestEA.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
int         h_atr;
datetime    lastbar;
int OnInit()
  {
   h_atr=INVALID_HANDLE;
   h_atr=iATR(_Symbol,_Period,100);
   if(h_atr==INVALID_HANDLE){return -1;}
   MathSrand(10);
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
   datetime now[1];
   if(CopyTime(_Symbol,_Period,0,1,now)<1){return;}
   if(now[0]==lastbar){return;}
   lastbar=now[0];

   int period=(int)MathFloor(MathRand()/1000+50);
   h_atr=iATR(_Symbol,_Period,period);
  }


So without trying to free memory through IndicatorRelease(), there's no problem...

Reason: