You are on page 1of 12

//@version=5

indicator(title="ALL Moving AverageS with multi TF", shorttitle="ALL MA MTF BY


RONNY", overlay=true)
len1 = input.int(44, minval=1, title="1st EMA Length")
src1 = input(close, title="1st EMA Source")
offset1 = input.int(title="1st EMA Offset", defval=0, minval=-500, maxval=500)
out1 = ta.ema(src1, len1)
tf1 = input.timeframe(title="1st Timeframe1", defval="15")
s1 = request.security(syminfo.tickerid, tf1, out1, gaps=barmerge.gaps_on)
plot(s1, title="EMA1", color=color.red, offset=offset1)
len2 = input.int(44, minval=1, title="2nd EMA Length")
src2 = input(close, title="2nd EMA Source")
offset2 = input.int(title="2nd EMA Offset", defval=0, minval=-500, maxval=500)
out2 = ta.ema(src2, len2)
tf2 = input.timeframe(title="2nd Timeframe1", defval="30")
s2 = request.security(syminfo.tickerid, tf2, out2, gaps=barmerge.gaps_on)
plot(s2, title="EMA2", color=color.red, offset=offset2)
len3 = input.int(44, minval=1, title="3rd EMA Length")
src3 = input(close, title="3rd EMA Source")
offset3 = input.int(title="3rd EMA Offset", defval=0, minval=-500, maxval=500)
out3 = ta.ema(src3, len3)
tf3 = input.timeframe(title="3rd Timeframe1", defval="60")
s3 = request.security(syminfo.tickerid, tf3, out3, gaps=barmerge.gaps_on)
plot(s3, title="EMA3", color=color.red, offset=offset3)
len4 = input.int(44, minval=1, title="4th EMA Length")
src4 = input(close, title="4th EMA Source")
offset4 = input.int(title="4th EMA Offset", defval=0, minval=-500, maxval=500)
out4 = ta.ema(src4, len4)
tf4 = input.timeframe(title="4th Timeframe1", defval="15")
s4 = request.security(syminfo.tickerid, tf4, out4, gaps=barmerge.gaps_on)
plot(s4, title="EMA4", color=color.red, offset=offset4)
len5 = input.int(44, minval=1, title="5th EMA Length")
src5 = input(close, title="5th EMA Source")
offset5 = input.int(title="5th EMA Offset", defval=0, minval=-500, maxval=500)
out5 = ta.ema(src5, len5)
tf5 = input.timeframe(title="5th Timeframe1", defval="30")
s5 = request.security(syminfo.tickerid, tf5, out5, gaps=barmerge.gaps_on)
plot(s5, title="EMA5", color=color.red, offset=offset5)
len6 = input.int(44, minval=1, title="6th EMA Length")
src6 = input(close, title="6th EMA Source")
offset6 = input.int(title="6th EMA Offset", defval=0, minval=-500, maxval=500)
out6 = ta.ema(src6, len6)
tf6 = input.timeframe(title="6th Timeframe1", defval="60")
s6 = request.security(syminfo.tickerid, tf6, out6, gaps=barmerge.gaps_on)
plot(s6, title="EMA6", color=color.red, offset=offset6)
len7 = input.int(44, minval=1, title="7th EMA Length")
src7 = input(close, title="7th EMA Source")
offset7 = input.int(title="7th EMA Offset", defval=0, minval=-500, maxval=500)
out7 = ta.ema(src7, len7)
tf7 = input.timeframe(title="7th Timeframe1", defval="15")
s7 = request.security(syminfo.tickerid, tf7, out7, gaps=barmerge.gaps_on)
plot(s7, title="EMA7", color=color.red, offset=offset7)
len8 = input.int(44, minval=1, title="8th EMA Length")
src8 = input(close, title="8th EMA Source")
offset8 = input.int(title="8th EMA Offset", defval=0, minval=-500, maxval=500)
out8 = ta.ema(src8, len8)
tf8 = input.timeframe(title="8th Timeframe1", defval="30")
s8 = request.security(syminfo.tickerid, tf8, out8, gaps=barmerge.gaps_on)
plot(s8, title="EMA8", color=color.red, offset=offset8)
len9 = input.int(44, minval=1, title="9th EMA Length")
src9 = input(close, title="9th EMA Source")
offset9 = input.int(title="9th EMA Offset", defval=0, minval=-500, maxval=500)
out9 = ta.ema(src9, len9)
tf9 = input.timeframe(title="9th Timeframe1", defval="60")
s9 = request.security(syminfo.tickerid, tf9, out9, gaps=barmerge.gaps_on)
plot(s9, title="EMA9", color=color.red, offset=offset9)
len10 = input.int(44, minval=1, title="10th EMA Length")
src10 = input(close, title="10th EMA Source")
offset10 = input.int(title="10th EMA Offset", defval=0, minval=-500, maxval=500)
out10 = ta.ema(src10, len10)
tf10 = input.timeframe(title="10th Timeframe1", defval="60")
s10 = request.security(syminfo.tickerid, tf10, out10, gaps=barmerge.gaps_on)
plot(s10, title="EMA10", color=color.red, offset=offset10)
len11 = input.int(44, minval=1, title="11th EMA Length")
src11 = input(close, title="11th EMA Source")
offset11 = input.int(title="11th EMA Offset", defval=0, minval=-500, maxval=500)
out11 = ta.ema(src11, len11)
tf11 = input.timeframe(title="11th Timeframe1", defval="60")
s11 = request.security(syminfo.tickerid, tf11, out11, gaps=barmerge.gaps_on)
plot(s11, title="EMA11", color=color.red, offset=offset11)
len12 = input.int(44, minval=1, title="12th EMA Length")
src12 = input(close, title="12th EMA Source")
offset12 = input.int(title="12th EMA Offset", defval=0, minval=-500, maxval=500)
out12 = ta.ema(src12, len12)
tf12 = input.timeframe(title="12th Timeframe1", defval="60")
s12 = request.security(syminfo.tickerid, tf12, out12, gaps=barmerge.gaps_on)
plot(s12, title="EMA12", color=color.red, offset=offset12)
len13 = input.int(44, minval=1, title="13th EMA Length")
src13 = input(close, title="13th EMA Source")
offset13 = input.int(title="13th EMA Offset", defval=0, minval=-500, maxval=500)
out13 = ta.ema(src13, len13)
tf13 = input.timeframe(title="13th Timeframe1", defval="60")
s13 = request.security(syminfo.tickerid, tf9, out13, gaps=barmerge.gaps_on)
plot(s13, title="EMA13", color=color.red, offset=offset13)
len14 = input.int(44, minval=1, title="14th EMA Length")
src14 = input(close, title="14th EMA Source")
offset14 = input.int(title="14th EMA Offset", defval=0, minval=-500, maxval=500)
out14 = ta.ema(src14, len14)
tf14 = input.timeframe(title="14th Timeframe1", defval="60")
s14 = request.security(syminfo.tickerid, tf14, out14, gaps=barmerge.gaps_on)
plot(s14, title="EMA14", color=color.red, offset=offset14)
len15 = input.int(44, minval=1, title="15th SMA Length")
src15 = input(close, title="15th SMA Source")
offset15 = input.int(title="15th SMA Offset", defval=0, minval=-500, maxval=500)
out15 = ta.sma(src15, len15)
tf15 = input.timeframe(title="15th Timeframe1", defval="60")
s15 = request.security(syminfo.tickerid, tf15, out15, gaps=barmerge.gaps_on)
plot(s15, title="SMA15", color=color.red, offset=offset15)
len16 = input.int(44, minval=1, title="16th SMA Length")
src16 = input(close, title="16th SMA Source")
offset16 = input.int(title="16th SMA Offset", defval=0, minval=-500, maxval=500)
out16 = ta.sma(src16, len16)
tf16 = input.timeframe(title="16th Timeframe1", defval="60")
s16 = request.security(syminfo.tickerid, tf16, out16, gaps=barmerge.gaps_on)
plot(s16, title="SMA16", color=color.red, offset=offset16)
len17 = input.int(44, minval=1, title="17th SMA Length")
src17 = input(close, title="17th SMA Source")
offset17 = input.int(title="17th SMA Offset", defval=0, minval=-500, maxval=500)
out17 = ta.sma(src17, len17)
tf17 = input.timeframe(title="17th Timeframe1", defval="60")
s17 = request.security(syminfo.tickerid, tf17, out17, gaps=barmerge.gaps_on)
plot(s17, title="SMA17", color=color.red, offset=offset17)
len18 = input.int(44, minval=1, title="18th SMA Length")
src18 = input(close, title="18th SMA Source")
offset18 = input.int(title="18th SMA Offset", defval=0, minval=-500, maxval=500)
out18 = ta.sma(src18, len18)
tf18 = input.timeframe(title="18th Timeframe1", defval="60")
s18 = request.security(syminfo.tickerid, tf18, out18, gaps=barmerge.gaps_on)
plot(s18, title="SMA18", color=color.red, offset=offset18)
len19 = input.int(44, minval=1, title="19th SMA Length")
src19 = input(close, title="19th SMA Source")
offset19 = input.int(title="19th SMA Offset", defval=0, minval=-500, maxval=500)
out19 = ta.sma(src19, len19)
tf19 = input.timeframe(title="19th Timeframe1", defval="60")
s19 = request.security(syminfo.tickerid, tf19, out19, gaps=barmerge.gaps_on)
plot(s19, title="SMA19", color=color.red, offset=offset19)
len20 = input.int(44, minval=1, title="20th SMA Length")
src20 = input(close, title="20th SMA Source")
offset20 = input.int(title="20th SMA Offset", defval=0, minval=-500, maxval=500)
out20 = ta.sma(src20, len20)
tf20 = input.timeframe(title="20th Timeframe1", defval="60")
s20 = request.security(syminfo.tickerid, tf20, out20, gaps=barmerge.gaps_on)
plot(s20, title="SMA20", color=color.red, offset=offset20)
len21 = input.int(44, minval=1, title="21th SMA Length")
src21 = input(close, title="21th SMA Source")
offset21 = input.int(title="21th SMA Offset", defval=0, minval=-500, maxval=500)
out21 = ta.sma(src21, len21)
tf21 = input.timeframe(title="21th Timeframe1", defval="60")
s21 = request.security(syminfo.tickerid, tf21, out21, gaps=barmerge.gaps_on)
plot(s21, title="SMA21", color=color.red, offset=offset21)
len22 = input.int(44, minval=1, title="22th SMA Length")
src22 = input(close, title="22th SMA Source")
offset22 = input.int(title="22th SMA Offset", defval=0, minval=-500, maxval=500)
out22 = ta.sma(src22, len22)
tf22 = input.timeframe(title="22th Timeframe1", defval="60")
s22 = request.security(syminfo.tickerid, tf22, out22, gaps=barmerge.gaps_on)
plot(s22, title="SMA22", color=color.red, offset=offset22)
len23 = input.int(44, minval=1, title="23th SMA Length")
src23 = input(close, title="23th SMA Source")
offset23 = input.int(title="23th SMA Offset", defval=0, minval=-500, maxval=500)
out23 = ta.sma(src23, len23)
tf23 = input.timeframe(title="23th Timeframe1", defval="60")
s23 = request.security(syminfo.tickerid, tf23, out23, gaps=barmerge.gaps_on)
plot(s23, title="SMA23", color=color.red, offset=offset23)
len24 = input.int(44, minval=1, title="24th SMA Length")
src24 = input(close, title="24th SMA Source")
offset24 = input.int(title="24th SMA Offset", defval=0, minval=-500, maxval=500)
out24 = ta.sma(src24, len24)
tf24 = input.timeframe(title="24th Timeframe1", defval="60")
s24 = request.security(syminfo.tickerid, tf24, out24, gaps=barmerge.gaps_on)
plot(s24, title="SMA24", color=color.red, offset=offset24)
len25 = input.int(44, minval=1, title="25th SMA Length")
src25 = input(close, title="25th SMA Source")
offset25 = input.int(title="25th SMA Offset", defval=0, minval=-500, maxval=500)
out25 = ta.sma(src25, len25)
tf25 = input.timeframe(title="25th Timeframe1", defval="60")
s25 = request.security(syminfo.tickerid, tf25, out25, gaps=barmerge.gaps_on)
plot(s25, title="SMA25", color=color.red, offset=offset25)
len26 = input.int(44, minval=1, title="26th SMA Length")
src26 = input(close, title="26th SMA Source")
offset26 = input.int(title="26th SMA Offset", defval=0, minval=-500, maxval=500)
out26 = ta.sma(src26, len26)
tf26 = input.timeframe(title="26th Timeframe1", defval="60")
s26 = request.security(syminfo.tickerid, tf26, out26, gaps=barmerge.gaps_on)
plot(s26, title="SMA26", color=color.red, offset=offset26)
len27 = input.int(44, minval=1, title="27th SMA Length")
src27 = input(close, title="27th SMA Source")
offset27 = input.int(title="27th SMA Offset", defval=0, minval=-500, maxval=500)
out27 = ta.sma(src27, len27)
tf27 = input.timeframe(title="27th Timeframe1", defval="60")
s27 = request.security(syminfo.tickerid, tf27, out27, gaps=barmerge.gaps_on)
plot(s27, title="SMA27", color=color.red, offset=offset27)
len28 = input.int(44, minval=1, title="28th SMA Length")
src28 = input(close, title="28th SMA Source")
offset28 = input.int(title="28th SMA Offset", defval=0, minval=-500, maxval=500)
out28 = ta.sma(src28, len28)
tf28 = input.timeframe(title="28th Timeframe1", defval="60")
s28 = request.security(syminfo.tickerid, tf2, out28, gaps=barmerge.gaps_on)
plot(s28, title="SMA28", color=color.red, offset=offset28)

var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
runtime.error("No volume is provided by the data vendor.")

computeVWAP(src, isNewPeriod, stDevMultiplier) =>


var float sumSrcVol = na
var float sumVol = na
var float sumSrcSrcVol = na

sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]


