Download MetaTrader 5

Colored Volume Refresh

To add comments, please log in or register
Raja K.
Raja K.  

I am copying and pasting this from forexfactory because help might be better here:

There is a customized volume indicator which needs to do the following:

I want it to only show Volume bars for the corresponding price bars that made a high or low.

1. The price bar that makes a new high would have a volume bar shown as blue.

2. The price bar that makes a new low would have a volume bar shown as red.

3. The price bar that makes a new high AND a new low (outside bar) would have a volume bar colored grey.

4. The price bar that DOES NOT make a new high or a new low would have an invisible price bar.... i.e. no color.

I would like all the colors to be adjustable so if i change background colors on my charts i could adjust the volume colors if need be. 


The attached indicator does just this, but it does not work for a live market; that is, when the indicator gets attached to the chart, it will correctly show which volume bar gets which color; but will not create any new volume bars after.  I don't know if this is a difficult issue or just something simple that has been overlooked.

Here's the code for anyone who would rather see it here:

//|                                                billko_volume.mq4 |
//|                                                                  |
//|                                                                  |
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot Label1
#property indicator_label1  "New High Bar"
#property indicator_label2  "New Low Bar"
#property indicator_label3  "Outside Bar"
#property indicator_label4  "Inside Bar"

//--- input parameters
input color    NewHighBar=clrBlue;
input color    NewLowBar=clrRed;
input color    OutsideBar=clrGray;
input color    InsideBar;
//--- indicator buffers
double         NHB[];
double         NLB[];
double         OB[];
double         IB[];
//| Custom indicator initialization function                         |
int OnInit()
//--- indicator buffers mapping
//| 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[])

   int first,bar;
   if(prev_calculated>rates_total || prev_calculated<=0)
   else first=prev_calculated-1;

   for(bar=first; bar<rates_total && !IsStopped(); bar++)
      else if(low[bar]<low[bar+1])
//--- return value of prev_calculated for next call



To add comments, please log in or register