Reputation: 37
I would like the output from the indicator below to be the lines not continuous but only over 5 candles. Unfortunately, I haven't found a way to draw a Plor line over just 5 candles yet. I would also like the line to be a continuous line and not a dashed line. I tried this option but then the indicator output no longer works properly:
line.new(bar_index - 3, level1, bar_index + 3, level1, color=level1_col, width = 2)
line.new(bar_index - 3, level2, bar_index + 3, level2, color=level2_col, width = 2)
line.new(bar_index - 3, level3, bar_index + 3, level3, color=level3_col, width = 2)
line.new(bar_index - 3, level4, bar_index + 3, level4, color=level4_col, width = 2)
line.new(bar_index - 3, level5, bar_index + 3, level5, color=level5_col, width = 2)
line.new(bar_index - 3, level6, bar_index + 3, level6, color=level6_col, width = 2)
line.new(bar_index - 3, level7, bar_index + 3, level7, color=level7_col, width = 2)
line.new(bar_index - 3, level8, bar_index + 3, level8, color=level8_col, width = 2)
Here are the plot outputs of the indicator in the original:
plot(level1, style = plot.style_line, color=level1_col, show_last=1, linewidth=2, trackprice=true)
plot(level2, style = plot.style_line, color=level2_col, show_last=1, linewidth=2, trackprice=true)
plot(level3, style = plot.style_line, color=level3_col, show_last=1, linewidth=2, trackprice=true)
plot(level4, style = plot.style_line, color=level4_col, show_last=1, linewidth=2, trackprice=true)
plot(level5, style = plot.style_line, color=level5_col, show_last=1, linewidth=2, trackprice=true)
plot(level6, style = plot.style_line, color=level6_col, show_last=1, linewidth=2, trackprice=true)
plot(level7, style = plot.style_line, color=level7_col, show_last=1, linewidth=2, trackprice=true)
plot(level8, style = plot.style_line, color=level8_col, show_last=1, linewidth=2, trackprice=true)
Here is the indicator:
//@version=5
indicator("Test 81", overlay=true)
left = input.int(defval=10, title="Left Bars")
right = input.int(defval=1, title="Right Bars")
quick_right = input.int(defval=5, title="Quick Right")
src = input.string(defval="Close",options = ["Close","High/Low"], title = "Source")
pivot_high = src=="Close" ? ta.pivothigh(close,left,right) : ta.pivothigh(high,left,right)
pivot_lows = src=="Close" ? ta.pivotlow(close, left,right) : ta.pivotlow(low,left,right)
quick_pivot_high = src=="Close" ? ta.pivothigh(close,left,quick_right) : ta.pivothigh(high,left,quick_right)
quick_pivot_lows = src=="Close" ? ta.pivotlow(close, left,quick_right) : ta.pivotlow(low, left,quick_right)
level1 = src=="Close" ? ta.valuewhen(quick_pivot_high, close[quick_right], 0) : ta.valuewhen(quick_pivot_high, high[quick_right], 0)
level2 = src=="Close" ? ta.valuewhen(quick_pivot_lows, close[quick_right], 0) : ta.valuewhen(quick_pivot_lows, low[quick_right], 0)
level3 = src=="Close" ? ta.valuewhen(pivot_high, close[right], 0) : ta.valuewhen(pivot_high, high[right], 0)
level4 = src=="Close" ? ta.valuewhen(pivot_lows, close[right], 0) : ta.valuewhen(pivot_lows, low[right], 0)
level5 = src=="Close" ? ta.valuewhen(pivot_high, close[right], 1) : ta.valuewhen(pivot_high, high[right], 1)
level6 = src=="Close" ? ta.valuewhen(pivot_lows, close[right], 1) : ta.valuewhen(pivot_lows, low[right], 1)
level7 = src=="Close" ? ta.valuewhen(pivot_high, close[right], 2) : ta.valuewhen(pivot_high, high[right], 2)
level8 = src=="Close" ? ta.valuewhen(pivot_lows, close[right], 2) : ta.valuewhen(pivot_lows, low[right], 2)
level1_col = close >= level1 ? color.lime : color.orange
level2_col = close >= level2 ? color.lime : color.orange
level3_col = close >= level3 ? color.lime : color.orange
level4_col = close >= level4 ? color.lime : color.orange
level5_col = close >= level5 ? color.lime : color.orange
level6_col = close >= level6 ? color.lime : color.orange
level7_col = close >= level7 ? color.lime : color.orange
level8_col = close >= level8 ? color.lime : color.orange
plot(level1, style = plot.style_line, color=level1_col, show_last=1, linewidth=2, trackprice=true)
plot(level2, style = plot.style_line, color=level2_col, show_last=1, linewidth=2, trackprice=true)
plot(level3, style = plot.style_line, color=level3_col, show_last=1, linewidth=2, trackprice=true)
plot(level4, style = plot.style_line, color=level4_col, show_last=1, linewidth=2, trackprice=true)
plot(level5, style = plot.style_line, color=level5_col, show_last=1, linewidth=2, trackprice=true)
plot(level6, style = plot.style_line, color=level6_col, show_last=1, linewidth=2, trackprice=true)
plot(level7, style = plot.style_line, color=level7_col, show_last=1, linewidth=2, trackprice=true)
plot(level8, style = plot.style_line, color=level8_col, show_last=1, linewidth=2, trackprice=true)
Upvotes: 0
Views: 84
Reputation: 21342
It is a dashed line because of trackprice=true
so you need to delete those.
plot()
has an argument called show_last
which does exactly what you want and is set to 1
in the code.
show_last (input int) If set, defines the number of bars (from the last bar back to the past) to plot on chart.
Just change it to 5
and you will be good.
Upvotes: 0