sumVol := isNewPeriod ? volume : volume + sumVol[1]
// sumSrcSrcVol calculates the dividend of the equation that is later used to
calculate the standard deviation
sumSrcSrcVol := isNewPeriod ? volume * math.pow(src, 2) : volume *
math.pow(src, 2) + sumSrcSrcVol[1]

_vwap = sumSrcVol / sumVol


variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)
variance := variance < 0 ? 0 : variance
stDev = math.sqrt(variance)

lowerBand = _vwap - stDev * stDevMultiplier


upperBand = _vwap + stDev * stDevMultiplier

[_vwap, lowerBand, upperBand]

hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")


var anchor = input.string(defval = "Session", title="Anchor Period",
options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century",
"Earnings", "Dividends", "Splits"], group="VWAP Settings")
src = input(title = "Source", defval = hlc3, group="VWAP Settings")
offset = input(0, title="Offset", group="VWAP Settings")

showBands = input(true, title="Calculate Bands", group="Standard Deviation Bands


Settings")
stdevMult = input(1.0, title="Bands Multiplier", group="Standard Deviation Bands
Settings")

timeChange(period) =>
ta.change(time(period))

new_earnings = request.earnings(syminfo.tickerid, earnings.actual,


barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_dividends = request.dividends(syminfo.tickerid, dividends.gross,
barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on,
barmerge.lookahead_on, ignore_invalid_symbol=true)

isNewPeriod = switch anchor


"Earnings" => not na(new_earnings)
"Dividends" => not na(new_dividends)
"Splits" => not na(new_split)
"Session" => timeChange("D")
"Week" => timeChange("W")
"Month" => timeChange("M")
"Quarter" => timeChange("3M")
"Year" => timeChange("12M")
"Decade" => timeChange("12M") and year % 10 == 0
"Century" => timeChange("12M") and year % 100 == 0
=> false

isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits"


if na(src[1]) and not isEsdAnchor
isNewPeriod := true

float vwapValue = na
float std = na
float upperBandValue = na
float lowerBandValue = na

if not (hideonDWM and timeframe.isdwm)


[_vwap, bottom, top] = computeVWAP(src, isNewPeriod, stdevMult)
vwapValue := _vwap
upperBandValue := showBands ? top : na
lowerBandValue := showBands ? bottom : na

plot(vwapValue, title="VWAP", color=#2962FF, offset=offset)

upperBand = plot(upperBandValue, title="Upper Band", color=color.green,


offset=offset)
lowerBand = plot(lowerBandValue, title="Lower Band", color=color.green,
offset=offset)

fill(upperBand, lowerBand, title="Bands Fill", color= showBands ?


color.new(color.green, 95) : na)

atrPeriod = input(10, "ATR Length")


factor = input.float(3.0, "Factor", step = 0.01)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

bodyMiddle = plot((open + close) / 2, display=display.none)


upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green,
style=plot.style_linebr)
downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red,
style=plot.style_linebr)

fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)


fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)

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

