Getting stuck with horizontal line code. plz help
Posted: Sun Feb 12, 2023 8:59 pm
https://www.tradingview.com/x/1VpFAdqO/
I've posted a photo of my chart. I have been able to create horizontal lines from a few of the Labeled highs/lows, but i'm stuck with how to get horizontal lines to come from Each Labeled high/low. Any help would be extremely appreciated.
Here's the code:
//@version=5
indicator("FBT Order", overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500)
exend_lines = input.int(defval = 1, title = "extend lines", minval = 0, maxval = 10, step = 1)
zig_up_color = input.color(defval = color.rgb(76, 175, 79, 100), title = "zigzag uptrend color")
zig_dn_color = input.color(defval = color.rgb(255, 82, 82, 100), title = "zigzag uptrend color")
upper_line_color = input.color(defval = #707177, title = "upper line color")
lower_line_color = input.color(defval = #707177, title = "lower line color")
upper_text_color = input.color(defval = #707177, title = "upper text color")
lower_text_color = input.color(defval = #707177, title = "lower text color")
inside_bar_color = input.color(defval = #bdced9, title = "inside bar color")
ohlc4_up_color = input.color(defval = color.rgb(76, 175, 79, 100), title = "zigzag uptrend color")
ohlc4_dn_color = input.color(defval = color.rgb(255, 82, 82, 100), title = "zigzag uptrend color")
var float zig_zag = 0.0
var int trend = 0
var color zig_zag_color = na
outside_bar = high > high[1] and low < low[1]
inside_bar = high < high[1] and low > low[1]
var float A = 0.0
var int A_index = 0
var float B = 0.0
var int B_index = 0
var float C = 0.0
var int C_index = 0
var float D = 0.0
var int D_index = 0
var string label_text = ""
var bool red_line_crossed = false
var bool green_line_crossed = false
var string last_live_line = ""
if barstate.isconfirmed
if high >= high[1] and low >= low[1]
trend := 1
else if low <= low[1] and high <= high[1]
trend := -1
if trend == 1 and inside_bar// and not(inside_bar[1])
trend := -1
else if trend == -1 and inside_bar// and not(inside_bar[1])
trend := 1
if trend == 1 and outside_bar// and not(outside_bar[1])
if ohlc4 < ohlc4[1]
trend := -1
else
trend := 1
else if trend == -1 and outside_bar// and not(outside_bar[1])
if ohlc4 < ohlc4[1]
trend := -1
else
trend := 1
if trend == 1
zig_zag := high
zig_zag_color := zig_up_color
else if trend == -1
zig_zag := low
zig_zag_color := zig_dn_color
if trend != trend[1] and barstate.isconfirmed
A := B
A_index := bar_index - 1
B := C
B_index := bar_index - 1
C := D
C_index := bar_index - 1
D := zig_zag[1]
D_index := bar_index - 1
if trend == 1 and outside_bar and low < D
D := low
D_index := bar_index
if trend == -1 and outside_bar and high > D
D := high
D_index := bar_index
if trend == -1 and D > B
label_text := "HH"
if trend == -1 and D < B
label_text := "LH"
line.new(D_index, D, bar_index + exend_lines, D, xloc = xloc.bar_index, color = upper_line_color)
last_live_line := "upper_line"
green_line_crossed := false
if trend == 1 and D < B
label_text := "LL"
if trend == 1 and D > B
label_text := "HL"
line.new(D_index, D, bar_index + exend_lines, D, xloc = xloc.bar_index, color = lower_line_color)
last_live_line := "lower_line"
red_line_crossed := false
label.new(x = D_index, y = D, text = label_text, xloc = xloc.bar_index, yloc = trend == 1 ? yloc.belowbar : yloc.abovebar, color = na, style = label.style_none, textcolor = trend == -1 ? upper_text_color : lower_text_color, size = size.normal)
a_lines = line.all
if barstate.isconfirmed and array.size(a_lines) > 0// and trend == trend[1]
if last_live_line == "lower_line"
if low < line.get_y1(array.get(a_lines, array.size(a_lines) - 1))
red_line_crossed := true
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
alert("CHOCH " + syminfo.tickerid)
last_live_line := ""
else if red_line_crossed == false
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
if last_live_line == "upper_line"
if high > line.get_y1(array.get(a_lines, array.size(a_lines) - 1))
green_line_crossed := true
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
alert("CHOCH " + syminfo.tickerid)
last_live_line := ""
else if green_line_crossed == false
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
if red_line_crossed[1]
red_line_crossed := false
if green_line_crossed[1]
green_line_crossed := false
barcolor(inside_bar ? inside_bar_color : na)
I've posted a photo of my chart. I have been able to create horizontal lines from a few of the Labeled highs/lows, but i'm stuck with how to get horizontal lines to come from Each Labeled high/low. Any help would be extremely appreciated.
Here's the code:
//@version=5
indicator("FBT Order", overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500)
exend_lines = input.int(defval = 1, title = "extend lines", minval = 0, maxval = 10, step = 1)
zig_up_color = input.color(defval = color.rgb(76, 175, 79, 100), title = "zigzag uptrend color")
zig_dn_color = input.color(defval = color.rgb(255, 82, 82, 100), title = "zigzag uptrend color")
upper_line_color = input.color(defval = #707177, title = "upper line color")
lower_line_color = input.color(defval = #707177, title = "lower line color")
upper_text_color = input.color(defval = #707177, title = "upper text color")
lower_text_color = input.color(defval = #707177, title = "lower text color")
inside_bar_color = input.color(defval = #bdced9, title = "inside bar color")
ohlc4_up_color = input.color(defval = color.rgb(76, 175, 79, 100), title = "zigzag uptrend color")
ohlc4_dn_color = input.color(defval = color.rgb(255, 82, 82, 100), title = "zigzag uptrend color")
var float zig_zag = 0.0
var int trend = 0
var color zig_zag_color = na
outside_bar = high > high[1] and low < low[1]
inside_bar = high < high[1] and low > low[1]
var float A = 0.0
var int A_index = 0
var float B = 0.0
var int B_index = 0
var float C = 0.0
var int C_index = 0
var float D = 0.0
var int D_index = 0
var string label_text = ""
var bool red_line_crossed = false
var bool green_line_crossed = false
var string last_live_line = ""
if barstate.isconfirmed
if high >= high[1] and low >= low[1]
trend := 1
else if low <= low[1] and high <= high[1]
trend := -1
if trend == 1 and inside_bar// and not(inside_bar[1])
trend := -1
else if trend == -1 and inside_bar// and not(inside_bar[1])
trend := 1
if trend == 1 and outside_bar// and not(outside_bar[1])
if ohlc4 < ohlc4[1]
trend := -1
else
trend := 1
else if trend == -1 and outside_bar// and not(outside_bar[1])
if ohlc4 < ohlc4[1]
trend := -1
else
trend := 1
if trend == 1
zig_zag := high
zig_zag_color := zig_up_color
else if trend == -1
zig_zag := low
zig_zag_color := zig_dn_color
if trend != trend[1] and barstate.isconfirmed
A := B
A_index := bar_index - 1
B := C
B_index := bar_index - 1
C := D
C_index := bar_index - 1
D := zig_zag[1]
D_index := bar_index - 1
if trend == 1 and outside_bar and low < D
D := low
D_index := bar_index
if trend == -1 and outside_bar and high > D
D := high
D_index := bar_index
if trend == -1 and D > B
label_text := "HH"
if trend == -1 and D < B
label_text := "LH"
line.new(D_index, D, bar_index + exend_lines, D, xloc = xloc.bar_index, color = upper_line_color)
last_live_line := "upper_line"
green_line_crossed := false
if trend == 1 and D < B
label_text := "LL"
if trend == 1 and D > B
label_text := "HL"
line.new(D_index, D, bar_index + exend_lines, D, xloc = xloc.bar_index, color = lower_line_color)
last_live_line := "lower_line"
red_line_crossed := false
label.new(x = D_index, y = D, text = label_text, xloc = xloc.bar_index, yloc = trend == 1 ? yloc.belowbar : yloc.abovebar, color = na, style = label.style_none, textcolor = trend == -1 ? upper_text_color : lower_text_color, size = size.normal)
a_lines = line.all
if barstate.isconfirmed and array.size(a_lines) > 0// and trend == trend[1]
if last_live_line == "lower_line"
if low < line.get_y1(array.get(a_lines, array.size(a_lines) - 1))
red_line_crossed := true
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
alert("CHOCH " + syminfo.tickerid)
last_live_line := ""
else if red_line_crossed == false
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
if last_live_line == "upper_line"
if high > line.get_y1(array.get(a_lines, array.size(a_lines) - 1))
green_line_crossed := true
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
alert("CHOCH " + syminfo.tickerid)
last_live_line := ""
else if green_line_crossed == false
line.set_x2(array.get(a_lines, array.size(a_lines) - 1), bar_index + exend_lines)
if red_line_crossed[1]
red_line_crossed := false
if green_line_crossed[1]
green_line_crossed := false
barcolor(inside_bar ? inside_bar_color : na)