Need help altering difference code

RickK

Active member
Hey All,

I'm trying to design a lower indicator that has the day's open as a zeroline and the current price either above or below the zeroline as a histogram that measures from the zeroline and up (if price is currently above the day's open) or from the zeroline and down (if price is currently below the day's open). Hoping someone can help...or direct me to relevant education.

I can plot the price line (red line on top indicator shown below), but when I change the line to a histogram it starts from the bottom of the display. I'm hoping to get it to start from the zeroline and project downward or upward (looking like a MACD histogram does).

Thanks!

Here's the current code:

Code:
declare lower;

input period_day = AggregationPeriod.DAY;

def begin = open(period = period_day);
def end = close(period = period_day);
def NetChg = end - begin;
def NetChgRatio = NetChg;

plot OpenLine = begin;
plot value = close;

AddLabel(yes, "Net NQ " + NetChgRatio , if NetChgRatio > 0 then Color.GREEN else if NetChgRatio < 0 then color.RED else color.LIGHT_GRAY);

I also tried the following code, to no avail.

Code:
declare lower;

input period_day = AggregationPeriod.DAY;

def begin = open(period = period_day);
def end = close(period = period_day);
def NetChg = end - begin;
def NetChgRatio = NetChg;

plot OpenLine = begin;
plot value = begin + NetChg;
#plot value = close; commented out this line to replace with line above

AddLabel(yes, "Net NQ " + NetChgRatio , if NetChgRatio > 0 then Color.GREEN else if NetChgRatio < 0 then color.RED else color.LIGHT_GRAY);

 
Last edited:

halcyonguy

Active member
VIP
i think histograms plot from 0..? so find the difference from the day open to close.
diff = close - dayopen
use 2 plot variables, to create 2 histograms.
if positive, plot a value to histogram1 else 0.
if the difference is negative, then plot (-1 * difference ) to a 2nd histogram else 0.
 

generic

Active member
@RickK Try this and see if it's what you're looking for.
Code:
declare lower;

input period_day = AggregationPeriod.DAY;

def begin = open(period = period_day);
def end = close(period = period_day);
def NetChg = end - begin;
def NetChgRatio = NetChg;
def diff = close - begin;

plot d = diff;
d.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

AddLabel(yes, "Net NQ " + NetChgRatio , if NetChgRatio > 0 then Color.GREEN else if NetChgRatio < 0 then color.RED else color.LIGHT_GRAY);
 

RickK

Active member
@RickK Try this and see if it's what you're looking for.
Code:
declare lower;

input period_day = AggregationPeriod.DAY;

def begin = open(period = period_day);
def end = close(period = period_day);
def NetChg = end - begin;
def NetChgRatio = NetChg;
def diff = close - begin;

plot d = diff;
d.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

AddLabel(yes, "Net NQ " + NetChgRatio , if NetChgRatio > 0 then Color.GREEN else if NetChgRatio < 0 then color.RED else color.LIGHT_GRAY);

You are the man @generic !! Thanks so much! 🙏 Worked like a charm.
 

Similar threads

Top