You are on page 1of 22

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// Big thanks to AlbaTherium for orginal script
https://www.tradingview.com/script/nSSzkNji-AlbaTherium-Structure-mapping-v2-0/
// Author: Ma Bang Chu from https://t.me/wyckoffneverdie

//@version=5
indicator("聖杯 ver2", "聖杯 ver2", true, max_bars_back = 5000, max_labels_count =
500, max_lines_count = 500)

ShowBB = input.bool(false, 'BB ON/OFF ', inline = 'overlayLine1', group =


'ON/OFF')
////////////ShowSmartTrail ADD START
ShowSmartTrail = input.bool(true, 'Smart Trail Now TF', group = 'ON/OFF', inline =
'overlayLine3')
ShowSmartTrailTF1 = input.bool(true, 'SMT TF 1', group = 'ON/OFF', inline =
'overlayLine3')
ShowSmartTrailTF2 = input.bool(false, 'SMT TF 2', group = 'ON/OFF', inline =
'overlayLine3')

multiTF1 = input.timeframe('60','multi timeframe 1:', group="👉 SmartTrail


Settings")
multiTF2 = input.timeframe('5','multi timeframe 2:', group="👉 SmartTrail Settings")
trailType = input.string('modified', 'Trailtype', options=['modified',
'unmodified'], group = "👉 SmartTrail Settings")
ATRPeriod = input(200, 'ATR Period', group = "👉 SmartTrail Settings")
ATRFactor_default = input.float(8, 'ATR Factor mặc định', group = "👉 SmartTrail
Settings" ,tooltip = "Các TF ngoài các khung bên dưới sẽ sử dụng thông số mặc
định",minval = 2, maxval = 10, step = 0.5)

ATRFactor_ON_OF = input.bool(true,"Thiet lap gia tri theo tung TF", group = "👉
SmartTrail Settings")
ATRFactor_M5 = input.float(6, 'ATR Factor M5', group = "👉 SmartTrail
Settings" ,tooltip = "Thông số mặc định phù hợp đánh vàng",minval = 2, maxval = 10,
step = 0.5)
ATRFactor_M15 = input.float(5.7, 'ATR Factor M15', group = "👉 SmartTrail
Settings" ,tooltip = "Thông số mặc định phù hợp đánh vàng",minval = 2, maxval = 10,
step = 0.5)
ATRFactor_M30 = input.float(8, 'ATR Factor M30', group = "👉 SmartTrail
Settings" ,tooltip = "Thông số mặc định phù hợp đánh vàng",minval = 2, maxval = 10,
step = 0.5)
ATRFactor_H1 = input.float(6, 'ATR Factor H1', group = "👉 SmartTrail
Settings" ,tooltip = "Thông số mặc định phù hợp đánh vàng",minval = 2, maxval = 10,
step = 0.5)
ATRFactor_H4 = input.float(7, 'ATR Factor H4', group = "👉 SmartTrail
Settings" ,tooltip = "Thông số mặc định phù hợp đánh vàng",minval = 2, maxval = 10,
step = 0.5)
ATRFactor_D1 = input.float(7, 'ATR Factor D1', group = "👉 SmartTrail
Settings" ,tooltip = "Thông số mặc định phù hợp đánh vàng",minval = 2, maxval = 10,
step = 0.5)
smtColorfib1_up = input.color (color.rgb(0, 13, 255, 57), "smtColorfib1_up",
group="👉 SmartTrail Settings")
smtColorfib1_down = input.color (color.rgb(255, 0, 0, 50), "smtColorfib1_down",
group="👉 SmartTrail Settings")
smtColorfib2 = input.color (color.new(#73760d, 49), "smtColorfib2", group="👉
SmartTrail Settings")
smtColorfib3 = input.color (color.new(#73760d, 51), "smtColorfib3", group="👉
SmartTrail Settings")

fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6

//box_width = input.float(7, title = 'Supply/Demand Box Width', group = "👉 SUPPLY


AND DEMAND", minval = 1, maxval = 10, step = 0.5)
Smoothing = input(5, 'Smoothing', group = "👉 SmartTrail Settings")

/// set value ATRFactor when TimeFrame change


getATRFactor(TF) =>
ATRFactor = if TF == "5" and ATRFactor_ON_OF
ATRFactor_M5
else if TF == "15"and ATRFactor_ON_OF
ATRFactor_M15
else if TF == "30"and ATRFactor_ON_OF
ATRFactor_M30
else if TF == "60" and ATRFactor_ON_OF
ATRFactor_H1
else if TF == "240"and ATRFactor_ON_OF
ATRFactor_H4
else if TF == "1440"and ATRFactor_ON_OF
ATRFactor_D1
else
ATRFactor_default
ATRFactor

// drawWithLabel(price) =>
// // Khai báo biến cho nhãn
// var label_id = label.new(na, na, text="", color=color.rgb(33, 149, 243,
100), style=label.style_label_left, yloc=yloc.price)
// // Xóa nhãn nếu không phải là cây nến cuối cùng
// if not barstate.islast
// label.delete(label_id)
// // Tính chỉ số của cây nến cuối cùng
// last_candle_index = bar_index - ta.barssince(ta.change(time)) + 1
// // Đặt nhãn mới cho đường EMA tại cây nến cuối cùng
// if barstate.islast
// label_id := label.new(last_candle_index, price, text="EMA(" +
str.tostring(price) + ")", color=color.blue, style=label.style_label_left,
yloc=yloc.price)

// Function
Wild_ma(_src, _malength) =>
_wild = 0.0
_wild := nz(_wild[1]) + (_src - nz(_wild[1])) / _malength
_wild

CalculateSMT_MultiTF(TF, ATRFactorInput) =>


norm_o = request.security(ticker.new(syminfo.prefix, syminfo.ticker), TF, open)
norm_h = request.security(ticker.new(syminfo.prefix, syminfo.ticker), TF, high)
norm_l = request.security(ticker.new(syminfo.prefix, syminfo.ticker), TF, low)
norm_c = request.security(ticker.new(syminfo.prefix, syminfo.ticker), TF,
close)
ATRFactor = ATRFactorInput
/////////// TRUE RANGE CALCULATIONS /////////////////
HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod)))
HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 *
(norm_l - norm_h[1])
LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 *
(norm_l[1] - norm_h)
trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) :
math.max(norm_h - norm_l, math.abs(norm_h - norm_c[1]), math.abs(norm_l -
norm_c[1]))
/////////// TRADE LOGIC ////////////////////////

loss = ATRFactor* Wild_ma(trueRange, ATRPeriod)

Up68 = norm_c - loss


