Memory usage by an indicator

 

Hello,


I have a function using the iATR method. 

My function is being called once per bar onTick();

I noticed when backtesting that my RAM gets filled up within a few seconds and my Windows freezes.

If I comment-out the last line (IndicatorRelease) then the problem resolves.


Why is that?

  int atrHandle = iATR(_Symbol, PERIOD_CURRENT, 2); // 2 is assuming an H1 trading period. For less than H1 we should increase this value
     
    // Check for a valid handle
    if(atrHandle == INVALID_HANDLE)
     {
      Print("Error creating ATR handle: ", GetLastError());
      return false;
     }
     
   //--- create an array to hold ATR values
   double atrValues[];

   //--- copy the last ATR value into the array
   if(CopyBuffer(atrHandle, 0, 0, 1, atrValues) <= 0)
     {
      Print("Error copying ATR values: ", GetLastError());
      IndicatorRelease(atrHandle);
      return false;
     }



   //--- get the latest ATR value
   double lastATRValue = atrValues[0];  

   IndicatorRelease(atrHandle);
 
Alon D:

Hello,


I have a function using the iATR method. 

My function is being called once per bar onTick();

I noticed when backtesting that my RAM gets filled up within a few seconds and my Windows freezes.

If I comment-out the last line (IndicatorRelease) then the problem resolves.


Why is that?


Change atrHandle to be a global variable and create the handle only once in OnInit() function,

And move the IndicatorRelease to your DeInit() function.

 
Alon D:

Hello,


I have a function using the iATR method. 

My function is being called once per bar onTick();

I noticed when backtesting that my RAM gets filled up within a few seconds and my Windows freezes.

If I comment-out the last line (IndicatorRelease) then the problem resolves.


Why is that?

search mql documents. There are examples how to do this.

the behaviour you have described is to be expected.