MQL4 - automated forex trading   /  

Forum

Memory Usage of iStdDevOnArray

Back to topics list To post a new topic, please log in or register

avatar
2462
phy 2008.02.08 01:23 

When i add an indicator using iStdDevOnArray to my chart, MT4 memory jumps by 10megabytes


Open "empty" MT4, 24 megabytes in use.

Add indicator below, un-comment iMAOnArray function, compile.

Memory usage barely changed, still 24 megabytes.

Comment out iMAOnArray and un-comment iStdDevOnArray. Recompile.

MT4 memory usage jumps to 34 megabytes.

Is this necessay? 10 charts with 3 such indicators adds 300meg to MT4 memory usage. I have become fond of standard deviations recently.


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
 
//---- buffers
double lineBuffer[];
 
double testBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,lineBuffer); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   ArrayResize(testBuffer, Bars);
   ArraySetAsSeries(testBuffer, true);
  
   for(int i = Bars-1; i >= 0; i--){
       testBuffer[i] = Close[i];
   }
   for(    i = Bars-50; i >= 0; i--){
  
       // TEST -- Pick one or the other below, monitor memory usage in TaskManager
      
      
       // Memory requirement samll for this indicator
       //lineBuffer[i] = iMAOnArray(testBuffer, 0, 30, 0, 0, i);
      
      
       // Memory requirement 10 megabyte per chart for this indicator
       // lineBuffer[i] = iStdDevOnArray(testBuffer, 0, 30, 0, 0, i);
 
   }
   return(0);
}


article

A Method of Drawing the Support/Resistance Levels

This article describes the process of creating a simple script for detecting the support/resistance levels. It is written for beginners, so you can find the detailed explanation of every stage of the process. However, though the script is very simple, the article will be also useful for advanced traders and the users of the MetaTrader 4 platform. It contains the examples of the data export into the tabular format, the import of the table to Microsoft Excel and plotting the charts for the further detailed analysis.


avatar
Moderator
33782
Rosh 2008.02.08 10:22 
Add into function start()
Comment("Bars=",Bars);
How many bars are there on your charts?

avatar
2462
phy 2008.02.08 11:12 
The chart had 2000 bars.

avatar
Moderator
33782
Rosh 2008.02.08 11:41 
Thank you, we will check it.

avatar
2462
phy 2008.02.08 12:05 

Here is updated test indicator...

Change between iStdDeviation line and iMAOnArray line using option.

Memory requirement jumps up and down with change


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
 
extern bool STD_DEV_LINE = false;
 
//---- buffers
double lineBuffer[];
double testBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,lineBuffer); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
  
   Comment("\n Bars = ", Bars, "  Time is ", TimeToStr(LocalTime(), TIME_SECONDS));
  
   ArrayResize(testBuffer, Bars);
   ArraySetAsSeries(testBuffer, true);
  
   for(int i = Bars-1; i >= 0; i--){
       testBuffer[i] = Close[i];
   }
   for(    i = Bars-50; i >= 0; i--){
  
       // Memory requirement small for this indicator
        if(STD_DEV_LINE == false) lineBuffer[i] = iMAOnArray(testBuffer, 0, 30, 0, 0, i);
             
       // Memory requirement large for this indicator
        if(STD_DEV_LINE == true)  lineBuffer[i] = iStdDevOnArray(testBuffer, 0, 30, 0, 0, i);
 
   }  
   return(0);
}



avatar
Moderator
33782
Rosh 2008.02.08 17:01 
Bug is fixed, thank you very much! New build will be available soon.

avatar
2462
phy 2008.02.08 20:53 

BUG! How about that..



avatar
Moderator
5089
stringo 2008.02.12 18:59 

Yes, bug. iStdevOnArray started again and again and recalculated every time. Thank You. Your code has helped to discover old problem


avatar
12
apparelink 2009.07.28 18:48 

Hi stringo,

Is there any performance difference between the standard iStdevOnArray() and a custom function like MathStdev()? Is iStdevOnArray() in MT4 optimized in some way?

//+------------------------------------------------------------------+
//| Calculates the standard deviation of a set of values in an array.
//| MathStdev() measures how widely values are dispersed from the
//| average value (the mean).
//+------------------------------------------------------------------+
double MathStdev(double &array[])
{
   int size = ArraySize(array);
   double sum,
          stdev,
          mean = MathAvg(array);
   for (int i = 0; i < size; i++)
      sum += MathPow((array[i] - mean), 2);
   stdev = MathSqrt(sum / (size -1));
   return (stdev);
}

//+------------------------------------------------------------------+
//| Calculates the average value (the mean) of a set of values in an
//| array.
//+------------------------------------------------------------------+
double MathAvg(double &array[])
{
   int size = ArraySize(array);
   double sum,
          mean;
   for (int i = 0; i < size; i++)
      sum += array[i];
   mean = sum / size;
   return (mean);
}

Kind regards,


Scott

Back to topics list  

To add comments, please log in or register