Comert Ultimate KY-ToolBox by Hassonya

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 16

//Twitter Adres: @Hassonya

//@version=4
study(title="Comert Ultimate KY-ToolBox by Hassonya", shorttitle="ComertTOOLBOX
V2", overlay=true, max_lines_count=500, max_labels_count=500, precision=2)

//Source
src = input(close, title="Source")
trade = input(defval="Stock", title="Which Market: ", options=["Stock", "Crypto"],
type=input.string)

//Moving Averages
////////////////////////
moving_ok = input(title = "═══════════════ Moving Averages Settings ", defval=true,
type=input.bool)

//Moving Averages Period


res = input(title="Resolution", type=input.resolution, defval="")

////////////////////////////////////////////////////// MOVAV
//moving average lengths and independent moving average types
//MA1 settings
ma1_active = input(true, title="MA1", inline="MA1")
ma1_length = input(21, title="Length", inline="MA1")
MAType_1 = input(defval="EMA", title="Type", options=["SMA", "EMA", "WMA", "VWMA",
"SMMA", "DEMA", "TEMA", "HullMA", "EHMA", "ETMA", "ZEMA", "TMA", "SSMA", "STMA",
"ALMA"], type=input.string, inline="MA1")

//MA2 settings
ma2_active = input(true, title="MA2", inline="MA2")
ma2_length = input(55, title="Length", inline="MA2")
MAType_2 = input(defval="EMA", title="Type", options=["SMA", "EMA", "WMA", "VWMA",
"SMMA", "DEMA", "TEMA", "HullMA", "EHMA", "ETMA", "ZEMA", "TMA", "SSMA", "STMA",
"ALMA"], type=input.string, inline="MA2")

//MA3 settings
ma3_active = input(true, title="MA3", inline="MA3")
ma3_length = input(89, title="Length", inline="MA3")
MAType_3 = input(defval="EMA", title="Type", options=["SMA", "EMA", "WMA", "VWMA",
"SMMA", "DEMA", "TEMA", "HullMA", "EHMA", "ETMA", "ZEMA", "TMA", "SSMA", "STMA",
"ALMA"], type=input.string, inline="MA3")

//MA4 settings
ma4_active = input(true, title="MA4", inline="MA4")
ma4_length = input(200, title="Length", inline="MA4")
MAType_4 = input(defval="EMA", title="Type", options=["SMA", "EMA", "WMA", "VWMA",
"SMMA", "DEMA", "TEMA", "HullMA", "EHMA", "ETMA", "ZEMA", "TMA", "SSMA", "STMA",
"ALMA"], type=input.string, inline="MA4")

//MA5 settings
ma5_active = input(true, title="MA5", inline="MA5")
ma5_length = input(233, title="Length", inline="MA5")
MAType_5 = input(defval="EMA", title="Type", options=["SMA", "EMA", "WMA", "VWMA",
"SMMA", "DEMA", "TEMA", "HullMA", "EHMA", "ETMA", "ZEMA", "TMA", "SSMA", "STMA",
"ALMA"], type=input.string, inline="MA5")

//gamma değeri
gamma = 0.55

//ssma
variant_supersmoother(src,MovAv) =>
a1 = exp(-1.414*3.14159 / MovAv)
b1 = 2*a1*cos(1.414*3.14159 / MovAv)
c2 = b1
c3 = (-a1)*a1
c1 = 1 - c2 - c3
v9 = 0.0
v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
v9

//smma
variant_smoothed(src,MovAv) =>
_sma = sma(src, MovAv)
v5 = 0.0
v5 := na(v5[1]) ? _sma : (v5[1] * (MovAv - 1) + src) / MovAv
v5

//zema
variant_zerolagema(src,MovAv) =>
ema1 = ema(src, MovAv)
ema2 = ema(ema1, MovAv)
v10 = ema1+(ema1-ema2)
v10

//dema
variant_doubleema(src,MovAv) =>
v2 = ema(src, MovAv)
v6 = 2 * v2 - ema(v2, MovAv)
v6

//tema
variant_tripleema(src,MovAv) =>
v2 = ema(src, MovAv)
v7 = 3 * (v2 - ema(v2, MovAv)) + ema(ema(v2, MovAv), MovAv)
v7

//Laguerre
variant_lag(p,g) =>
L0 = 0.0
L1 = 0.0
L2 = 0.0
L3 = 0.0
L0 := (1 - g)*p+g*nz(L0[1])
L1 := -g*L0+nz(L0[1])+g*nz(L1[1])
L2 := -g*L1+nz(L1[1])+g*nz(L2[1])
L3 := -g*L2+nz(L2[1])+g*nz(L3[1])
f = (L0 + 2*L1 + 2*L2 + L3)/6
f

//alma
variant_alma(src, MovAv) =>
var float _offset = 0.85
var float _sigma = 6.0
alma(src, MovAv, _offset, _sigma)

//vidya
variant_vidya(src, MovAv) =>
_cmo = cmo(src, MovAv)/100 //Change Momentum Oscillator
var _factor = 2 / (MovAv + 1)
var _vidya = 0.0
_vidya := src * _factor * abs(_cmo) + nz(_vidya[1]) * (1 - _factor *
abs(_cmo))

//return variant, defaults to SMA


variant(type, src, MovAv, g) =>
type=="EMA" ? ema(src,MovAv) :
type=="WMA" ? wma(src,MovAv):
type=="VWMA" ? vwma(src,MovAv) :
type=="SMMA" ? variant_smoothed(src,MovAv) :
type=="DEMA" ? variant_doubleema(src,MovAv):
type=="TEMA" ? variant_tripleema(src,MovAv):
type=="LAGMA" ? variant_lag(src,g) :
type=="HullMA"? wma(2 * wma(src, MovAv / 2) - wma(src, MovAv),
round(sqrt(MovAv))) :
type=="EHMA" ? ema(2*ema(src, MovAv/2)-ema(src, MovAv), round(sqrt(MovAv))) :
type=="ETMA" ? ema(ema(src, MovAv), MovAv) :
type=="SSMA" ? variant_supersmoother(src,MovAv) :
type=="ALMA" ? variant_alma(src, MovAv) :
type=="VIDYA" ? variant_vidya(src, MovAv) :
type=="STMA" ? sma(sma(src, MovAv), MovAv) :
type=="ZEMA" ? variant_zerolagema(src,MovAv) :
type=="TMA" ? sma(sma(src,MovAv),MovAv) :
sma(src,MovAv)

//assign functions
mov_1 = variant(MAType_1, src, ma1_length, gamma)
mov_2 = variant(MAType_2, src, ma2_length, gamma)
mov_3 = variant(MAType_3, src, ma3_length, gamma)
mov_4 = variant(MAType_4, src, ma4_length, gamma)
mov_5 = variant(MAType_5, src, ma5_length, gamma)

//mtf source
mtf1 = security(syminfo.tickerid, res, mov_1)
mtf2 = security(syminfo.tickerid, res, mov_2)
mtf3 = security(syminfo.tickerid, res, mov_3)
mtf4 = security(syminfo.tickerid, res, mov_4)
mtf5 = security(syminfo.tickerid, res, mov_5)

ma1=plot(moving_ok and ma1_active ? mtf1 : na, title="Moving-Averages-1",


color=color.new(color.lime,0), linewidth=1)
ma2=plot(moving_ok and ma2_active ? mtf2 : na, title="Moving-Averages-2",
color=color.new(color.blue,0), linewidth=1)
ma3=plot(moving_ok and ma3_active ? mtf3 : na, title="Moving-Averages-3",
color=color.new(color.red,0), linewidth=1)
ma4=plot(moving_ok and ma4_active ? mtf4 : na, title="Moving-Averages-4",
color=color.new(color.orange,0), linewidth=1)
ma5=plot(moving_ok and ma5_active ? mtf5 : na, title="Moving-Averages-5",
color=color.new(color.purple,0), linewidth=1)

//Pivot Points
////////////////////////
pivot_ok = input(title = "═══════════════ Pivot Points Settings ", defval=false,
type=input.bool)

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(title="Type", defval="Traditional", options=[TRADITIONAL, FIBONACCI,


WOODIE, CLASSIC, DEMARK, CAMARILLA])
pivot_time_frame = input(title="Pivots Timeframe", defval=AUTO, options=[AUTO,
DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, BIYEARLY, TRIYEARLY, QUINQUENNIALLY,
DECENNIALLY])
look_back = input(title="Number of Pivots Back", type=input.integer, defval=15,
minval=1, maxval=5000)
is_daily_based = input(title="Use Daily-based Values", type=input.bool,
defval=true, 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_labels = input(title="Show Labels", type=input.bool, defval=true, inline =


"labels")
position_labels = input("Right", "", options = ["Left", "Right"], inline =
"labels")

var DEF_COLOR = #FB8C00


var arr_time = array.new_int()
var p = array.new_float()
p_show = input(true, "P ", inline = "P")
p_color = input(DEF_COLOR, "", inline = "P")

var r1 = array.new_float()
var s1 = array.new_float()
s1r1_show = input(true, "S1/R1", inline = "S1/R1")
s1_color = input(color.red, "S1", inline = "S1/R1")
r1_color = input(color.green, "R1", inline = "S1/R1")

var r2 = array.new_float()
var s2 = array.new_float()
s2r2_show = input(true, "S2/R2", inline = "S2/R2")
s2_color = input(color.red, "S2", inline = "S2/R2")
r2_color = input(color.green, "R2", inline = "S2/R2")

var r3 = array.new_float()
var s3 = array.new_float()
s3r3_show = input(true, "S3/R3", inline = "S3/R3")
s3_color = input(color.red, "S3", inline = "S3/R3")
r3_color = input(color.green, "R3", inline = "S3/R3")

var r4 = array.new_float()
var s4 = array.new_float()
s4r4_show = input(true, "S4/R4", inline = "S4/R4")
s4_color = input(color.red, "S4", inline = "S4/R4")
r4_color = input(color.green, "R4", inline = "S4/R4")

var r5 = array.new_float()
var s5 = array.new_float()
s5r5_show = input(true, "S5/R5", inline = "S5/R5")
s5_color = input(color.red, "S5", inline = "S5/R5")
r5_color = input(color.green, "R5", inline = "S5/R5")

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 labels = array.new_label()
var values = array.new_label()

draw_line(i, pivot, col) =>


if array.size(arr_time) > 1 and pivot_ok
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))