Dn68 = norm_c + loss

TrendUp = Up68

TrendDown = Dn68

Trendtrade = 1
TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up68, TrendUp[1]) : Up68

TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn68, TrendDown[1]) : Dn68

Trendtrade := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 :


nz(Trendtrade[1], 1)
trail = Trendtrade == 1 ? TrendUp : TrendDown

ex = 0.0
ex := ta.crossover(Trendtrade, 0) ? norm_h : ta.crossunder(Trendtrade, 0) ?
norm_l : Trendtrade == 1 ? math.max(ex[1], norm_h) : Trendtrade == -1 ?
math.min(ex[1], norm_l) : ex[1]
[ex,trail,Trendtrade]

// calculate and plot


nowTF = str.tostring(timeframe.period)
[ex,trail,Trendtrade] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), nowTF, CalculateSMT_MultiTF(nowTF,getATRFactor(nowTF)) )

// plot SMT now TF


f2 = ex + (trail - ex) * fib2Level / 100
f3 = ex + (trail - ex) * fib3Level / 100
Fib1 = plot(ShowSmartTrail ?trail:na, 'S/R - SIGNAL', style=plot.style_line,
color=Trendtrade == 1 ? smtColorfib1_up : Trendtrade == -1 ? smtColorfib1_down :
na,linewidth = 1,editable = false)
Fib2 = plot(ShowSmartTrail ?f2:na, 'Ranger B', color=smtColorfib2)
Fib3 = plot(ShowSmartTrail ?f3:na, 'Ranger C',color=smtColorfib3)
fill(Fib1, Fib3, color = trail > f3 ? color.rgb(202, 50, 39, 63): color.rgb(67,
160, 72, 72))
fill(Fib3, Fib2, color = trail > f3 ? color.rgb(202, 50, 39, 87): color.rgb(67,
160, 72, 87))

smartTrailTiming = ((high >= trail) and (low <= trail)) or ((high >= f3) and (low
<= f3)) or ((high >= f2) and (low <= f2))
alertcondition(smartTrailTiming, title="Smart trail timing", message="Smart trail
timing")
//plot SMT HTF 1
[exHTF,trailHTF,TrendtradeHTF] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), multiTF1, CalculateSMT_MultiTF(multiTF1,getATRFactor(multiTF1)))
f2HTF = exHTF + (trailHTF - exHTF) * fib2Level / 100
f3HTF = exHTF + (trailHTF - exHTF) * fib3Level / 100
Fib1HTF = plot(ShowSmartTrailTF1 ?trailHTF:na, 'S/R - SIGNAL',
style=plot.style_line, color=TrendtradeHTF == 1 ? smtColorfib1_up : TrendtradeHTF
== -1 ? smtColorfib1_down : na,linewidth = 1,editable = false)
Fib2HTF = plot(ShowSmartTrailTF1 ?f2HTF:na, 'Ranger B', color=smtColorfib2)
Fib3HTF = plot(ShowSmartTrailTF1 ?f3HTF:na, 'Ranger C',color=smtColorfib3)
fill(Fib1HTF, Fib3HTF, color = trailHTF > f3HTF ? color.rgb(202, 39, 161, 63):
color.rgb(19, 46, 153, 72),title = 'Backgroud TF 1')
fill(Fib3HTF, Fib2HTF, color = trailHTF > f3HTF ? color.rgb(202, 39, 161, 87):
color.rgb(19, 46, 153, 87),title = 'Backgroud TF 1')

//plot SMT HTF 2

[exHTF2,trailHTF2,TrendtradeHTF2] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), multiTF2, CalculateSMT_MultiTF(multiTF2,getATRFactor(multiTF2)) )
f2HTF2 = exHTF2 + (trailHTF2 - exHTF2) * fib2Level / 100
f3HTF2 = exHTF2 + (trailHTF2 - exHTF2) * fib3Level / 100
Fib1HTF2 = plot(ShowSmartTrailTF2 ?trailHTF2:na, 'S/R - SIGNAL',
style=plot.style_line, color=TrendtradeHTF2 == 1 ? smtColorfib1_up : TrendtradeHTF2
== -1 ? smtColorfib1_down : na,linewidth = 1,editable = false)
Fib2HTF2 = plot(ShowSmartTrailTF2 ?f2HTF2:na, 'Ranger B', color=smtColorfib2)
Fib3HTF2 = plot(ShowSmartTrailTF2 ?f3HTF2:na, 'Ranger C',color=smtColorfib3)
fill(Fib1HTF2, Fib3HTF2, color = trailHTF2 > f3HTF2 ? color.rgb(206, 141, 21, 63):
color.rgb(21, 220, 220, 72),title = 'Backgroud TF 2')
fill(Fib3HTF2, Fib2HTF2, color = trailHTF2 > f3HTF2 ? color.rgb(206, 141, 21, 87):
color.rgb(21, 220, 220, 87),title = 'Backgroud TF 2')

///// SMART TRAIL ADD END


///ema

///ema///
showEMA = input.bool(false, 'EMA 13 50 200 800 ON/OFF', inline = 'overlayLine5',
group = 'ON/OFF')

EMA = "EMA Setting"


len0= input.int(5, minval=1, title="EMA Length", group = EMA)
len1= input.int(13, minval=1, title="EMA Length", group = EMA)
len2 = input.int(50, minval=1, title="EMA Length", group = EMA)
len3 = input.int(200, minval=1, title="EMA Length", group = EMA)
len4 = input.int(800, minval=1, title="EMA Length", group = EMA)
src = close
ema0 = ta.ema(src,len0) //5
ema1 = ta.ema(src,len1) //13
ema2 = ta.ema(src,len2) //50
ema3 = ta.ema (src,len3)//200=
ema4 = ta.ema (src,len4)//800=
plot(showEMA?ema0:na, title="EMA 5", linewidth=1, color = color.rgb(30, 0, 255,
80), display = display.none)
plot(showEMA?ema1:na, title="EMA 13", linewidth=1, color = color.rgb(255, 82, 82,
48))
plot(showEMA?ema2:na, title="EMA 50", linewidth=1, color = color.rgb(25, 207, 207,
50))
plot(showEMA?ema3:na, title="EMA 200", linewidth=1, color = color.rgb(0, 0, 0, 49))
plot(showEMA?ema4:na, title="EMA 800", linewidth=1, color = color.rgb(30, 0, 255,
46), display = display.none)

