TradingView
xinolia
26 Feb 2022 pukul 15.36

Zig Zag(auto Horizon lines) 

Bitcoin all time history indexINDEX

Huraian

A guy who automatically draws a horizon from the top of the zigzag
*Gray horizon may be repainted
The horizon of the characteristic price in the past reacts well, so it is used for contrarian

ジグザクの頂点から、自動で水平線を引く奴です
※灰色の水平線はリペイントする可能性があります
過去の特徴的な価格の水平線はよく反応するので、逆張りするとかが用途です

Nota Keluaran

update: add alert
Komen
brettkind
Does this Indicator repaint?
ab_fiba
Hello. Tell me to really add the code so that the lines are not displayed on the entire chart, but for example on the price range. So that in the settings you can manually specify the range on which to draw support and resistance lines. For example BTC 18000-25000.
It would be very convenient.
Thanks in advance!
shahabforuhar
//@version=5
indicator("Zig Zag(auto Horizon lines)", overlay=true, max_lines_count=500, max_labels_count=500)
dev_threshold = input.float(title="Deviation (%)", defval=10.0, minval=0.00001, maxval=100.0)
depth = input.int(title="Depth", defval=10, minval=1)
line_color2 = input(title="Line Color", defval=#2962FF)
extend_to_last_bar = input(title="Extend to Last Bar", defval=true)
display_reversal_price = input(title="Display Reversal Price", defval=false)
display_cumulative_volume = input(title="Display Cumulative Volume", defval=false)
display_reversal_price_change = input(title="Display Reversal Price Change", defval=false, inline="price rev")
difference_price = input.string("Absolute", "", options=["Absolute", "Percent"], inline="price rev")
showzigzagfg = input.bool(title="Show ZigZag", defval=true)
noneColor = color.new(color.white, 100)
line_color = showzigzagfg ? line_color2 : noneColor
show0fg = input.bool(title="Show Horizon LINES", defval=true)
LINEMAX = input.int(title="MAX Horizon LINES", defval=15, minval=1)

pivots(src, length, isHigh) =>
p = nz(src[length])
if length == 0
[time, p]
else
isFound = true
for i = 0 to math.abs(length - 1)
if isHigh and src > p
isFound := false
if not isHigh and src < p
isFound := false
for i = length + 1 to 2 * length
if isHigh and src >= p
isFound := false
if not isHigh and src <= p
isFound := false
if isFound and length * 2 <= bar_index
[time[length], p]
else
[int(na), float(na)]

[iH, pH] = pivots(high, math.floor(depth / 2), true)
[iL, pL] = pivots(low, math.floor(depth / 2), false)

calc_dev(base_price, price) =>
100 * (price - base_price) / base_price

price_rotation_aggregate(price_rotation, pLast, cum_volume) =>
str = ""
if display_reversal_price
str += str.tostring(pLast, format.mintick) + " "
if display_reversal_price_change
str += price_rotation + " "
if display_cumulative_volume
str += "\n" + cum_volume
str

caption(isHigh, iLast, pLast, price_rotation, cum_volume) =>
price_rotation_str = price_rotation_aggregate(price_rotation, pLast, cum_volume)
if display_reversal_price or display_reversal_price_change or display_cumulative_volume
if not isHigh
label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.belowbar, textcolor=color.red)
else
label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.abovebar, textcolor=color.green)

price_rotation_diff(pLast, price) =>
if display_reversal_price_change
tmp_calc = price - pLast
str = difference_price == "Absolute"? (math.sign(tmp_calc) > 0? "+" : "") + str.tostring(tmp_calc, format.mintick) : (math.sign(tmp_calc) > 0? "+" : "-") + str
aryans1884
How to get previous 6 pivots
wisesun
what do depth represent?
RozaniGhani-RG
i think the code is similar to old version of built-in zigzag indicator.
TrnMnhThna4ac6022685c4df9
Hello, how to alert when new High or Low?
zxzxzx1234
Hello, good work, can the horizontal line be turned into a range, thanks
Lebih