//tostring(pp)
draw_label(i, y, txt, pp, txt_color,z) =>
if show_labels and pivot_ok
o = z == "Stock" ? tostring(pp, "##.##") : tostring(pp)
offset = ' '
labels_align_str_left= position_labels == "Left" ? txt + " " + o + offset :
offset + txt + " " + o
x = position_labels == "Left" ? array.get(arr_time, i) :
array.get(arr_time, i + 1)
array.push(labels, 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))
array.push(r3, pivotX_Median * 2 + (pivotX_prev_high - 2 * pivotX_prev_low))
array.push(s3, pivotX_Median * 2 - (2 * pivotX_prev_high - pivotX_prev_low))
array.push(r4, pivotX_Median * 3 + (pivotX_prev_high - 3 * pivotX_prev_low))
array.push(s4, pivotX_Median * 3 - (3 * pivotX_prev_high - pivotX_prev_low))
array.push(r5, pivotX_Median * 4 + (pivotX_prev_high - 4 * pivotX_prev_low))
array.push(s5, pivotX_Median * 4 - (4 * 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)
array.push(r3, pivotX_Median + 1 * pivot_range)
array.push(s3, pivotX_Median - 1 * 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)
array.push(r3, pivot_point_r3)
array.push(s3, pivot_point_s3)
array.push(r4, pivot_point_r3 + pivot_range)
array.push(s4, pivot_point_s3 - pivot_range)

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)
array.push(r3, pivotX_Median + 2 * pivot_range)
array.push(s3, pivotX_Median - 2 * pivot_range)
array.push(r4, pivotX_Median + 3 * pivot_range)
array.push(s4, pivotX_Median - 3 * 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)
array.push(r3, pivotX_prev_close + pivot_range * 1.1 / 4.0)
array.push(s3, pivotX_prev_close - pivot_range * 1.1 / 4.0)
array.push(r4, pivotX_prev_close + pivot_range * 1.1 / 2.0)
array.push(s4, pivotX_prev_close - pivot_range * 1.1 / 2.0)

