ArraySetAsSeries does NOT work with volume array

To add comments, please log in or register
Skullnick
52
Skullnick  

Hi,

Could this be fixed in the next version ? Test for yourself : 

//+------------------------------------------------------------------+
//|                                                     B_Volume.mq5 |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property link      "https://www.mql5.com"
#property version   "1.00"

//--- plot parameters
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_color1  Green,Red
#property indicator_minimum 0.0

//---- indicator buffers
double                    ExtVolumesBuffer[];
double                    ExtColorBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
//---- buffers   
   SetIndexBuffer(0,ExtVolumesBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"B_Volume");
//---- indicator digits
   IndicatorSetInteger(INDICATOR_DIGITS,0);
}
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    // Set as timeseries
    ArraySetAsSeries(close, true);
    ArraySetAsSeries(open, true);
    ArraySetAsSeries(volume, true);
     
//--- Check correct amount of data
    if(rates_total < 2)
      return(0);
      
    int iLast = 0;

    if(prev_calculated == 0)
      iLast = rates_total - 2;
    else
      iLast = rates_total - prev_calculated;
      
//--- main loop
    for(int i = iLast; i >= 0 && !IsStopped();i--)
    {
      ExtVolumesBuffer[i] = (double)volume[i];
      
      if(close[i] > open[i])
        ExtColorBuffer[i]=1.0; // set color Green
      else                               
        ExtColorBuffer[i]=0.0; // set color Red            
    }
//---- OnCalculate done. Return new prev_calculated.
    return(rates_total);
  }

//+------------------------------------------------------------------+


Now just, to test it, set it as FALSE and in the main loop just write :

for(int i = 1; i <= rates_total - 1 && !IsStopped();i++)
Alain Verleyen
39009
Alain Verleyen  
Skullnick:

Hi,

Could this be fixed in the next version ? Test for yourself : 


Now just, to test it, set it as FALSE and in the main loop just write :

Your topic is certainly not a trading systems. Please use the appropriate section when posting. Moved.


ArraySetAsSeries is working well with ALL arrays.

It's a bug in your code. You need to add :

    ArraySetAsSeries(ExtVolumesBuffer, true);
    ArraySetAsSeries(ExtColorBuffer, true);
Skullnick
52
Skullnick  
Alain Verleyen:

Your topic is certainly not a trading systems. Please use the appropriate section when posting. Moved.


ArraySetAsSeries is working well with ALL arrays.

It's a bug in your code. You need to add :

Thanks - I'm tired... :)
To add comments, please log in or register