var DEF_COLOR = #FB8C00


var arr_time = array.new_int()
var p = array.new_float()
p_show = input.bool(true, "P ", inline="P")
p_color = input.color(DEF_COLOR, "", inline="P")
var Rt1 = array.new_float()
var St1 = array.new_float()
St1Rt1_show = input.bool(true, "St1/Rt1", inline="St1/Rt1")
St1Rt1_color = input.color(DEF_COLOR, "", inline="St1/Rt1")
var Rt2 = array.new_float()
var St2 = array.new_float()
St2Rt2_show = input.bool(true, "St2/Rt2", inline="St2/Rt2")
St2Rt2_color = input.color(DEF_COLOR, "", inline="St2/Rt2")
var Rt3 = array.new_float()
var St3 = array.new_float()
St3Rt3_show = input.bool(true, "St3/Rt3", inline="St3/Rt3")
St3Rt3_color = input.color(DEF_COLOR, "", inline="St3/Rt3")
var Rt4 = array.new_float()
var St4 = array.new_float()
St4Rt4_show = input.bool(true, "St4/Rt4", inline="St4/Rt4")
St4Rt4_color = input.color(DEF_COLOR, "", inline="St4/Rt4")
var Rt5 = array.new_float()
var St5 = array.new_float()
St5Rt5_show = input.bool(true, "St5/Rt5", inline="St5/Rt5")
St5Rt5_color = input.color(DEF_COLOR, "", inline="St5/Rt5")
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()

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))

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


