Displaying Volume on Chart window

 

Hi,

Would anyone know how to display volume in the chart window?

It is easy enough displaying it in a separate window, but I am having problems placing it in the chart window itself (at the bottom border). My code is listed below. If I use #property indicator_separate_window, it shows in a separate window. If I use #property indicator_chart_window, it doesn't show at all. I guess this is because the indicator values are displayed relative to price itself, which might be an issue.

Any help most appreciated.

Cheers, mag1kus


//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
 
double VolBuffer[];
 
int init()
  {
   IndicatorBuffers(1);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, VolBuffer);
   SetIndexDrawBegin(0, VolBuffer);
   return(0);
  }
 
int start()
  {
   int counted_bars = IndicatorCounted();
   int limit = Bars - counted_bars;
   if (counted_bars > 0) limit++;
 
   for(int i = 0; i < limit; i++)
      VolBuffer[i] = Volume[i];
   
   return(0);
  } 
 

You are right, it's because the values are drawn relative to the price. You have to use https://docs.mql4.com/windows/WindowPriceMin and introduce some scaling variable. It should work basically.

But there are a few downsides.

  • if the range of the visual chart changes you have to redraw all the values
  • it will not realy work for visual backtests since you cannot calculate easily the WindowPriceMin for past bars..

 

Oh thanks for the quick response! I was unfamiliar with WindowPriceMin. I'll incorporate WindowPriceMin, or just simply use Ctrl-L.

Thanks again!

 

mag1kus:

Would anyone know how to display volume in the chart window?

It is easy enough displaying it in a separate window, but I am having problems placing it in the chart window itself (at the bottom border).

press control-L, no code needed.
 
i though you may want use some custom volume indicator...
 
Oh yes that is my intent. But was just going to use Ctrl-L if all else failed as I wanted to make modifications to the standard Volume indicator.
Reason: