0

I'm trying to offset the colored histogram bars to the left 2 spaces(offset= -2). The colored bars represent up and down fractals above and below the Zeroline. I've gotten this far but I can't figure out where or how to accomplish this. The offset work fine with a plots.

Any help is appreciated

Fractal Colored Histogram

I have no experience in scripting, just copy and paste and some trouble shooting, but I been stuck on this one for a couple of week. So I figure I better reach out for help.

I tried applying the offset command to various histogram related line to no avail.

//@version=4
study("TSI histogram Fractal Alerts", shorttitle='TSI Alerts', precision=1)

long = input(title="Long Length", type=input.integer, defval=16) 
short = input(title="Short Length", type=input.integer, defval=8) 
sig1 = input(title="Sig1 Length", type=input.integer, defval=6) 
price = close
pc = change(price)
src = input(close, "source")
Zeroline = 0
check = input(true, "Histogram Alert Points")
offset=-2


double_smooth(src, long, short) =>
    fist_smooth = ema(src, long)
    ema(fist_smooth, short)

double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(abs(pc), long, short)
tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)

hist = tsi_value - ema(tsi_value, sig1) 
signal = ema(tsi_value, sig1)

// //////////////////////////////////////////////////////////////

h1 = hist[4]
h2 = hist[3]
h3 = hist[2]
h4 = hist[1]
h5 = hist[0]

l1 = hist[4]
l2 = hist[3]
l3 = hist[2]
l4 = hist[1]
l5 = hist[0]

histhi = h1 < h2 and h2 < h3 and h3 > h4 and h4 > h5
histlo = l1 > l2 and l2 > l3 and l3 < l4 and l4 < l5

// histogram pattern -----

hist_up_plus = hist >= 0 and histhi
hist_down_plus = hist <= 0 and histlo
hist_up_minus = hist <= 0 and histhi
hist_down_minus = hist >= 0 and histlo

hist_color = 
   hist_up_plus ? color.rgb(234, 54, 54) :
   hist_down_plus ? color.rgb(39, 154, 89) : 
   hist_up_minus ? color.rgb(67, 85, 187) : 
   hist_down_minus ? color.rgb(183, 172, 50) : color.rgb (242, 244, 244)

// plot -----
plot(hist, "Histogram", hist_color, 1, plot.style_columns)
plot(signal, "Signal", #f1cb0a, 1, transp=0, linewidth=1)
plot(tsi_value, "TSI", #0094ff, 1, transp=95, linewidth=1)

// alert -----

plotchar(check and (hist[1] < 0 and hist[0] > 0), "Histogram Crossover", "▔", location.top, color.rgb(247, 225, 61), 20)
plotchar(check and (hist[1] > 0 and hist[0] < 0), "Histogram Crossunder", "▁", location.bottom, color.rgb(247, 225, 61), 20)

plotchar(check and (crossover(signal, +0)), "Signal Line Crossover", "▔", location.top, color.rgb(96, 162, 243), 20)
plotchar(check and (crossunder(signal, -0)), "Signal Line Crossover", "▁", location.bottom, color.rgb(96, 162, 243), 20)

// Line plots
hline(0, title="Zeroline", color=color.rgb(50, 49, 49, transp=50), linewidth=1)
hline(40, title="Overbought", color=color.rgb(36, 140, 36, transp=50), linewidth=1)
hline(-40, title="Oversold", color=color.rgb(197, 49, 49, transp=50), linewidth=1)

hline(20, title="Neutral Zone_T", color=color.rgb(50, 49, 49, transp=50), linewidth=1)
hline(-20, title="Neutral Zone_B", color=color.rgb(50, 49, 49, transp=50), linewidth=1)
Roadside
  • 1
  • 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Nov 30 '22 at 06:40
  • just add the offset parameter to the plot lines if that is all you need and give the offset the value you want. – John Baron Nov 30 '22 at 13:38

1 Answers1

0

You can't offset just the color and the whole series. If you want to offset them both, you can use:

plot(hist, "Histogram", hist_color, 1, plot.style_columns, offset = -2)

If you want to offset just the color, but not the hist series, we'll need to be a bit more creative and plot 2 separate plot one over the other. One of them will plot the hist series and will have no offset and will have only the basic color. The other one will have different colors (all colors other then the basic one), and it will offset them by -2:

hist_color = 
   hist_up_plus ? color.rgb(234, 54, 54) :
   hist_down_plus ? color.rgb(39, 154, 89) : 
   hist_up_minus ? color.rgb(67, 85, 187) : 
   hist_down_minus ? color.rgb(183, 172, 50) : na

// plot -----
plot(hist, "Histogram", color.rgb (242, 244, 244), 1, plot.style_columns)
plot(hist[2], "Histogram", hist_color, 1, plot.style_columns, offset = -2)
mr_statler
  • 1,913
  • 2
  • 3
  • 14