A Different Way of Looking at Volume

 

Hi all


I want to Change the way the volume histogram is displayed on my charts. Rather than the standard method of the colours changing depending on whether the volume is either higher or lower than the previous bar. I would like to see it so the volume bar is green when the close on the price candle is 'up' and have the volume bar red when the close on the price candle is 'down'.


As you can see from the attached file, I have borrowed a standard volume indicator from the MT code base and attempted to change it. I say 'attempted' because that is about all it is. As you will see, my understanding of coding is very limited and I have run into a brick wall on this one. When I compile it there aren't any warnings or errors (which is always a happy occasion for me). But the indicator doesn't work either.


If anyone out there has nothing better to do, maybe they would like to take a look at my efforts and, after they have finished laughing, give me some pointers as to where I've gone wrong.


Thanks in advance.


Regards


Llamedos.

Files:
 

L

I see where you're going but you may just be re-inventing the OBV?

See what you think of this https://www.mql5.com/en/code/7997

Good Luck

-BB-

 
The method to do what you want is to have 2 indicator buffers one for each colour then load the buffer colour with the value of volume depending on the comparison between the last and current close prices. The buffer that is not required is loaded with EMPTY_VALUE not 0.0 because 0.0 will give you a line on the chart when really you want the unused histogram to disappear. Try this and look how simple it is. Check it is the right way round and works correctly though because I just slapped this together in a few minutes but I think you get the general idea.
Files:
 

Hi Guys - thank you both for your replies. I have answered you separately below.


Ruptor - thank you very much for making sense of my effort at coding this thing. I have tweaked your code a bit - changed the predefined variables from 'Volumes' to 'Open' and Close' - and attached the result below if you are interested. As you will see I found it easier to work out and learn what you were doing and why by adding LOTS of notes. I hope my interpretation of the code is correct!


BarrowBoy - Thanks for the link to the OBV indicator. While I had previously heard of OBV I had never looked at how the indicator was built and the page you linked to gives a really good explanation.


Having read about it, I am now sure that the information I have plotted with my indicator is not the same as OBV - no where near as sophisticated for a start! Mine is simply designed to show if the volume bar I am looking at was created on an 'up' bar or a 'down' bar. As I am a devotee of VSA it helps me be able to clarify this at a glance. But OBV does look interesting and I will look at it to see if it can be usefully incorporated into my studies.


Anyway, thanks to both of you for your input.


Regards


Llamedos