if show_labels
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(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(Rt1, pivotX_Median * 2 - pivotX_prev_low)
array.push(St1, pivotX_Median * 2 - pivotX_prev_high)
array.push(Rt2, pivotX_Median + 1 * (pivotX_prev_high - pivotX_prev_low))
array.push(St2, pivotX_Median - 1 * (pivotX_prev_high - pivotX_prev_low))
array.push(Rt3, pivotX_Median * 2 + (pivotX_prev_high - 2 * pivotX_prev_low))
array.push(St3, pivotX_Median * 2 - (2 * pivotX_prev_high - pivotX_prev_low))
array.push(Rt4, pivotX_Median * 3 + (pivotX_prev_high - 3 * pivotX_prev_low))
array.push(St4, pivotX_Median * 3 - (3 * pivotX_prev_high - pivotX_prev_low))
array.push(Rt5, pivotX_Median * 4 + (pivotX_prev_high - 4 * pivotX_prev_low))
array.push(St5, 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(Rt1, pivotX_Median + 0.382 * pivot_range)
array.push(St1, pivotX_Median - 0.382 * pivot_range)
array.push(Rt2, pivotX_Median + 0.618 * pivot_range)
array.push(St2, pivotX_Median - 0.618 * pivot_range)
array.push(Rt3, pivotX_Median + 1 * pivot_range)
array.push(St3, 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(Rt1, pivotX_Woodie_Median * 2 - pivotX_prev_low)
array.push(St1, pivotX_Woodie_Median * 2 - pivotX_prev_high)
array.push(Rt2, pivotX_Woodie_Median + 1 * pivot_range)
array.push(St2, pivotX_Woodie_Median - 1 * pivot_range)

pivot_point_Rt3 = pivotX_prev_high + 2 * (pivotX_Woodie_Median -


pivotX_prev_low)
pivot_point_St3 = pivotX_prev_low - 2 * (pivotX_prev_high -
pivotX_Woodie_Median)
array.push(Rt3, pivot_point_Rt3)
array.push(St3, pivot_point_St3)
array.push(Rt4, pivot_point_Rt3 + pivot_range)
array.push(St4, pivot_point_St3 - 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(Rt1, pivotX_Median * 2 - pivotX_prev_low)
array.push(St1, pivotX_Median * 2 - pivotX_prev_high)
array.push(Rt2, pivotX_Median + 1 * pivot_range)
array.push(St2, pivotX_Median - 1 * pivot_range)
array.push(Rt3, pivotX_Median + 2 * pivot_range)
array.push(St3, pivotX_Median - 2 * pivot_range)
array.push(Rt4, pivotX_Median + 3 * pivot_range)
array.push(St4, 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(Rt1, pivotX_Demark_X / 2 - pivotX_prev_low)
array.push(St1, 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(Rt1, pivotX_prev_close + pivot_range * 1.1 / 12.0)
array.push(St1, pivotX_prev_close - pivot_range * 1.1 / 12.0)
array.push(Rt2, pivotX_prev_close + pivot_range * 1.1 / 6.0)
array.push(St2, pivotX_prev_close - pivot_range * 1.1 / 6.0)
array.push(Rt3, pivotX_prev_close + pivot_range * 1.1 / 4.0)
array.push(St3, pivotX_prev_close - pivot_range * 1.1 / 4.0)
array.push(Rt4, pivotX_prev_close + pivot_range * 1.1 / 2.0)
array.push(St4, pivotX_prev_close - pivot_range * 1.1 / 2.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(Rt1) > 0 and St1Rt1_show
array.shift(Rt1)
if array.size(St1) > 0 and St1Rt1_show
array.shift(St1)
if array.size(Rt2) > 0 and St2Rt2_show
array.shift(Rt2)
if array.size(St2) > 0 and St2Rt2_show
array.shift(St2)
if array.size(Rt3) > 0 and St3Rt3_show
array.shift(Rt3)
if array.size(St3) > 0 and St3Rt3_show
array.shift(St3)
if array.size(Rt4) > 0 and St4Rt4_show
array.shift(Rt4)
if array.size(St4) > 0 and St4Rt4_show
array.shift(St4)
if array.size(Rt5) > 0 and St5Rt5_show
array.shift(Rt5)
if array.size(St5) > 0 and St5Rt5_show
array.shift(St5)
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


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(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", p_color)
if array.size(Rt1) > 0 and St1Rt1_show
draw_line(i, Rt1, St1Rt1_color)
draw_label(i, array.get(Rt1, i), "Rt1", St1Rt1_color)
if array.size(St1) > 0 and St1Rt1_show
draw_line(i, St1, St1Rt1_color)
draw_label(i, array.get(St1, i), "St1", St1Rt1_color)
if array.size(Rt2) > 0 and St2Rt2_show
draw_line(i, Rt2, St2Rt2_color)
draw_label(i, array.get(Rt2, i), "Rt2", St2Rt2_color)
if array.size(St2) > 0 and St2Rt2_show
draw_line(i, St2, St2Rt2_color)
draw_label(i, array.get(St2, i), "St2", St2Rt2_color)
if array.size(Rt3) > 0 and St3Rt3_show
draw_line(i, Rt3, St3Rt3_color)
draw_label(i, array.get(Rt3, i), "Rt3", St3Rt3_color)
if array.size(St3) > 0 and St3Rt3_show
draw_line(i, St3, St3Rt3_color)
draw_label(i, array.get(St3, i), "St3", St3Rt3_color)
if array.size(Rt4) > 0 and St4Rt4_show
draw_line(i, Rt4, St4Rt4_color)
draw_label(i, array.get(Rt4, i), "Rt4", St4Rt4_color)
if array.size(St4) > 0 and St4Rt4_show
draw_line(i, St4, St4Rt4_color)
draw_label(i, array.get(St4, i), "St4", St4Rt4_color)
if array.size(Rt5) > 0 and St5Rt5_show
draw_line(i, Rt5, St5Rt5_color)
draw_label(i, array.get(Rt5, i), "Rt5", St5Rt5_color)
if array.size(St5) > 0 and St5Rt5_show
draw_line(i, St5, St5Rt5_color)
draw_label(i, array.get(St5, i), "St5", St5Rt5_color)

You might also like