resolution = get_pivot_resolution()

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


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

var number_of_years = 0
is_change_years = false
var custom_years_resolution = pivot_time_frame == BIYEARLY or pivot_time_frame ==
TRIYEARLY or pivot_time_frame == QUINQUENNIALLY or pivot_time_frame == DECENNIALLY
if custom_years_resolution and change(time(resolution))
number_of_years += 1
if pivot_time_frame == BIYEARLY and number_of_years % 2 == 0
is_change_years := true
number_of_years := 0
else if pivot_time_frame == TRIYEARLY and number_of_years % 3 == 0
is_change_years := true
number_of_years := 0
else if pivot_time_frame == QUINQUENNIALLY and number_of_years % 5 == 0
is_change_years := true
number_of_years := 0
else if pivot_time_frame == DECENNIALLY and number_of_years % 10 == 0
is_change_years := true
number_of_years := 0

var is_change = false


var uses_current_bar = timeframe.isintraday and kind == WOODIE
var change_time = int(na)
is_time_change = (change(time(resolution)) and not custom_years_resolution) 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
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)
if array.size(r2) > 0 and s2r2_show
array.shift(r2)
if array.size(s2) > 0 and s2r2_show
array.shift(s2)
if array.size(r3) > 0 and s3r3_show
array.shift(r3)
if array.size(s3) > 0 and s3r3_show
array.shift(s3)
if array.size(r4) > 0 and s4r4_show
array.shift(r4)
if array.size(s4) > 0 and s4r4_show
array.shift(s4)
if array.size(r5) > 0 and s5r5_show
array.shift(r5)
if array.size(s5) > 0 and s5r5_show
array.shift(s5)
is_change := true
else
if is_daily_based
pivotX_high := max(pivotX_high, sec_high)
pivotX_low := min(pivotX_low, sec_low)
else
pivotX_high := max(pivotX_high, high)
pivotX_low := min(pivotX_low, low)

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


