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

//@version=5

indicator(title='Goethe A - Multiple Leading Indicator Package', shorttitle='Goethe


A', overlay=true)

//HMA

setting8header = input(title='----------------Trend Caluculation


Settings----------------', defval=false)

length = input.int(400, minval=1, title='Longer MA Length', tooltip='This is for the


MA trend calculation, it directly interacts with entry signals as entry signals of
the opposite trend direction are not printed')
src = input(close, title='Source')
smoothing2 = input.string(defval='HMA', options=['HMA', 'SMA', 'EMA', 'WMA', 'VWMA'],
title='Longer Moving Average')

hullma2(src, length) =>


if smoothing2 == 'HMA'
ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length),
math.floor(math.sqrt(length)))
else
if smoothing2 == 'SMA'
ta.sma(src, length)
else
if smoothing2 == 'EMA'
ta.ema(src, length)
else
if smoothing2 == 'WMA'
ta.wma(src, length)
else
if smoothing2 == 'VWMA'
ta.vwma(src, length)

hullma = hullma2(src, length)

//EMA

lenEMA = input.int(50, minval=1, title='Shorter MA Length', tooltip='This is for the


MA trend calculation, it directly interacts with entry signals as entry signals of
the opposite trend direction are not printed')
offset = input.int(title='Offset', defval=0, minval=-500, maxval=500)

smoothing3 = input.string(defval='EMA', options=['HMA', 'SMA', 'EMA', 'WMA', 'VWMA'],


title='Shorter Moving Average')
ema2(src, length) =>
if smoothing3 == 'HMA'
ta.wma(2 * ta.wma(src, lenEMA / 2) - ta.wma(src, lenEMA),
math.floor(math.sqrt(lenEMA)))
else
if smoothing3 == 'SMA'
ta.sma(src, length)
else
if smoothing3 == 'EMA'
ta.ema(src, length)
else
if smoothing3 == 'WMA'
ta.wma(src, length)
else
if smoothing3 == 'VWMA'
ta.vwma(src, length)

emaout = ema2(src, lenEMA)

//Ichimoku

kumomulti = input.int(1, minval=1, title='Ichimoku Timeframe Multiplier')


conversionPeriods = 9 * kumomulti
basePeriods = 26 * kumomulti
laggingSpan2Periods = 52 * kumomulti
displacement = 1
donchian(len) =>
math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLineKUMO1 = math.avg(conversionLine, baseLine)
leadLineKUMO2 = donchian(laggingSpan2Periods)

whattrend = input.bool(title='Ichimoku Trend Calculation?', defval=true,


tooltip='alternative trend calculation based on an ichimoku cloud, if unchecked the
normal fast-slow MA calculation is used')

leadLine1 = whattrend ? leadLineKUMO2 : hullma


leadLine2 = whattrend ? leadLineKUMO1 : emaout

// OBV

setting7header = input(title='----------------OBV Settings----------------',


defval=false)
shortLength = input.int(1, title='Short OBV period', tooltip='These setting are used
for the divergence circles, they are based on an OBV indicator')
longLength = input.int(20, title='Long OBV period', tooltip='These setting are used
for the divergence circles, they are based on an OBV indicator')
pivR = input.int(title='OBV Wave Pivot Lookback Right', defval=1, tooltip='These
setting are used for the divergence circles, they are based on an OBV indicator')
pivL = input.int(title='OBV Wave Pivot Lookback Left', defval=20, tooltip='These
setting are used for the divergence circles, they are based on an OBV indicator')

// 1 - Compute regular OBV


//obv = cum(change(src) > 0 ? +volume : change(src) < 0 ? -volume : 0*volume)

// 2 - Compute OBV ocillator


obvOsc = ta.ema(ta.obv, shortLength) - ta.ema(ta.obv, longLength)

obvColor = obvOsc > 0 ? color.new(color.aqua, 60) : color.new(color.orange, 60)

// OBV Divergence

setting6header = input(title='----------------OBV Divergence


Settings----------------', defval=false)

up = ta.rma(math.max(ta.change(src), 0), shortLength)


down = ta.rma(-math.min(ta.change(src), 0), shortLength)
lbR = input.int(title='Divergence Pivot Lookback Right', defval=1, tooltip='These
setting are used for the divergence circles, they are based on an OBV indicator')
lbL = input.int(title='Divergence Pivot Lookback Left', defval=5, tooltip='These
setting are used for the divergence circles, they are based on an OBV indicator')
rangeUpper = input.int(title='Max of Lookback Range', defval=100, tooltip='These
setting are used for the divergence circles, they are based on an OBV indicator')
rangeLower = input.int(title='Min of Lookback Range', defval=2, tooltip='These
setting are used for the divergence circles, they are based on an OBV indicator')
plotBull = input(title='Plot Bullish', defval=true)
plotHiddenBull = input(title='Plot Hidden Bullish', defval=false)
plotBear = input(title='Plot Bearish', defval=true)
plotHiddenBear = input(title='Plot Hidden Bearish', defval=false)

whatobv = input.bool(title='Use PVT instead of OBV?', tooltip='If unchecked OBV is


used for Divergence', defval=false)

WhatOSC = whatobv ? ta.ema(ta.pvt, 3) - ta.ema(ta.pvt, 20) : ta.ema(ta.obv,


shortLength) - ta.ema(ta.obv, longLength)

bearColor = color.new(color.red, 0)
bullColor = color.new(color.green, 0)
hiddenBullColor = color.new(color.blue, 0)
hiddenBearColor = color.new(color.yellow, 0)
textColor = color.new(color.white, 0)
noneColor = color.new(color.white, 100)
//osc = ta.ema(ta.obv, shortLength) - ta.ema(ta.obv, longLength)
//osc = ta.ema(ta.pvt, 3) - ta.ema(ta.pvt, 20)
osc = WhatOSC
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low

oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)


bullCond = plotBull and priceLL and oscHL and plFound

//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low

oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Higher Low

priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)


hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High

oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)

bearCond = plotBear and priceHH and oscLH and phFound

//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Lower High

priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)

hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound

// OBV Plots

PHCond = obvOsc > 0 ? ta.pivothigh(obvOsc, pivL, pivR) : na


PLCond = obvOsc < 0 ? ta.pivotlow(obvOsc, pivL, pivR) : na

obvOsc2 = ta.sma(obvOsc, 3)

crossoverCond1 = ta.crossunder(obvOsc, 0)
crossoverCond2 = ta.crossover(obvOsc, 0)

// PVT Plots

obvOscPVT = ta.ema(ta.pvt, 3) - ta.ema(ta.pvt, 20)

PHCondPVT = obvOscPVT > 0 ? ta.pivothigh(obvOscPVT, pivL, pivR) : na


PLCondPVT = obvOscPVT < 0 ? ta.pivotlow(obvOscPVT, pivL, pivR) : na

obvOsc2PVT = ta.sma(obvOscPVT, 3)

crossoverCond1PVT = ta.crossunder(obvOscPVT, 0)
crossoverCond2PVT = ta.crossover(obvOscPVT, 0)

// DC Stoploss

setting5header = input(title='----------------DC Stoploss Settings----------------',


defval=false)

DClength = input.int(17, minval=1, title='Stoploss Lenght', tooltip='This setting


modifies the trailing stoploss')
DClower = ta.lowest(DClength)
DCupper = ta.highest(DClength)
DCbasis = math.avg(DCupper, DClower)
DCcolor1 = leadLine1 > leadLine2 ? color.new(color.silver, 60) : na
DCcolor2 = leadLine1 < leadLine2 ? color.new(color.silver, 60) : na
DCu = plot(DCupper, 'Stoploss Upper', color=DCcolor1)
DCl = plot(DClower, 'Stoploss Lower', color=DCcolor2)

//TSI
setting0header = input(title='----------------TSI Settings----------------',
defval=false)

long = input.int(title='TSI Long Length', defval=5, tooltip='These setting are used


for the bigger entry signal triangles')
short = input.int(title='TSI Short Length', defval=12, tooltip='These setting are
used for the bigger entry signal triangles')
signal = input.int(title='TSI Signal Length', defval=10, tooltip='These setting are
used for the bigger entry signal triangles')
treshold = input.int(title='Crossover treshold', defval=30, tooltip='This setting is
for the treshold, a higher number is going to print less but stronger signals ')
price = ohlc4
src2 = ohlc4
double_smooth(src2, long, short) =>
fist_smooth = ta.ema(src2, long)
ta.ema(fist_smooth, short)
pc = ta.change(price)
double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(math.abs(pc), long, short)
tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
tsi1 = tsi_value
tsi2 = ta.wma(tsi_value, signal)
data1 = tsi1 and tsi2 > treshold ? ta.crossunder(tsi1, tsi2) : na
data2 = tsi1 and tsi2 < -treshold ? ta.crossover(tsi1, tsi2) : na

//RSI Bands

setting1header = input(title='----------------RSI Bands Settings----------------',


defval=false)

obLevelRSI = input.int(70, title='RSI Bands Overbought', tooltip='These settings are


used for the white square that signals when an impulsive move ends')
osLevelRSI = input.int(30, title='RSI Bands Oversold', tooltip='These settings are
used for the white square that signals when an impulsive move ends')
lengthRSI = input.int(14, title='RSI Bands Length', tooltip='These settings are used
for the white square that signals when an impulsive move ends')
srcCU = input.source(close, title='RSI Band Cross Up Source', tooltip='These settings
are used for the white square that signals when an impulsive move ends')
srcCD = input.source(close, title='RSI Band Cross Down Source', tooltip='These
settings are used for the white square that signals when an impulsive move ends')
RSIMACross = input.int(title='RSI Band MA for Cross', defval=2, tooltip='These
settings are used for the white square that signals when an impulsive move ends')

epRSI = 2 * lengthRSI - 1
aucRSI = ta.ema(math.max(src - src[1], 0), epRSI)
adcRSI = ta.ema(math.max(src[1] - src, 0), epRSI)
x1RSI = (lengthRSI - 1) * (adcRSI * obLevelRSI / (100 - obLevelRSI) - aucRSI)
ubRSI = x1RSI >= 0 ? src + x1RSI : src + x1RSI * (100 - obLevelRSI) / obLevelRSI
x2RSI = (lengthRSI - 1) * (adcRSI * osLevelRSI / (100 - osLevelRSI) - aucRSI)
lbRSI = x2RSI >= 0 ? src + x2RSI : src + x2RSI * (100 - osLevelRSI) / osLevelRSI

plot(ubRSI, title='RSI Band Resistance', color=color.new(color.orange, 95),


linewidth=1)
plot(lbRSI, title='RSI Band Support', color=color.new(color.aqua, 95), linewidth=1)
plot(math.avg(ubRSI, lbRSI), title='RSI Band Midline', color=color.new(color.silver,
100), linewidth=1)

// Heiken Ashi Smoothed MA

setting19header = input(title='----------------Smoothed Heikin Ashi


Trend----------------', defval=false)

HAma1_len = input.int(26, title="Heikin Ashi MA 01")


HAma2_len = input.int(13, title="Heikin Ashi MA 02")

HAo=ta.ema(open,HAma1_len)
HAc=ta.ema(close,HAma1_len)
HAh=ta.ema(high,HAma1_len)
HAl=ta.ema(low,HAma1_len)

HAha_t = ticker.heikinashi(syminfo.tickerid)
HAha_o = request.security(HAha_t, timeframe.period, HAo)
HAha_c = request.security(HAha_t, timeframe.period, HAc)
HAha_h = request.security(HAha_t, timeframe.period, HAh)
HAha_l = request.security(HAha_t, timeframe.period, HAl)

HAo2=ta.ema(HAha_o, HAma2_len)
HAc2=ta.ema(HAha_c, HAma2_len)
HAh2=ta.ema(HAha_h, HAma2_len)
HAl2=ta.ema(HAha_l, HAma2_len)

ha_col=HAo2>HAc2 ? color.new(color.orange,0) : color.new(color.aqua,0)


ha_col2=HAo2>HAc2 ? color.new(color.orange,100) : color.new(color.aqua,100)

//plotcandle(HAo2, HAc2, title="Heikin Ashi Smoothed", color=ha_col)

testor1 = plot(HAo2, title='Heiken Ashi Open Candle', color=ha_col, linewidth=1,


style = plot.style_circles)
testor2 = plot(HAc2, title='Heiken Ashi Close Candle', color=ha_col, linewidth=1,
style= plot.style_circles)
plot(HAh2, title='Heiken Ashi High Wick', color=ha_col2, linewidth=1)
plot(HAl2, title='Heiken Ashi Low Wick', color=ha_col2, linewidth=1)

//fill(testor1,testor2, title='Heiken Ashi High Wick', color=ha_col)


//wolfpack id

setting2header = input(title='----------------Wolfpack ID Settings----------------',


defval=false)

input1 = input.int(title='Wolfpack Fast Length', defval=3, tooltip='These setting are


used for the smaller triangles that indicate a pivot point. This can be used as
secondary entry signal or in the opposite direction as take profit')
input2 = input.int(title='Wolfpack Slow Length', defval=8, tooltip='These setting are
used for the smaller triangles that indicate a pivot point. This can be used as
secondary entry signal or in the opposite direction as take profit')
pivRW = input.int(title='Wolfpack Wave Pivot Lookback Right', defval=1,
tooltip='These setting are used for the smaller triangles that indicate a pivot
point. This can be used as secondary entry signal or in the opposite direction as
take profit')
pivLW = input.int(title='Wolfpack Wave Pivot Lookback Left', defval=10,
tooltip='These setting are used for the smaller triangles that indicate a pivot
point. This can be used as secondary entry signal or in the opposite direction as
take profit')
fastmaa = ta.ema(close, input1)
fastmab = ta.ema(close, input2)
bspread = (fastmaa - fastmab) * 1.001
mmmm = bspread > 0 ? color.new(color.aqua, 0) : color.new(color.orange, 0)

PHCondW = bspread > 0 ? ta.pivothigh(bspread, pivLW, pivRW) : na


PLCondW = bspread < 0 ? ta.pivotlow(bspread, pivLW, pivRW) : na

//volume candles

setting3header = input(title='----------------Volume Candle


Settings----------------', defval=false)

lengthvolume = input.int(55, title='MA Volume Length', minval=2)


thresholdExtraHigh = input.float(4, title='Extra High Volume Threshold')
thresholdHigh = input(2.5, title='High Volume Threshold')
thresholdMedium = input.float(1, title='Medium Volume Threshold')
thresholdNormal = input(-0.5, title='Normal Volume Threshold')

mean = ta.sma(volume, lengthvolume)


std = ta.stdev(volume, lengthvolume)
stdbar = (volume - mean) / std

bcolor = stdbar > thresholdExtraHigh ? color.red : stdbar > thresholdHigh ?


color.orange : stdbar > thresholdMedium ? color.yellow : stdbar > thresholdNormal ?
color.white : color.aqua

barcolor(bcolor, title='Volume Candle Colors')


//pivots

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'

setting4header = input(title='----------------Pivots----------------', defval=false)

kind = input.string(title='Type', defval='Fibonacci', 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 = color.new(color.silver, 70)


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 r1 = array.new_float()
var s1 = array.new_float()
s1r1_show = input.bool(true, 'S1/R1', inline='S1/R1')
s1r1_color = input.color(DEF_COLOR, '', inline='S1/R1')

var r2 = array.new_float()
var s2 = array.new_float()
s2r2_show = input.bool(true, 'S2/R2', inline='S2/R2')
s2r2_color = input.color(DEF_COLOR, '', inline='S2/R2')

var r3 = array.new_float()
var s3 = array.new_float()
s3r3_show = input.bool(true, 'S3/R3', inline='S3/R3')
s3r3_color = input.color(DEF_COLOR, '', inline='S3/R3')

var r4 = array.new_float()
var s4 = array.new_float()
s4r4_show = input.bool(true, 'S4/R4', inline='S4/R4')
s4r4_color = input.color(DEF_COLOR, '', inline='S4/R4')

var r5 = array.new_float()
var s5 = array.new_float()
s5r5_show = input.bool(true, 'S5/R5', inline='S5/R5')
s5r5_color = input.color(DEF_COLOR, '', 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'
resolution
else if timeframe.isweekly or timeframe.ismonthly
resolution := '12M'
resolution
else if pivot_time_frame == DAILY
resolution := 'D'
resolution
else if pivot_time_frame == WEEKLY
resolution := 'W'
resolution
else if pivot_time_frame == MONTHLY
resolution := 'M'
resolution
else if pivot_time_frame == QUARTERLY
resolution := '3M'
resolution
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
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(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
pivotX_Demark_X
if pivotX_prev_close > pivotX_prev_open
pivotX_Demark_X := pivotX_prev_high * 2 + pivotX_prev_low + pivotX_prev_close
pivotX_Demark_X
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] = 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)

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 ta.change(time(resolution))
number_of_years := number_of_years + 1
if pivot_time_frame == BIYEARLY and number_of_years % 2 == 0
is_change_years := true
number_of_years := 0
number_of_years
else if pivot_time_frame == TRIYEARLY and number_of_years % 3 == 0
is_change_years := true
number_of_years := 0
number_of_years
else if pivot_time_frame == QUINQUENNIALLY and number_of_years % 5 == 0
is_change_years := true
number_of_years := 0
number_of_years
else if pivot_time_frame == DECENNIALLY and number_of_years % 10 == 0
is_change_years := true
number_of_years := 0
number_of_years

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 not custom_years_resolution or
is_change_years
if is_time_change
change_time := time
change_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
pivotX_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]
pivotX_prev_close

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
is_change
else
if is_daily_based
pivotX_high := math.max(pivotX_high, sec_high)
pivotX_low := math.min(pivotX_low, sec_low)
pivotX_low
else
pivotX_high := math.max(pivotX_high, high)
pivotX_low := math.min(pivotX_low, low)
pivotX_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 by 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 by 1
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)
if array.size(r2) > 0 and s2r2_show
draw_line(i, r2, s2r2_color)
draw_label(i, array.get(r2, i), 'R2', s2r2_color)
if array.size(s2) > 0 and s2r2_show
draw_line(i, s2, s2r2_color)
draw_label(i, array.get(s2, i), 'S2', s2r2_color)
if array.size(r3) > 0 and s3r3_show
draw_line(i, r3, s3r3_color)
draw_label(i, array.get(r3, i), 'R3', s3r3_color)
if array.size(s3) > 0 and s3r3_show
draw_line(i, s3, s3r3_color)
draw_label(i, array.get(s3, i), 'S3', s3r3_color)
if array.size(r4) > 0 and s4r4_show
draw_line(i, r4, s4r4_color)
draw_label(i, array.get(r4, i), 'R4', s4r4_color)
if array.size(s4) > 0 and s4r4_show
draw_line(i, s4, s4r4_color)
draw_label(i, array.get(s4, i), 'S4', s4r4_color)
if array.size(r5) > 0 and s5r5_show
draw_line(i, r5, s5r5_color)
draw_label(i, array.get(r5, i), 'R5', s5r5_color)
if array.size(s5) > 0 and s5r5_show
draw_line(i, s5, s5r5_color)
draw_label(i, array.get(s5, i), 'S5', s5r5_color)
//Pivot point settings

setting9header = input(title='----------------Pivot Points Settings----------------',


defval=false)

whatpivotIndicator = input.bool(title='OBV for Pivot Points?', tooltip='If unchecked


Wolfpack is used for Pivot Point caluculation', defval=true)

PHCondlul = whatpivotIndicator ? PHCond : PHCondW


PLCondlul = whatpivotIndicator ? PLCond : PLCondW

whatpivot = input.bool(title='OBV and Wolfpack Pivot Points Double Confirmation?',


tooltip='If unchecked either OBV or Wolfpack is used for Pivot Point caluculation',
defval=false)

pivotbothH = whatpivot ? PHCondW and PHCond : PHCondlul


pivotbothL = whatpivot ? PLCondW and PLCond : PLCondlul

//Plots

p1 = plot(leadLine1, color=color.new(color.aqua, 100), title='Long Trend MA')


p2 = plot(leadLine2, color=color.new(color.orange, 100), title='Short Trend MA')
fill(p1, p2, color=leadLine1 < leadLine2 ? color.new(color.aqua, 85) :
color.new(color.orange, 85), transp=90)

datasell = leadLine1 > leadLine2 and (tsi1 and tsi2 > treshold ? ta.crossunder(tsi1,
tsi2) : na)
databuy = leadLine1 < leadLine2 and (tsi1 and tsi2 < -treshold ? ta.crossover(tsi1,
tsi2) : na)

datastpbuy = leadLine1 > leadLine2 and (tsi1 and tsi2 < -treshold ?
ta.crossover(tsi1, tsi2) : na)
datatpsell = leadLine1 < leadLine2 and (tsi1 and tsi2 > treshold ?
ta.crossunder(tsi1, tsi2) : na)

rsibandcrossup = ta.crossover(ta.ema(srcCU, RSIMACross), lbRSI)


rsibandcrossdown = ta.crossunder(ta.ema(srcCD, RSIMACross), ubRSI)

//srclul = input(hl2, title='PVT Source')

//calcentry1 = (srclul > HAl2 and srclul < HAh2) and HAo2>HAc2 and leadLine1 >
leadLine2 ? pivotbothH : na
//calcentry2 = (srclul > HAl2 and srclul < HAh2) and HAo2<HAc2 and leadLine1 <
leadLine2 ? pivotbothL : na

//calcentry1 = (high > HAo2 and high > HAc2) and HAo2>HAc2 and leadLine1 > leadLine2
? pivotbothH : na
//calcentry2 = (low < HAo2 and low < HAc2) and HAo2<HAc2 and leadLine1 < leadLine2 ?
pivotbothL : na

//calcentry1 = (high > HAo2 and high > HAc2) and HAo2>HAc2 and leadLine1 > leadLine2
? PHCondPVT : na
//calcentry2 = (low < HAo2 and low < HAc2) and HAo2<HAc2 and leadLine1 < leadLine2 ?
PLCondPVT : na

//plotshape(calcentry1, title='Entry Suggestion Short', location=location.abovebar,


style=shape.circle, size=size.tiny, color=color.new(color.white, 00))
//plotshape(calcentry2, title='Entry Suggestion Long', location=location.belowbar,
style=shape.circle, size=size.tiny, color=color.new(color.white, 00))

plotshape(rsibandcrossup, title='RSI Band Cross Up', location=location.belowbar,


style=shape.square, size=size.auto, color=color.new(color.white, 00))
plotshape(rsibandcrossdown, title='RSI Band Cross Down', location=location.abovebar,
style=shape.square, size=size.auto, color=color.new(color.white, 00))

plotshape(datasell, title='Sell Signal', style=shape.triangledown, size=size.tiny,


location=location.abovebar, color=color.new(color.orange, 0))
plotshape(databuy, title='Buy Signal', style=shape.triangleup, size=size.tiny,
location=location.belowbar, color=color.new(color.aqua, 0))

plotshape(PHCondPVT, title='Pivot High', location=location.abovebar,


style=shape.triangledown, size=size.auto, color=color.new(color.purple, 00))
plotshape(PLCondPVT, title='Pivot Low', location=location.belowbar,
style=shape.triangleup, size=size.auto, color=color.new(color.purple, 00))

plotshape(pivotbothH, title='Pivot High', location=location.abovebar,


style=shape.triangledown, size=size.auto, color=color.new(color.orange, 00))
plotshape(pivotbothL, title='Pivot Low', location=location.belowbar,
style=shape.triangleup, size=size.auto, color=color.new(color.aqua, 00))

plotshape(hiddenBearCond, title='Hidden Bear Divergence', location=location.abovebar,


style=shape.labeldown, size=size.tiny, color=color.new(color.orange, 00))
plotshape(bearCond, title='Bear Divergence', location=location.abovebar,
style=shape.labeldown, size=size.tiny, color=color.new(color.red, 00))
plotshape(hiddenBullCond, title='Hidden Bull Divergence', location=location.belowbar,
style=shape.labelup, size=size.tiny, color=color.new(color.aqua, 00))
plotshape(bullCond, title='Bull Divergence', location=location.belowbar,
style=shape.labelup, size=size.tiny, color=color.new(color.green, 00))

//Alerts

wolfpackCond1 = ta.crossover(bspread, 0)
wolfpackCond2 = ta.crossunder(bspread, 0)
trendcond = ta.cross(leadLine1, leadLine2)
datasellcond = leadLine1 > leadLine2 and (tsi1 and tsi2 > treshold ?
ta.crossunder(tsi1, tsi2) : na)
databuycond = leadLine1 < leadLine2 and (tsi1 and tsi2 < -treshold ?
ta.crossover(tsi1, tsi2) : na)
datastpbuycond = leadLine1 > leadLine2 and (tsi1 and tsi2 < -treshold ?
ta.crossover(tsi1, tsi2) : na)
datatpsellcond = leadLine1 < leadLine2 and (tsi1 and tsi2 > treshold ?
ta.crossunder(tsi1, tsi2) : na)

alertcondition(rsibandcrossup, title='RSI Band Cross Up', message='RSI Band crossed


up {{ticker}}')
alertcondition(rsibandcrossdown, title='RSI Band Cross Down', message='RSI Band
crossed down {{ticker}}')
alertcondition(trendcond, title='Longtherm Trend Changed', message='Longtherm Trend
Changed {{ticker}}')
alertcondition(databuycond, title='Entry Signal Long', message='Long {{ticker}}')
alertcondition(datasellcond, title='Entry Signal Short', message='Short {{ticker}}')
alertcondition(datastpbuycond, title='Exit Signal Take Profit', message='Take Profit
{{ticker}}')
alertcondition(datatpsellcond, title='Exit Signal Take Profit', message='Take Profit
{{ticker}}')
alertcondition(wolfpackCond1, title='Wolfpack Bullish Cross', message='Wolfpack Id
bullish cross {{ticker}}')
alertcondition(wolfpackCond2, title='Wolfpack Bearish Cross', message='Wolfpack Id
bearish cross {{ticker}}')
alertcondition(pivotbothH, title='Pivot High', message='Pivot High {{ticker}}')
alertcondition(pivotbothL, title='Pivot Low', message='Pivot Low {{ticker}}')
alertcondition(crossoverCond1, title='OBV Crossed Up', message='OBV Cross Up
{{ticker}}')
alertcondition(crossoverCond2, title='OBV Crossed Down', message='OBV Cross Down
{{ticker}}')
alertcondition(bullCond, title='Bull Diversion', message='OBV Regular Bull Div
{{ticker}}')
alertcondition(bearCond, title='Bear Diversion', message='OBV Regular Bear Div
{{ticker}}')
alertcondition(hiddenBullCond, title='Hidden Bull Diversion', message='OBV Hidden
Bull Div {{ticker}}')
alertcondition(hiddenBearCond, title='Hidden Bear Diversion', message='OBV Hidden
Bear Div {{ticker}}')

You might also like