plot(ta.crossover(ema0,ema1) and showEMA ? ema1 : na,'EMA 5 Crossover EMA


13',#627dcc73,3,plot.style_cross)
plot(ta.crossover(ema1,ema0) and showEMA? ema1 : na,'EMA 5 Crossover EMA
13',#cc626e73,3,plot.style_cross)

//alert

entry_setup = ta.crossover(ema0, ema1)


alertcondition(entry_setup, title="EMA5/13 cross", message="entry time")

ema1350_setup = ta.crossover(ema1, ema2)


alertcondition(ema1350_setup, title="EMA13/50 cross", message="EMA13/50 cross")

ema50200_setup = ta.crossover(ema2, ema3)


alertcondition(ema50200_setup, title="EMA50/200 cross", message="EMA50/200 cross")
//EMA _end

// BB start

BBlength = input.int(20, minval=1)


srcBB = input(close, title="Source")
mult22 = input.float(2, minval=0.001, maxval=50, title="StdDev")
basis22 = ta.sma(srcBB, BBlength)
dev22 = mult22 * ta.stdev(srcBB, BBlength)
upper22 = basis22 + dev22
lower22 = basis22 - dev22
offset = input.int(0, "Offset", minval = -500, maxval = 500)

plot(ShowBB ?basis22:na, "BB Basis", color=#eca0275c, offset = offset)


p11 = plot(ShowBB ?upper22:na, "BB Upper", color=#4a2bfd64, offset = offset)
p22 = plot(ShowBB ?lower22:na, "BB Lower", color=#4a2bfd6c, offset = offset)
fill(p11, p22, title = "BB Background", color=color.rgb(61, 124, 175,
100),display=display.none)
// BB end code

// pivot
///pivot Add Start
ShowPivot = input.bool(false,'Show Pivot', inline = 'overlayLine8',group =
'ON/OFF')
AUTO = "Auto"
DAILY = "Daily"
WEEKLY = "Weekly"
MONTHLY = "Monthly"
QUARTERLY = "Quarterly"
YEARLY = "Yearly"
BIYEARLY = "Biyearly"
TRIYEARLY = "Triyearly"
QUINQUENNIALLY = "Quinquennially"
DECENNIALLY = "Decennially"

TRADITIONAL = "Traditional"
FIBONACCI = "Fibonacci"
WOODIE = "Woodie"
CLASSIC = "Classic"
DEMARK = "DM"
CAMARILLA = "Camarilla"

kind = input.string(title="Type", defval="Traditional", options=[TRADITIONAL,


FIBONACCI, WOODIE, CLASSIC, DEMARK, CAMARILLA] , group = "PIVOT")
pivot_time_frame = input.string(title="Pivots Timeframe", defval=AUTO,
options=[AUTO, DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, BIYEARLY, TRIYEARLY,
QUINQUENNIALLY, DECENNIALLY], group = "PIVOT")
look_back = input.int(title="Number of Pivots Back", defval=15, minval=1,
maxval=5000, group = "PIVOT")
is_daily_based = input.bool(title="Use Daily-based Values", group = "PIVOT",
defval=false, tooltip="When this option is unchecked, Pivot Points will use
intraday data while calculating on intraday charts. If Extended Hours are displayed
on the chart, they will be taken into account during the pivot level calculation.
If intraday OHLC values are different from daily-based values (normal for stocks),
the pivot levels will also differ.")
show_labelsPivot = input.bool(title="Show Labels", defval=true, inline="labels",
group = "PIVOT")
position_labels = input.string("Left", "", options=["Left", "Right"],
inline="labels", group = "PIVOT")

var DEF_COLOR = #FB8C00


var arr_time = array.new_int()
var p = array.new_float()
p_show = input.bool(true, "P ", inline="P", group = "PIVOT")
p_color = input.color(DEF_COLOR, "", inline="P", group = "PIVOT")
var r1 = array.new_float()
var s1 = array.new_float()
s1r1_show = input.bool(true, "S1/R1", inline="S1/R1", group = "PIVOT")
s1r1_color = input.color(DEF_COLOR, "", inline="S1/R1", group = "PIVOT")
var r2 = array.new_float()
var s2 = array.new_float()
// s2r2_show = input.bool(false, "S2/R2", inline="S2/R2")
// s2r2_color = input.color(DEF_COLOR, "", inline="S2/R2")
// var r3 = array.new_float()
// var s3 = array.new_float()

pivotX_open = float(na)
pivotX_open := nz(pivotX_open[1], open)
pivotX_high = float(na)
pivotX_high := nz(pivotX_high[1], high)
pivotX_low = float(na)
pivotX_low := nz(pivotX_low[1], low)
pivotX_prev_open = float(na)
pivotX_prev_open := nz(pivotX_prev_open[1])
pivotX_prev_high = float(na)
pivotX_prev_high := nz(pivotX_prev_high[1])
pivotX_prev_low = float(na)
pivotX_prev_low := nz(pivotX_prev_low[1])
pivotX_prev_close = float(na)
pivotX_prev_close := nz(pivotX_prev_close[1])

get_pivot_resolution() =>
resolution = "M"
if pivot_time_frame == AUTO
if timeframe.isintraday
resolution := timeframe.multiplier <= 15 ? "D" : "W"
else if timeframe.isweekly or timeframe.ismonthly
resolution := "12M"
else if pivot_time_frame == DAILY
resolution := "D"
else if pivot_time_frame == WEEKLY
resolution := "W"
else if pivot_time_frame == MONTHLY
resolution := "M"
else if pivot_time_frame == QUARTERLY
resolution := "3M"
else if pivot_time_frame == YEARLY or pivot_time_frame == BIYEARLY or
pivot_time_frame == TRIYEARLY or pivot_time_frame == QUINQUENNIALLY or
pivot_time_frame == DECENNIALLY
resolution := "12M"
resolution

var lines = array.new_line()


var labelsPivot = array.new_label()
widthpivot = input.int(title="Độ Rộng đường Pivot", defval=2, minval=1,
maxval=5000)

draw_line(i, pivot, col) =>


if array.size(arr_time) > 1
array.push(lines, line.new(array.get(arr_time, i), array.get(pivot, i),
array.get(arr_time, i + 1), array.get(pivot, i), color=col,
xloc=xloc.bar_time,width = widthpivot))

draw_label(i, y, txt, txt_color) =>


if show_labelsPivot
offset = ' '
labels_align_str_left= position_labels == "Left" ? txt + offset : offset +
txt
x = position_labels == "Left" ? array.get(arr_time, i) :
array.get(arr_time, i + 1)
array.push(labelsPivot, label.new(x = x, y=y, text=labels_align_str_left,
textcolor=txt_color, style=label.style_label_center, color=#00000000,
xloc=xloc.bar_time))

traditional() =>
pivotX_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_prev_close) / 3
array.push(p, pivotX_Median)
array.push(r1, pivotX_Median * 2 - pivotX_prev_low)
array.push(s1, pivotX_Median * 2 - pivotX_prev_high)
array.push(r2, pivotX_Median + 1 * (pivotX_prev_high - pivotX_prev_low))
array.push(s2, pivotX_Median - 1 * (pivotX_prev_high - pivotX_prev_low))

fibonacci() =>
pivotX_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_prev_close) / 3
pivot_range = pivotX_prev_high - pivotX_prev_low
array.push(p, pivotX_Median)
array.push(r1, pivotX_Median + 0.382 * pivot_range)
array.push(s1, pivotX_Median - 0.382 * pivot_range)
array.push(r2, pivotX_Median + 0.618 * pivot_range)
array.push(s2, pivotX_Median - 0.618 * pivot_range)

woodie() =>
pivotX_Woodie_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_open * 2)/4
pivot_range = pivotX_prev_high - pivotX_prev_low
array.push(p, pivotX_Woodie_Median)
array.push(r1, pivotX_Woodie_Median * 2 - pivotX_prev_low)
array.push(s1, pivotX_Woodie_Median * 2 - pivotX_prev_high)
array.push(r2, pivotX_Woodie_Median + 1 * pivot_range)
array.push(s2, pivotX_Woodie_Median - 1 * pivot_range)

pivot_point_r3 = pivotX_prev_high + 2 * (pivotX_Woodie_Median -


pivotX_prev_low)
pivot_point_s3 = pivotX_prev_low - 2 * (pivotX_prev_high -
pivotX_Woodie_Median)

classic() =>
pivotX_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_prev_close)/3
pivot_range = pivotX_prev_high - pivotX_prev_low
array.push(p, pivotX_Median)
array.push(r1, pivotX_Median * 2 - pivotX_prev_low)
array.push(s1, pivotX_Median * 2 - pivotX_prev_high)
array.push(r2, pivotX_Median + 1 * pivot_range)
array.push(s2, pivotX_Median - 1 * pivot_range)

demark() =>
pivotX_Demark_X = pivotX_prev_high + pivotX_prev_low * 2 + pivotX_prev_close
if pivotX_prev_close == pivotX_prev_open
pivotX_Demark_X := pivotX_prev_high + pivotX_prev_low + pivotX_prev_close *
2
if pivotX_prev_close > pivotX_prev_open
pivotX_Demark_X := pivotX_prev_high * 2 + pivotX_prev_low +
pivotX_prev_close
array.push(p, pivotX_Demark_X / 4)
array.push(r1, pivotX_Demark_X / 2 - pivotX_prev_low)
array.push(s1, pivotX_Demark_X / 2 - pivotX_prev_high)

camarilla() =>
pivotX_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_prev_close) / 3
pivot_range = pivotX_prev_high - pivotX_prev_low
array.push(p, pivotX_Median)
array.push(r1, pivotX_prev_close + pivot_range * 1.1 / 12.0)
array.push(s1, pivotX_prev_close - pivot_range * 1.1 / 12.0)
array.push(r2, pivotX_prev_close + pivot_range * 1.1 / 6.0)
array.push(s2, pivotX_prev_close - pivot_range * 1.1 / 6.0)

resolution = get_pivot_resolution()

[sec_open, sec_high, sec_low, sec_close] = request.security(syminfo.tickerid,


resolution, [open, high, low, close], lookahead = barmerge.lookahead_on)
sec_open_gaps_on = request.security(syminfo.tickerid, resolution, open, gaps =
barmerge.gaps_on, lookahead = barmerge.lookahead_on)

custom_years_divisor = switch pivot_time_frame


BIYEARLY => 2
TRIYEARLY => 3
QUINQUENNIALLY => 5
DECENNIALLY => 10
=> -1

is_change_years = false
if custom_years_divisor > 0 and ta.change(time(resolution))
is_change_years := year % custom_years_divisor == 0
var is_change = false
var uses_current_bar = timeframe.isintraday and kind == WOODIE
var change_time = int(na)
is_time_change = (ta.change(time(resolution)) and custom_years_divisor == -1) or
is_change_years
if is_time_change
change_time := time

if (not uses_current_bar and is_time_change) or (uses_current_bar and not


na(sec_open_gaps_on))
if is_daily_based and custom_years_divisor == -1
pivotX_prev_open := sec_open[1]
pivotX_prev_high := sec_high[1]
pivotX_prev_low := sec_low[1]
pivotX_prev_close := sec_close[1]
pivotX_open := sec_open
pivotX_high := sec_high
pivotX_low := sec_low
else
pivotX_prev_high := pivotX_high
pivotX_prev_low := pivotX_low
pivotX_prev_open := pivotX_open
pivotX_open := open
pivotX_high := high
pivotX_low := low
pivotX_prev_close := close[1]

if barstate.islast and not is_change and array.size(arr_time) > 0


array.set(arr_time, array.size(arr_time) - 1, change_time)
else
array.push(arr_time, change_time)

if kind == TRADITIONAL
traditional()
else if kind == FIBONACCI
fibonacci()
else if kind == WOODIE
woodie()
else if kind == CLASSIC
classic()
else if kind == DEMARK
demark()
else if kind == CAMARILLA
camarilla()

if array.size(arr_time) > look_back


if array.size(arr_time) > 0
array.shift(arr_time)
if array.size(p) > 0 and p_show
array.shift(p)
if array.size(r1) > 0 and s1r1_show
array.shift(r1)
if array.size(s1) > 0 and s1r1_show
array.shift(s1)
is_change := true
else
if is_daily_based and custom_years_divisor == -1
pivotX_high := math.max(pivotX_high, sec_high)
pivotX_low := math.min(pivotX_low, sec_low)
else
pivotX_high := math.max(pivotX_high, high)
pivotX_low := math.min(pivotX_low, low)

if barstate.islast and array.size(arr_time) > 0 and is_change and ShowPivot


is_change := false
if array.size(arr_time) > 2 and custom_years_divisor > 0
last_pivot_time = array.get(arr_time, array.size(arr_time) - 1)
prev_pivot_time = array.get(arr_time, array.size(arr_time) - 2)
estimate_pivot_time = last_pivot_time - prev_pivot_time
array.push(arr_time, last_pivot_time + estimate_pivot_time)
else
array.push(arr_time, time_close(resolution))

for i = 0 to array.size(lines) - 1
if array.size(lines) > 0
line.delete(array.shift(lines))
if array.size(lines) > 0
label.delete(array.shift(labelsPivot))

for i = 0 to array.size(arr_time) - 2
if array.size(p) > 0 and p_show
draw_line(i, p, p_color)
draw_label(i, array.get(p, i), "P", p_color)
if array.size(r1) > 0 and s1r1_show
draw_line(i, r1, s1r1_color)
draw_label(i, array.get(r1, i), "R1", s1r1_color)
if array.size(s1) > 0 and s1r1_show
draw_line(i, s1, s1r1_color)
draw_label(i, array.get(s1, i), "S1", s1r1_color)

// session code start

//Session C
showSession = input(false, 'Show Session Asian', group = 'ON/OFF', inline =
'overlayLine5')

show_sesc = input(true, '', inline = 'sesc', group = 'Session C')


sesc_txt = input('Tokyo', '', inline = 'sesc', group = 'Session C')
sesc_ses = input.session('0100-0715', '', inline = 'sesc', group = 'Session C')
sesc_css = input.color(#e91e63, '', inline = 'sesc', group = 'Session C')

sesc_range = input(true, 'Range', inline = 'sesc_overlays', group = 'Session C')


sesc_maxmin = input(false, 'Max/Min', inline = 'sesc_overlays', group = 'Session
C')

//Timezones
tz_incr = input.int(0, 'UTC (+/-)', group = 'Timezone', group = "EntryTime")
use_exchange = input(false, 'Use Exchange Timezone', group = 'EntryTime')

//Ranges Options
bg_transp = input.float(90, 'Range Area Transparency', group = 'Ranges Settings')
show_outline = input(false, 'Range Outline', group = 'Ranges Settings')
show_txt = input(false, 'Range Label', group = 'Ranges Settings')

//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index

//Get session average


get_avg(session)=>
var len = 1
var float csma = na
var float sma = na

if session > session[1]


len := 1
csma := close

if session and session == session[1]


len += 1
csma += close
sma := csma / len

sma

isValidResolution() => timeframe.isdwm == true or timeframe.period == "120" or


timeframe.period == "240" or timeframe.period == "180" or timeframe.period == "360"
? 0 : 1
isBelowHourValidResolution() => timeframe.isdwm == true or timeframe.period ==
"120" or timeframe.period == "240" or timeframe.period == "180" or timeframe.period
== "360" ? 0 : 1

//Get trendline coordinates


get_linreg(session)=>
var len = 1
var float cwma = na
var float csma = na
var float csma2 = na

var float y1 = na
var float y2 = na
var float stdev = na
var float r2 = na

if session > session[1]


len := 1
cwma := close
csma := close
csma2 := close * close

if session and session == session[1]


len += 1
csma += close
csma2 += close * close
cwma += close * len

sma = csma / len


wma = cwma / (len * (len + 1) / 2)

cov = (wma - sma) * (len+1)/2


stdev := math.sqrt(csma2 / len - sma * sma)
r2 := cov / (stdev * (math.sqrt(len*len - 1) / (2 * math.sqrt(3))))

y1 := 4 * sma - 3 * wma
y2 := 3 * wma - 2 * sma

[y1 , y2, stdev, r2]

//Session Vwap
get_vwap(session) =>
var float num = na
var float den = na

if session > session[1]


num := close * volume
den := volume

else if session and session == session[1]


num += close * volume
den += volume
else
num := na

[num, den]

//Set line
set_line(session, y1, y2, session_css)=>
var line tl = na

if session > session[1]


tl := line.new(n, close, n, close, color = session_css)

if session and session == session[1]


line.set_y1(tl, y1)
line.set_xy2(tl, n, y2)

//Set session range


get_range(session, session_name, session_css)=>
var t = 0
var max = high
var min = low
var box bx = na
var label lbl = na

if session > session[1]


t := time
max := high
min := low

bx := box.new(n, max, n, min


, bgcolor = color.new(session_css, bg_transp)
, border_color = show_outline ? session_css : na
, border_style = line.style_dotted)

if show_txt
lbl := label.new(t, max, session_name
, xloc = xloc.bar_time
, textcolor = session_css
, style = label.style_label_down
, color = color.new(color.white, 100)
, size = size.tiny)

if session and session == session[1]


max := math.max(high, max)
min := math.min(low, min)

box.set_top(bx, max)
box.set_rightbottom(bx, n, min)

if show_txt
label.set_xy(lbl, int(math.avg(t, time)), max)

[session ? na : max, session ? na : min]

//-----------------------------------------------------------------------------}
//Sessions
//-----------------------------------------------------------------------------{
tf = timeframe.period

var tz = use_exchange ? syminfo.timezone :


str.format('UTC{0}{1}', tz_incr >= 0 ? '+' : '-', math.abs(tz_incr))

is_sesc = math.sign(nz(time(tf, sesc_ses, tz)))

//-----------------------------------------------------------------------------}
//Overlays
//-----------------------------------------------------------------------------{

var float max_sesc = na


var float min_sesc = na

//Ranges
if show_sesc and sesc_range and showSession
[max, min] = get_range(is_sesc, sesc_txt, sesc_css)
max_sesc := max
min_sesc := min

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Plot max/min
plot(sesc_maxmin ? max_sesc : na, 'Session C Maximum', sesc_css, 1,
plot.style_linebr)
plot(sesc_maxmin ? min_sesc : na, 'Session C Minimum', sesc_css, 1,
plot.style_linebr)

/// Session ADD END

// Import high low daily ADD START


showYHYL = input.bool(false, 'Show YH/YL ON/', inline = 'overlayLine7', group =
'ON/OFF')

var DAILY_LINE_STYLE = line.style_dashed


var DAILY_LINE_WITDH = 1
var WEEKLY_LINE_STYLE = line.style_dashed
var WEEKLY_LINE_WIDTH = 1
var MONTHLY_LINE_STYLE = line.style_dashed
var MONTHLY_LINE_WIDTH = 1

//--------------------------------------------------------------------
// Inputs
//--------------------------------------------------------------------

g_indicator = "Highs & Lows"


g_style = "Style"
t_heads = "Extends previous highs and lows in the future."
t_gradient = "Show a color gradient that highlights the recency of
highs and lows."

var i_isDailyEnabled = input (true, "Daily",


inline="Daily", group=g_indicator)
var i_dailyColor = input (color.green, "",
inline="Daily", group=g_indicator)
var i_dailyLookback = input.int (1, "", 1,
inline="Daily", group=g_indicator)
var i_isWeeklyEnabled = input (false, "Weekly",
inline="Weekly", group=g_indicator)
var i_weeklyColor = input (color.orange, "",
inline="Weekly", group=g_indicator)
var i_weeklyLookback = input.int (1, "", 1,
inline="Weekly", group=g_indicator)
var i_isMonthlyEnabled = input (false, "Monthly",
inline="Monthly", group=g_indicator)
var i_monthlyColor = input (color.red, "",
inline="Monthly", group=g_indicator)
var i_monthlyLookback = input.int (1, "", 1,
inline="Monthly", group=g_indicator)
var i_areHeadsEnabled = input (false, "Show Projections", t_heads,
inline="Head", group=g_style)
var i_rightOffset = input.int (20, "", 1,
inline="Head", group=g_style)
var i_hasGradient = input (false, "Show Gradient",
t_gradient, group=g_style)

//--------------------------------------------------------------------
// Variables declarations
//--------------------------------------------------------------------

var a_lastHighs = array.new_float(3)


var a_lastLows = array.new_float(3)
var canShowDaily = i_isDailyEnabled and timeframe.isintraday
var canShowWeekly = i_isWeeklyEnabled and
(timeframe.isintraday or timeframe.isdaily)
var canShowMonthly = i_isMonthlyEnabled and not
timeframe.ismonthly

[dailyTime, dailyHigh, dailyLow, isLastDaily] =


request.security(syminfo.tickerid, 'D', [time, high, low, barstate.islast],
lookahead=barmerge.lookahead_on)
[weeklyTime, weeklyHigh, weeklyLow, isLastWeekly] =
request.security(syminfo.tickerid, 'W', [time, high, low, barstate.islast],
lookahead=barmerge.lookahead_on)
[monthlyTime, monthlyHigh, monthlyLow, isLastMonthly] =
request.security(syminfo.tickerid, 'M', [time, high, low, barstate.islast],
lookahead=barmerge.lookahead_on)

hasDailyTimeChanged = dailyTime != dailyTime[1]


hasWeekklyTimeChanged = weeklyTime != weeklyTime[1]
hasMonthlyTimeChanged = monthlyTime != monthlyTime[1]
//--------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------

f_getRightBarIndex() => bar_index + i_rightOffset

f_draw(bool _isNew, float _h, float _l, int _lookback, color _color, string _style,
int _width) =>
var line _high = na
var line _low = na
var _highs = array.new_line()
var _lows = array.new_line()
_end = i_areHeadsEnabled ? f_getRightBarIndex() : bar_index

if _isNew
line.set_x2(_high, _end)
line.set_x2(_low, _end)

if i_hasGradient
_size = array.size(_highs)
if _size > 1
for i = 0 to _size - 1
_c = color.from_gradient(i, 0, _size - 1, color.new(_color,
100), color.new(_color, 0))
line.set_color(array.get(_highs, i), _c)
line.set_color(array.get(_lows, i), _c)

_high := line.new(bar_index, _h, bar_index, _h, color=_color, style=_style,


width=_width)
_low := line.new(bar_index, _l, bar_index, _l, color=_color, style=_style,
width=_width)
array.push(_highs, _high)
array.push(_lows, _low)

if array.size(_highs) > _lookback + 1


line.delete(array.shift(_highs))
line.delete(array.shift(_lows))

if i_areHeadsEnabled and barstate.islast and array.size(_highs) > 1


// Avoid updating the last/current high and low
for i = 0 to array.size(_highs) - 2
line.set_x2(array.get(_highs, i), f_getRightBarIndex())
line.set_x2(array.get(_lows, i), f_getRightBarIndex())

//--------------------------------------------------------------------
// Logic
//--------------------------------------------------------------------

if canShowDaily and hasDailyTimeChanged and not isLastDaily


array.set(a_lastHighs, 0, dailyHigh)
array.set(a_lastLows, 0, dailyLow)

if canShowWeekly and hasWeekklyTimeChanged and not isLastWeekly


array.set(a_lastHighs, 1, weeklyHigh)
array.set(a_lastLows, 1, weeklyLow)

if canShowMonthly and hasMonthlyTimeChanged and not isLastMonthly


array.set(a_lastHighs, 2, monthlyHigh)
array.set(a_lastLows, 2, monthlyLow)
//--------------------------------------------------------------------
// Plotting & styling
//--------------------------------------------------------------------

if canShowMonthly and showYHYL


f_draw(hasMonthlyTimeChanged, monthlyHigh, monthlyLow, i_monthlyLookback,
i_monthlyColor, MONTHLY_LINE_STYLE, MONTHLY_LINE_WIDTH)

if canShowWeekly and showYHYL


f_draw(hasWeekklyTimeChanged, weeklyHigh, weeklyLow, i_weeklyLookback,
i_weeklyColor, WEEKLY_LINE_STYLE, WEEKLY_LINE_WIDTH)

if canShowDaily and showYHYL


f_draw(hasDailyTimeChanged, dailyHigh, dailyLow, i_dailyLookback, i_dailyColor,
DAILY_LINE_STYLE, DAILY_LINE_WITDH)

// Plot invisible highs and lows for displaying their last values in `status line`,
`scale`, `data window` as well for providing defaults alert conditions

plot(array.get(a_lastHighs, 0), "DH", color.new(i_dailyColor, 100),


editable=false)
plot(array.get(a_lastLows, 0), "DL", color.new(i_dailyColor, 100),
editable=false)
plot(array.get(a_lastHighs, 1), "WH", color.new(i_weeklyColor, 100),
editable=false)
plot(array.get(a_lastLows, 1), "WL", color.new(i_weeklyColor, 100),
editable=false)
plot(array.get(a_lastHighs, 2), "MH", color.new(i_monthlyColor, 100),
editable=false)
plot(array.get(a_lastLows, 2), "ML", color.new(i_monthlyColor, 100),
editable=false)

// Import high low daily ADD END

swing_length = input.int(10, title = 'Swing High/Low Length', group = "👉 SUPPLY AND
DEMAND", minval = 1, maxval = 50)
zigzag_color = input.color(color.new(#000000,0), title = 'Zig Zag', group = 'Visual
Settings', inline = '9')
Zigzag = input.bool(false, ' Show Zigzag ON/OFF', inline = 'overlayLine7', group =
'ON/OFF')
///////////////////////////////////////// ZIGZAG HIGH
LOW //////////////////////////

// 0. Inputs
// 1. Types
// 2. Switches
// 3. Variables and arrays
// 4. Custom Functions
// 5. Execution
// 6. Constructs

//#region ———————————————————— 0. Inputs


K0 = 'Zigzag values\nDefault : 14\nMin : 2\nMax : 50'
K1 = 'Short\nExamKle : L or LL\nLong\nExamKle : Low or Lower Low'
K2 = 'Constrast : Constrast color of chart background\nCustom : Input color\nNone :
Color follow Trend Color'
K3 = 'Small font size recommended for mobile app or multiKle layout'
K4 = 'Default\nStyle : Solid\nWidth : 4'
length1 = input.int( 21, 'Trend Speed', minval = 2, maxval = 50,
tooltip = K0,group = " ZIGZAG HIGH - LOW")
colorUp = input.color(color.rgb(187, 194, 190),'Trend Color', inline = '0')
colorDn = input.color( color.rgb(196, 187, 187), '', inline = '0')
showLabel = input.bool( true, 'Label', group = 'Show / hide',
inline = '1')
showLine = input.bool( true, 'Line', group = 'Show / hide',
inline = '1')
disKlayLabel = input.string( 'HHLL', 'Text', group = 'Label', inline =
'2', options = ['HHLL', 'HL'])
nameHL = input.string( 'Short', '', group = 'Label', inline =
'2', options = ['Short', 'Long'], tooltip = K1)
colorLabel = input.string( 'Trend', 'Color', group = 'Label', inline =
'3', options = ['Contrast', 'Custom', 'Trend'])
customLabel = input.color(color.blue, '', group = 'Label', inline = '3',
tooltip = K2)
sizeLabel = input.string( 'normal', 'Size', group = 'Label', inline =
'4', options = ['tiny', 'small', 'normal', 'large', 'huge'], tooltip = K3)
lineType = input.string( 'solid', 'DisKlay', group = 'Line', inline =
'5', options = ['dash', 'dot', 'solid', 'arrow right', 'arrow left'])
width = input.int( 1, '', group = 'Line', inline =
'5', minval = 1, maxval = 4, tooltip = K4)
colorLine = input.string( 'Trend', 'Color', group = 'Line', inline =
'6', options = ['Contrast', 'Custom', 'Trend'])
customLine = input.color(color.blue, '', group = 'Line', inline = '6',
tooltip = K2)
//#endregion

//#region ———————————————————— 1. Types


// @type Used for label
// @field Hi Float value of high
// @field Lo Float value of low
type HL
string Hi = na
string Lo = na

// @type Used for point especially for array


// @field x int value for bar_index
// @field y float value for price
// @field sty label style
// @field col color for text label
// @field str high or low string
type point
int x = na
float y = na
string sty = na
color col = na
string str = na

// @type Used for initial setup


// @field hi high value
// @field lo low value
// @field colorHi color for high value
// @field colorLo color for low value
// @field strHi string for high value
// @field strLo string for low value
type startUp
float hi = na
float lo = na
color colorHi = na
color colorLo = na
string strHi = na
string strLo = na
//#endregion

//#region ———————————————————— 2. Switches


[H1, L1] = switch nameHL
'Short' => [ 'H', 'L']
'Long' => ['HIGH', 'LOW']
[Hi, Lo] = switch nameHL
'Short' => [ 'H', 'L']
'Long' => ['HIGHER\n', 'LOWER\n']
switchLine = switch lineType
'dash' => line.style_dashed
'dot' => line.style_dotted
'solid' => line.style_solid
'arrow right' => line.style_arrow_right
'arrow left' => line.style_arrow_left
switchLabelColor = switch colorLabel
'Contrast' => chart.fg_color
'Custom' => customLabel
switchLineColor = switch colorLine
'Contrast' => chart.fg_color
'Custom' => customLine
//#endregion

//#region ———————————————————— 3. Variables and arrays


float Kh = na, Kh := ta.highestbars(high, length1 ) == 0 ? high : na
float Kl = na, Kl := ta.lowestbars( low, length1 ) == 0 ? low : na
var dir = 0, dir := Kh and na(Kl) ? 1 : Kl and na(Kh) ? -1 : dir
var zigzag = array.new<point>(0)
oldzigzag = zigzag.copy()
dirchanged = ta.change(dir)
hiLo = HL.new(Hi, Lo)
varSetup = startUp.new(Kh, Kl, colorUp, colorDn, H1,L1)
//#endregion

//#region ———————————————————— 4. Custom Functions


// @function variable for point
// @param setup type containing ternary conditional operator
// @returns newPoint to be used later in initialize
method dirVariables(startUp setup = na) =>
var point newPoint = na
x = bar_index
y = dir == 1 ? setup.hi : setup.lo
sty = dir == 1 ? label.style_label_down : label.style_label_up
col = dir == 1 ? setup.colorHi : setup.colorLo
str = dir == 1 ? setup.strHi : setup.strLo
newPoint := point.new(x, y, sty, col, str)
newPoint

// @function initialize zigzag array


// @param setup type containing ternary conditional operator
// @param maxSize maximum array size
// @returns zigzag array after cleanup
method initialize(point[] zigzag = na, startUp setup = na, int maxSize = 10)=>
newPoint = setup.dirVariables()
zigzag.unshift(newPoint)
if zigzag.size() > maxSize
zigzag.pop()

// @function update zigzag array


// @param setup type containing ternary conditional operator
// @param maxSize maximum array size
// @param dir direction value
// @returns zigzag array after cleanup
method update(point[] zigzag = na, startUp setup = na, maxSize = 10, int dir =
na)=>
if array.size(zigzag) == 0
zigzag.initialize(setup, maxSize)
else
newPoint = setup.dirVariables()
dirOver = dir == 1 and newPoint.y > zigzag.get(0).y
dirLess = dir == -1 and newPoint.y < zigzag.get(0).y
if dirOver or dirLess
zigzag.set(0, newPoint)
point.new(na, na, na, na, na)

// @function compare zigzag


// @param zigzag original array
// @param oldzigzag copied array
// @returns boolOr Or statement
// @returns boolAnd And statement
method boolPoint(point[] zigzag = na, point[] oldzigzag = na, int offset = 0) =>
boolOr = zigzag.get(offset + 0).x != oldzigzag.get(offset + 0).x or
zigzag.get(offset + 0).y != oldzigzag.get(offset + 0).y
boolAnd = zigzag.get(offset + 1).x == oldzigzag.get(offset + 1).x and
zigzag.get(offset + 1).y == oldzigzag.get(offset + 1).y
[boolOr, boolAnd]

// @function create label based on zigzag array


// @param zigzag original array
// @param size font size
// @param offset default value zero
// @returns new label
method createLabel(point[] zigzag = na, string size = na, int offset = 0) =>
label.new( x = int(zigzag.get(offset + 0).x),
y = zigzag.get(offset + 0).y,
text = zigzag.get(offset + 0).str,
xloc = xloc.bar_index,
color = color.new(color.blue, 100),
style = zigzag.get(offset + 0).sty,
textcolor = zigzag.get(offset + 0).col,
size = size,
tooltip = zigzag.get(offset + 0).str + '\n' +
str.tostring(zigzag.get(offset + 0).y))

// @function create line based on zigzag array


// @param zigzag original array
// @param width line thickness
// @param style line style
// @param offset default value zero
// @returns new line
method createLine(point[] zigzag = na, int width = na, string style = na, int
offset = 0) =>
line.new(x1 = int(zigzag.get(offset + 1).x),
y1 = zigzag.get(offset + 1).y,
x2 = int(zigzag.get(offset + 0).x),
y2 = zigzag.get(offset + 0).y,
xloc = xloc.bar_index,
color = zigzag.get(offset + 0).col,
style = style,
width = width)

// @function create line based on zigzag array


// @param zigzag original array
// @param hiLo switch value
// @param offset default value zero
// @returns ternary conditional of hiLo
method compareHL(point[] zigzag = na, HL hiLo = na, int offset = 0) =>
dir == 1 ? zigzag.get(offset + 0).y > zigzag.get(offset + 2).y ? hiLo.Hi :
hiLo.Lo :
zigzag.get(offset + 0).y < zigzag.get(offset + 2).y ? hiLo.Lo :
hiLo.Hi

// @function set text and tooltip for label


// @param this original array
// @param str string value for text
// @param tip string value for tooltip
method textTip(label this = na, string str = na, string tip = na) =>
this.set_text( str)
this.set_tooltip(tip)
//#endregion

//#region ———————————————————— 5. Execution


if Kh or Kl
if dirchanged
zigzag.initialize( varSetup, 4)
else
zigzag.update(varSetup, 4, dir)
//#endregion

//#region ———————————————————— 6. Constructs


if zigzag.size() >= 3
var line dirLine = na
var label dirLabel = na
var string dirString = na
[boolOr, boolAnd] = zigzag.boolPoint(oldzigzag)
if boolOr
if boolAnd
dirLine.delete()
dirLabel.delete()
if Zigzag ?showLabel :na
if disKlayLabel == 'HL' or disKlayLabel == 'HHLL'
dirLabel := zigzag.createLabel(sizeLabel)
if disKlayLabel == 'HHLL' and zigzag.size() >= 4
dirString := zigzag.compareHL(hiLo)
dirLabel.textTip(dirString + zigzag.get(0).str, dirString +
zigzag.get(0).str + '\n' + str.tostring(zigzag.get(0).y))
if colorLabel != 'Trend'
dirLabel.set_textcolor(switchLabelColor)
if Zigzag ? showLine :na
dirLine := zigzag.createLine(width, switchLine)
if colorLine != 'Trend'
dirLine.set_color(switchLineColor)
// //#endregion
///////////////////////////////////////////////////////////////////////
/// ichimoku add start
ShowIchi = input.bool(false, 'ICHIMOKU ON/OFF', group = 'ON/OFF')
conversionPeriods = input.int(9, minval=1, title="Conversion Line Length", group =
'ichimoku')
basePeriods = input.int(26, minval=1, title="Base Line Length", group = 'ichimoku')
laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length", group
= 'ichimoku')
displacement = input.int(26, minval=1, title="Lagging Span", group = 'ichimoku',
group = 'ichimoku')
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
// plot(ShowIchi?conversionLine:na, color=#2962FF, title="Conversion Line", display
= display.none)
// plot(ShowIchi?baseLine:na, color=#B71C1C, title="Base Line", display =
display.none)
//plot(ShowIchi?close:na, offset = -displacement + 1, color=#43A047, title="Lagging
Span")
p1 = plot(ShowIchi?leadLine1:na, offset = displacement - 1, color=#A5D6A7,
title="Leading Span A")
p2 = plot(ShowIchi?leadLine2:na, offset = displacement - 1, color=#EF9A9A,
title="Leading Span B")
plot(leadLine1 > leadLine2? leadLine1 : leadLine2, offset = displacement - 1, title
= "Kumo Cloud Upper Line", display = display.none)
plot(leadLine1 < leadLine2 ? leadLine1 : leadLine2, offset = displacement - 1,
title = "Kumo Cloud Lower Line", display = display.none)
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 72, 72) :
color.rgb(202, 50, 39, 63))

/// Ichimoku Add END

////////////////////////////
////////////////// REV ZONES BB ////////////////////
reversalZone = input.bool(false, "Reversal Zones ", inline =
'overlayLine8', group = 'ON/OFF', tooltip = 'Hiệu quả nhất khi sideway')

length = input.int(80, minval=1,title = "BAND",group = " Reversal Band")


maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"],group = " Reversal Band")
srcb = input(close, title="Source",group = " Reversal Band")
multb = input.float(1.618, minval=0.001, maxval=50, title="StdDev",group = "
Reversal Band")
Smoothing1 = input(5, 'Smoothing')
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

basis = ma(srcb, length, maType)


dev = multb * ta.stdev(srcb, length)
upper = basis + dev
lower = basis - dev
offset11 = input.int(0, "Offset", minval = -500, maxval = 500)
//plot(basis, "Basis", color=#FF6D00, offset = offset11,display = display.none,
editable = false)
A1 = plot(reversalZone?(ta.sma(upper, Smoothing1)):na, "Upper", color=#2962FF,
offset = offset11,display = display.none, editable = false)
B1 = plot(reversalZone?(ta.sma(lower, Smoothing1)):na, "Lower", color=#2962FF,
offset = offset11,display = display.none, editable = false)

mult1 = input.float(2.618, minval=0.001, maxval=50, title="StdDev")

basis1 = ma(srcb, length, maType)


dev1 = mult1 * ta.stdev(srcb, length)
upper1 = basis1 + dev1
lower1 = basis1 - dev1
offset12 = input.int(0, "Offset", minval = -500, maxval = 500)
//plot(basis1, "Basis", color=#FF6D00, offset = offset12,display = display.none,
editable = false)
A11 = plot(reversalZone?(ta.sma(upper1, Smoothing1)) : na, "Upper", color=#2962FF,
offset = offset12, editable = false)
B11 = plot(reversalZone?(ta.sma(lower1, Smoothing1)) : na, "Lower", color=#2962FF,
offset = offset12, editable = false)

fill(A1, A11, color = #a5a9ab86, transp = 60, editable = false)


fill(B1, B11, color = #a5a9ab86, transp = 60, editable = false)

////////////////// REV ZONES BB END ////////////////////

You might also like