is_change := false
if array.size(arr_time) > 2 and custom_years_resolution
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(labels))

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", array.get(p, i), p_color,trade)
//draw_values(i, array.get(p, i), p, p_color)
if array.size(r1) > 0 and s1r1_show
draw_line(i, r1, r1_color)
draw_label(i, array.get(r1, i), "R1", array.get(r1, i), r1_color,trade)
if array.size(s1) > 0 and s1r1_show
draw_line(i, s1, s1_color)
draw_label(i, array.get(s1, i), "S1", array.get(s1, i), s1_color,trade)
if array.size(r2) > 0 and s2r2_show
draw_line(i, r2, r2_color)
draw_label(i, array.get(r2, i), "R2", array.get(r2, i), r2_color,trade)
if array.size(s2) > 0 and s2r2_show
draw_line(i, s2, s2_color)
draw_label(i, array.get(s2, i), "S2", array.get(s2, i), s2_color,trade)
if array.size(r3) > 0 and s3r3_show
draw_line(i, r3, r3_color)
draw_label(i, array.get(r3, i), "R3", array.get(r3, i), r3_color,trade)
if array.size(s3) > 0 and s3r3_show
draw_line(i, s3, s3_color)
draw_label(i, array.get(s3, i), "S3", array.get(s3, i), s3_color,trade)
if array.size(r4) > 0 and s4r4_show
draw_line(i, r4, r4_color)
draw_label(i, array.get(r4, i), "R4", array.get(r4, i), r4_color,trade)
if array.size(s4) > 0 and s4r4_show
draw_line(i, s4, s4_color)
draw_label(i, array.get(s4, i), "S4", array.get(s4, i), s4_color,trade)
if array.size(r5) > 0 and s5r5_show
draw_line(i, r5, r5_color)
draw_label(i, array.get(r5, i), "R5", array.get(r5, i), r5_color,trade)
if array.size(s5) > 0 and s5r5_show
draw_line(i, s5, s5_color)
draw_label(i, array.get(s5, i), "S5", array.get(s5, i), s5_color,trade)

