Seeking coding help with Volume Value Color Indicator.

Kuza

New member
Was wondering if it was possible to show each Histogram bar of Volume on a Lower study as a different color depending on the range of volume. I basically copy/pasted the code from the "VolumeAvg" study and tried to edit it.

Code:
# Volume Value Color

declare lower;

input length = 50;

plot Vol = volume;

def rng1 = Vol >= 1;
def rng2 = Vol <= 49999;
def rng3 = Vol >= 50000;
def rng4 = Vol <= 99999;
def rng5 = Vol >= 100000;
def rng6 = Vol <= 999999;
def rng7 = Vol >= 1000000;

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("rng1 && rng2", Color.LIGHT_RED);
Vol.DefineColor("rng3 && rng4", Color.blue);
Vol.DefineColor("rng5 && rng6", Color.green);
Vol.DefineColor("rng7", Color.YELLOW);

These are my current results:
eLsDtes.jpg


Thanks in advance!
 

tomsk

Well-known member
VIP
@Kuza You might want to explore using the between() construct. The following study which is based on your partitioning of the volume size might be close to what you're looking for. You can then add bells and whistles to the code as you wish

Code:
# Volume Color Coded

declare lower;

plot Vol = volume;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.AssignValueColor(if volume >= 1000000 then Color.Yellow
                     else if between(volume, 100000, 999999) then Color.Green
                     else if between(volume, 50000, 99999) then Color.Blue
                     else Color.Light_Red);
# End Volume Color Coded
 
Last edited:

tomsk

Well-known member
VIP
@Kuza Here is another example using DefineColor, in case you'd like to see how this is being used

Code:
# Volume Color Coded
# tomsk
# 1.19.2020

declare lower;

plot Vol = volume;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Volume Low", Color.Light_Red);
Vol.DefineColor("Volume Moderate", Color.blue);
Vol.DefineColor("Volume High", Color.Green);
Vol.DefineColor("Volume Spike", Color.Yellow);
Vol.AssignValueColor(if volume >= 1000000 then Vol.Color("Volume Spike")
                     else if between(volume, 100000, 999999) then Vol.Color("Volume High")
                     else if between(volume, 50000, 99999) then Vol.Color("Volume Moderate")
                     else Vol.Color("Volume Low"));
# End Volume Color Coded
 

Kuza

New member
@tomsk Thanks so much! The between() construct was definitely a more simplified (and functional) route. I wanted to use this for pre-market and open market gap-ups that are seeing high volatility and price action. Usually these segments are fluff news, press releases, and other news related factors. I'm still working on my RSS Feed and News bookmarks, so I more than likely don't get alerted to news releases in time to catch the action. Basically, by the time I hover over the volume value, look up the "cause" of the volatility, and the stock float, I end up in a FOMO position. I'm hoping this indicator, along with my pm and open scanners, will help me find quicker positions to get in and scalp off the "hype" of the moment, rather than ending up in a short position.

Edit: Ohhh okay. Thank you for showing the proper way of using DefineColor with If/Then/Else statements.
 

Similar threads

Top