IBands Sucking all of my RAM

To add comments, please log in or register
Dragan Matesic
13
Dragan Matesic  

Hi all I'm having problem with iBANS indicator buffer. When I run my function it will run until my RAM memory reaches max and then it will return only 0.0 values from IBANDS indicator. Ones I stop function RAM is freed and and then when I start function again it will return normal values until RAM reaches max memory again.

How can I empty iBANDS indicator buffer during loop? Thanks in advance.


#property version   "1.00"
#property strict

int i=1;
int moreless=10;
datetime LastDbDate;
double ma5,ma10,ma15,ma30,ma60,ma100,ma200,ma500,band_main,band_upper,band_lower;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnStart()
  {

// Get last date from request
   string TheDate=request.getData();
   LastDbDate=StringToTime("01.01.2000 00:01:00");
   printf(LastDbDate);
// calculate diff between dates in database and current
   while(Time[i]>LastDbDate)
     {i++;};

   Print("total",i);
 
// send data that is still not in database
   for(int frame=i;frame>=1;frame--)
     {

      ma5=iMA(NULL,PERIOD_M5,5,0,MODE_SMA,PRICE_CLOSE,frame);
      ma10 = iMA(NULL,PERIOD_M5,10,0,MODE_SMA,PRICE_CLOSE,frame);
      ma15 = iMA(NULL,PERIOD_M5,15,0,MODE_SMA,PRICE_CLOSE,frame);
      ma30 = iMA(NULL,PERIOD_M5,30,0,MODE_SMA,PRICE_CLOSE,frame);
      ma60=iMA(NULL,PERIOD_M5,60,0,MODE_SMA,PRICE_CLOSE,frame);
      ma100=iMA(NULL,PERIOD_M5,100,0,MODE_SMA,PRICE_CLOSE,frame);
      ma200=iMA(NULL,PERIOD_M5,200,0,MODE_SMA,PRICE_CLOSE,frame);
      ma500=iMA(NULL,PERIOD_M5,500,0,MODE_SMA,PRICE_CLOSE,frame);

      band_main= iBands(Symbol(),PERIOD_M5,20,2,frame,PRICE_CLOSE,MODE_MAIN,0);
      band_upper = iBands(Symbol(),PERIOD_M5,20,2,frame,PRICE_CLOSE,MODE_UPPER,0);
      band_lower = iBands(Symbol(),PERIOD_M5,20,2,frame,PRICE_CLOSE,MODE_LOWER,0);
     
      printf("frame: %i, %s, %d,%f, %f,%f,%f,%s|, %f , %f , %f",frame,Symbol(),Period(),Open[frame],High[frame],Low[frame],Close[frame],TimeToStr(Time[frame]),band_main,band_upper,band_lower);
      string data=StringFormat("{'Number':'%d'##'Symbol':'%s'##'Period':'%d'##'OpenVal':'%f'##'High':'%f'##'Low':'%f'##'CloseVal':'%f'##'Time':'%s'##'Volume':'%d'##'ma5':'%f'##'ma10':'%f'##'ma15':'%f'##'ma30':'%f'##'ma60':'%f'##'ma100':'%f'##'ma200':'%f'##'ma500':'%f'##'band_main':'%f'##'band_upper':'%f'##'band_lower':'%f'}",frame,Symbol(),Period(),Open[frame],High[frame],Low[frame],Close[frame],TimeToStr(Time[frame]),Volume[frame],ma5,ma10,ma15,ma30,ma60,ma100,ma200,ma500,band_main,band_upper,band_lower);
     
     
      if (band_main == 0.000000)
      {         return 0;         }
        
      frame=frame;
     }
return 0;}


nicholi shen
1890
nicholi shen  
Dragan Matesic:

Hi all I'm having problem with iBANS indicator buffer. When I run my function it will run until my RAM memory reaches max and then it will return only 0.0 values from IBANDS indicator. Ones I stop function RAM is freed and and then when I start function again it will return normal values until RAM reaches max memory again.

How can I empty iBANDS indicator buffer during loop? Thanks in advance.


It's because you are creating potentially thousands of indicator instance since you are not using the correct shift index param. 

band_main= iBands(Symbol(),PERIOD_M5,20,2,frame,PRICE_CLOSE,MODE_MAIN,0);
band_main= iBands(Symbol(),PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_MAIN,frame);

Do try and avoid the overuse/abuse of global variables, and also use iBarShift instead of the while loop to test if the time is greater... 

Dragan Matesic
13
Dragan Matesic  
nicholi shen:

It's because you are creating potentially thousands of indicator instance since you are not using the correct shift index param. 

Do try and avoid the overuse/abuse of global variables, and also use iBarShift instead of the while loop to test if the time is greater... 

Oh I see it. Thanks Nicholi I just could not see what am I doing wrong.
To add comments, please log in or register