Download MetaTrader 5
To add comments, please log in or register
Format text in the messages editor. It is convenient!
Raja K.
25
Raja K. 2016.05.05 17:45 

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
   SetIndexBuffer(0,NHB);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,EMPTY,NewHighBar);
   SetIndexBuffer(1,NLB);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,EMPTY,NewLowBar);
   SetIndexBuffer(2,OB);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,EMPTY,OutsideBar);
   SetIndexBuffer(3,IB);
   SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,EMPTY,InsideBar);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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)
   {
      first=1;
   }
   else first=prev_calculated-1;

   for(bar=first; bar<rates_total && !IsStopped(); bar++)
   {
      if(high[bar]>high[bar+1])
      {
         if(low[bar]<low[bar+1])
            OB[bar]=(double)tick_volume[bar];
         else
            NHB[bar]=(double)tick_volume[bar];
      }
      else if(low[bar]<low[bar+1])
      {
         NLB[bar]=(double)tick_volume[bar];
      }
      else
      {
         IB[bar]=(double)tick_volume[bar];
      }
   }  
   
//--- return value of prev_calculated for next call
   return(rates_total);
   
  }
  
//+------------------------------------------------------------------+

 

Thanks. 

Files:
/
To add comments, please log in or register