//SuperTrend
////////////////////////
super_ok = input(title = "═══════════════ SuperTrend Settings ", defval=false,
type=input.bool)

Periods = input(title="ATR Period", type=input.integer, defval=10)


st_src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool,
defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=st_src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=st_src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(super_ok ? trend == 1 ? up : na : na, title="Up Trend",
style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(super_ok ? buySignal ? up : na : na, title="UpTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny,
color=color.new(color.green,0))
plotshape(super_ok ? buySignal and showsignals ? up : na : na, title="Buy",
text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny,
color=color.new(color.green,0), textcolor=color.white)
dnPlot = plot(super_ok ? trend == 1 ? na : dn : na, title="Down Trend",
style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(super_ok ? sellSignal ? dn : na : na, title="DownTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny,
color=color.new(color.red,0))
plotshape(super_ok ? sellSignal and showsignals ? dn : na : na, title="Sell",
text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny,
color=color.new(color.red,0), textcolor=color.white)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) :
color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) :
color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend
has changed direction!")

//Bollinger Bands
////////////////////////
bband_ok = input(title = "═══════════════ Bollinger Bands Settings ", defval=false,
type=input.bool)
bb_length = input(20, minval=1, title="BBands Length")
bb_mult1 = input(2.0, minval=0.001, maxval=50, title="BBands Multiplier-1")
bb_basis = sma(src, bb_length)
bb_dev1 = bb_mult1 * stdev(src, bb_length)
bb_upper1 = bb_basis + bb_dev1
bb_lower1 = bb_basis - bb_dev1
bb_offset = input(0, "BBands Offset", type = input.integer, minval = -500, maxval =
500)
plot(bband_ok ? bb_basis : na, "BBands Basis", color=#872323, offset = bb_offset)
bb_p1 = plot(bband_ok ? bb_upper1 : na, "BBands Upper 1", color=color.teal, offset
= bb_offset)
bb_p3 = plot(bband_ok ? bb_lower1 : na, "BBands Lower 1", color=color.teal, offset
= bb_offset)
fill(bb_p1, bb_p3, title = "BBands 1 Background", color=color.new(#198787,95))

//Ichimoku
////////////////////////
ichi_ok = input(title = "═══════════════ Ichimoku Cloud Settings ", defval=false,
type=input.bool)
tenkan_ok = input(false, title="Show/Hide Only Tenkansen")
kijun_ok = input(false, title="Show/Hide Only Kijunsen")
ichi_conversionPeriods = input(9, minval=1, title="ICHI Conversion Line Periods")
ichi_basePeriods = input(26, minval=1, title="ICHI Base Line Periods")
ichi_laggingSpan2Periods = input(52, minval=1, title="ICHI Lagging Span 2 Periods")
ichi_displacement = input(26, minval=1, title="ICHI Displacement")
donchian(len) => avg(lowest(len), highest(len))
ichi_conversionLine = donchian(ichi_conversionPeriods)
ichi_baseLine = donchian(ichi_basePeriods)
ichi_leadLine1 = avg(ichi_conversionLine, ichi_baseLine)
ichi_leadLine2 = donchian(ichi_laggingSpan2Periods)
plot(ichi_ok ? ichi_conversionLine : na, color=#0496ff, title="ICHI-Conversion
Line")
plot(ichi_ok ? ichi_baseLine : na, color=#991515, title="ICHI-Base Line")
plot(ichi_ok ? close : na, offset = -ichi_displacement + 1, color=#459915,
title="ICHI-Lagging Span")
ichi_p1 = plot(ichi_ok ? ichi_leadLine1 : na, offset = ichi_displacement - 1,
color=color.green,
title="ICHI-Lead 1")
ichi_p2 = plot(ichi_ok ? ichi_leadLine2: na, offset = ichi_displacement - 1,
color=color.red,
title="ICHI-Lead 2")
fill(ichi_p1, ichi_p2, color = ichi_leadLine1 > ichi_leadLine2 ? color.green :
color.red)
plot(tenkan_ok ? ichi_conversionLine : na, color=#0496ff, title="ICHI-Conversion
Line")
plot(kijun_ok ? ichi_baseLine : na, color=#991515, title="ICHI-Base Line")
//Don Chain Channels
////////////////////////
don_ok = input(title = "═══════════════ DonChain Channels Settings ", defval=false,
type=input.bool)
don_length = input(20, minval=1)
lower = lowest(don_length)
upper = highest(don_length)
basis = avg(upper, lower)
plot(don_ok ? basis : na, "Basis", color=#FF6D00)
u = plot(don_ok ? upper : na, "Upper", color=#2962FF)
l = plot(don_ok ? lower : na, "Lower", color=#2962FF)
fill(u, l, color=color.rgb(33, 150, 243, 95), title="Background")

//Parabolic Sar
////////////////////////
psar_ok = input(title = "═══════════════ Parabolic Sar Settings ", defval=false,
type=input.bool)
psar_start = input(0.02, title="PSAR Start")
psar_increment = input(0.02, title="PSAR Increment")
psar_maximum = input(0.2, "PSAR Max Value")
psar_out = sar(psar_start, psar_increment, psar_maximum)
plot(psar_ok ? psar_out : na, "ParabolicSAR", style=plot.style_cross,
color=#3A6CA8)

//Volume Based Bars


////////////////////////
vbcb_ok = input(title = "═══════════════ Volume Based Coloured Bars Settings ",
defval=false, type=input.bool)
vbcb_length= input(21, "Volume Based Bars Length", minval=1)
vbcb_avrg=sma(volume,vbcb_length)

vbcb_vold1 = volume > vbcb_avrg * 1.5 and close < open


vbcb_vold2 = volume >= vbcb_avrg * 0.5 and volume <= vbcb_avrg * 1.5 and close <
open
vbcb_vold3 = volume < vbcb_avrg * 0.5 and close < open
vbcb_volu1 = volume > vbcb_avrg * 1.5 and close > open
vbcb_volu2 = volume >= vbcb_avrg * 0.5 and volume <= vbcb_avrg * 1.5 and close >
open
vbcb_volu3 = volume < vbcb_avrg * 0.5 and close > open

vbcb_cold1 = #800000
vbcb_cold2 = #FF0000
vbcb_cold3 = color.orange
vbcb_colu1 = #006400
vbcb_colu2 = color.lime
vbcb_colu3 = #7FFFD4
vbcb_VolColor = vbcb_vold1 ? vbcb_cold1 : vbcb_vold2 ? vbcb_cold2 : vbcb_vold3 ?
vbcb_cold3 : vbcb_volu1 ? vbcb_colu1 : vbcb_volu2 ? vbcb_colu2 : vbcb_volu3 ?
vbcb_colu3 : na
barcolor(vbcb_ok ? vbcb_VolColor : na, title="Volume Based Coloured Bars")

//Mavilimw
////////////////////////
show_mav = input(title = "═══════════════ Mavilim Settings ", defval=false,
type=input.bool)
mavilimold = input(false, title="Show Previous Version of MavilimW?")
fmal=input(3,"Mavilim First Moving Average length")
smal=input(5,"Mavilim Second Moving Average length")
tmal=fmal+smal
Fmal=smal+tmal
Ftmal=tmal+Fmal
Smal=Fmal+Ftmal

M1= wma(src, fmal)


M2= wma(M1, smal)
M3= wma(M2, tmal)
M4= wma(M3, Fmal)
M5= wma(M4, Ftmal)
MAVW= wma(M5, Smal)
col1= MAVW>MAVW[1]
col3= MAVW<MAVW[1]
colorM = col1 ? color.blue : col3 ? color.red : color.yellow

plot(show_mav ? MAVW : na, color=colorM, linewidth=2, title="MAVW")


M12= wma(src, 3)
M22= wma(M12, 5)
M32= wma(M22, 8)
M42= wma(M32, 13)
M52= wma(M42, 21)
MAVW2= wma(M52, 34)

plot(mavilimold and MAVW2 ? MAVW2 : na, color=color.blue, linewidth=2,


title="MavWOld")

//Tillson
////////////////////////
show_t3 = input(title = "═══════════════ Tillson T3 Settings ", defval=false,
type=input.bool)

T3FiboLine = input(false, title="Show T3 Fibonacci Ratio Line?")

length1 = input(8, "T3 Length")


a1 = input(0.7, "Volume Factor")

e1 = ema((high + low + 2 * close) / 4, length1)


e2 = ema(e1, length1)
e3 = ema(e2, length1)
e4 = ema(e3, length1)
e5 = ema(e4, length1)
e6 = ema(e5, length1)
c1 = -a1 * a1 * a1
c2 = 3 * a1 * a1 + 3 * a1 * a1 * a1
c3 = -6 * a1 * a1 - 3 * a1 - 3 * a1 * a1 * a1
c4 = 1 + 3 * a1 + a1 * a1 * a1 + 3 * a1 * a1
T3 = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3

t3col1 = T3 > T3[1]


t3col3 = T3 < T3[1]
color_1 = t3col1 ? color.green : t3col3 ? color.red : color.yellow
plot(show_t3 ? T3 : na, color=color_1, linewidth=3, title="T3")

length12 = input(5, "T3 Length fibo")


a12 = input(0.618, "Volume Factor fibo")

e12 = ema((high + low + 2 * close) / 4, length12)


e22 = ema(e12, length12)
e32 = ema(e22, length12)
e42 = ema(e32, length12)
e52 = ema(e42, length12)
e62 = ema(e52, length12)
c12 = -a12 * a12 * a12
c22 = 3 * a12 * a12 + 3 * a12 * a12 * a12
c32 = -6 * a12 * a12 - 3 * a12 - 3 * a12 * a12 * a12
c42 = 1 + 3 * a12 + a12 * a12 * a12 + 3 * a12 * a12
T32 = c12 * e62 + c22 * e52 + c32 * e42 + c42 * e32

col12 = T32 > T32[1]


col32 = T32 < T32[1]
color2 = col12 ? color.blue : col32 ? color.purple : color.yellow
plot(show_t3 ? T3FiboLine and T32 ? T32 : na : na, color=color2, linewidth=2,
title="T3fibo")

alertcondition(crossover(T3, T3[1]), title="T3 BUY", message="T3 BUY!")


alertcondition(crossunder(T3, T3[1]), title="T3 SELL", message="T3 SELL!")

alertcondition(cross(T3, T3[1]), title="Color ALARM", message="T3 has changed


color!")

//OTT
////////////////////////
ott_ok = input(title = "═══════════════ Optimized Trend Tracker Settings ",
defval=false, type=input.bool)

length=input(2, "OTT Period", minval=1)


percent=input(1.4, "OTT Percent", type=input.float, step=0.1, minval=0)
showsupport = input(title="Show Support Line?", type=input.bool, defval=true)
showsignalsk = input(title="Show Support Line Crossing Signals?", type=input.bool,
defval=true)
showsignalsc = input(title="Show Price/OTT Crossing Signals?", type=input.bool,
defval=false)
highlight = input(title="Show OTT Color Changes?", type=input.bool, defval=false)
showsignalsr = input(title="Show OTT Color Change Signals?", type=input.bool,
defval=false)
ott_highlighting = input(title="Highlighter On/Off ?", type=input.bool,
defval=true)
mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA",
"WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])
Var_Func(src,length)=>
valpha=2/(length+1)
vud1=src>src[1] ? src-src[1] : 0
vdd1=src<src[1] ? src[1]-src : 0
vUD=sum(vud1,9)
vDD=sum(vdd1,9)
vCMO=nz((vUD-vDD)/(vUD+vDD))
VAR=0.0
VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])
VAR=Var_Func(src,length)
Wwma_Func(src,length)=>
wwalpha = 1/ length
WWMA = 0.0
WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])
WWMA=Wwma_Func(src,length)
Zlema_Func(src,length)=>
zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2
zxEMAData = (src + (src - src[zxLag]))
ZLEMA = ema(zxEMAData, length)
ZLEMA=Zlema_Func(src,length)
Tsf_Func(src,length)=>
lrc = linreg(src, length, 0)
lrc1 = linreg(src,length,1)
lrs = (lrc-lrc1)
TSF = linreg(src, length, 0)+lrs
TSF=Tsf_Func(src,length)
getMA(src, length) =>
ma = 0.0
if mav == "SMA"
ma := sma(src, length)
ma

if mav == "EMA"
ma := ema(src, length)
ma

if mav == "WMA"
ma := wma(src, length)
ma

if mav == "TMA"
ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1)
ma

if mav == "VAR"
ma := VAR
ma

if mav == "WWMA"
ma := WWMA
ma

if mav == "ZLEMA"
ma := ZLEMA
ma

if mav == "TSF"
ma := TSF
ma
ma

MAvg=getMA(src, length)
fark=MAvg*percent*0.01
longStop = MAvg - fark
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop
shortStop = MAvg + fark
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ?
-1 : dir
MT = dir==1 ? longStop: shortStop
OTT=MAvg>MT ? MT*(200+percent)/200 : MT*(200-percent)/200
plot(ott_ok ? showsupport ? MAvg : na : na, color=#0585E1, linewidth=2,
title="Support Line")
OTTC = highlight ? OTT[2] > OTT[3] ? color.green : color.red : #B800D9
pALL=plot(ott_ok ? nz(OTT[2]) : na, color=OTTC, linewidth=2, title="OTT")
alertcondition(cross(OTT[2], OTT[3]), title="Color ALARM", message="OTT Has Changed
Color!")
alertcondition(crossover(OTT[2], OTT[3]), title="GREEN ALERT", message="OTT GREEN
BUY SIGNAL!")
alertcondition(crossunder(OTT[2], OTT[3]), title="RED ALERT", message="OTT RED SELL
SIGNAL!")
alertcondition(cross(MAvg, OTT[2]), title="Cross Alert", message="OTT - Support
Line Crossing!")
alertcondition(crossover(MAvg, OTT[2]), title="Crossover Alarm", message="Support
Line BUY SIGNAL!")
alertcondition(crossunder(MAvg, OTT[2]), title="Crossunder Alarm", message="Support
Line SELL SIGNAL!")
alertcondition(cross(src, OTT[2]), title="Price Cross Alert", message="OTT - Price
Crossing!")
alertcondition(crossover(src, OTT[2]), title="Price Crossover Alarm",
message="PRICE OVER OTT - BUY SIGNAL!")
alertcondition(crossunder(src, OTT[2]), title="Price Crossunder Alarm",
message="PRICE UNDER OTT - SELL SIGNAL!")
buySignalk = crossover(MAvg, OTT[2])
plotshape(ott_ok ? buySignalk and showsignalsk ? OTT*0.995 : na : na, title="Buy",
text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny,
color=color.green, textcolor=color.white)
sellSignallk = crossunder(MAvg, OTT[2])
plotshape(ott_ok ? sellSignallk and showsignalsk ? OTT*1.005 : na : na,
title="Sell", text="Sell", location=location.absolute, style=shape.labeldown,
size=size.tiny, color=color.red, textcolor=color.white)
buySignalc = crossover(src, OTT[2])
plotshape(buySignalc and showsignalsc ? OTT*0.995 : na, title="Buy", text="Buy",
location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green,
textcolor=color.white)
sellSignallc = crossunder(src, OTT[2])
plotshape(sellSignallc and showsignalsc ? OTT*1.005 : na, title="Sell",
text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny,
color=color.red, textcolor=color.white)
ott_mPlot = plot(ohlc4, title="", style=plot.style_circles,
linewidth=0,display=display.none)
ott_longFillColor = ott_highlighting ? (MAvg>OTT ? color.green : na) : na
ott_shortFillColor = ott_highlighting ? (MAvg<OTT ? color.red : na) : na
fill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)
buySignalr = crossover(OTT[2], OTT[3])
plotshape(buySignalr and showsignalsr ? OTT*0.995 : na, title="Buy", text="Buy",
location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green,
textcolor=color.white)
sellSignallr = crossunder(OTT[2], OTT[3])
plotshape(sellSignallr and showsignalsr ? OTT*1.005 : na, title="Sell",
text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny,
color=color.red, textcolor=color.white)

You might also like