You are on page 1of 13

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

0 at
https://mozilla.org/MPL/2.0/
// © velupandianravichandran

//@version=5
indicator('ViPeR Market Structure BO', overlay=true, max_lines_count=500,
max_bars_back=4900, max_boxes_count=500, format=format.price, precision=2)

// Change Log
// Add Auto Toggle for R/S Gann Levels
// Trama 89
// Vibration Levels from Yesterday Low

//------------------------------------------------------------------
showBASB = input(true,'Show Buy Above Sell Below Levels?', group="Dynamic
Levels")
showLevels = input(false,'Show Resistance/Support/Target Levels?', group="Dynamic
Levels")
showVib = input(true,'Show Vibration Levels?', group="Dynamic Levels")
// vibSource = input.string(title="Vibration Level Source", defval="open",
options=["open" "high", "low", "close"], group="Dynamic Levels")
//------------------------------------------------------------------
trama_length = input.int(89,"TRAMA Length",minval=1,group="TRAMA")
tramaSRC = input(close, "TRAMA Source", group="TRAMA")
//----
ama = 0.
hh = math.max(math.sign(ta.change(ta.highest(trama_length))), 0)
ll = math.max(math.sign(ta.change(ta.lowest(trama_length)) * -1), 0)
tc = math.pow(ta.sma(hh or ll ? 1 : 0, trama_length), 2)
ama := nz(ama[1] + tc * (tramaSRC - ama[1]), tramaSRC)
plot(ama, 'Plot', color.new(#ff1100, 0), 2)
//------------------------------------------------------------------
slopeLength = input.int(14)
k = input.float(1.,'Slope',minval=0,step=.1)
method = input.string('Atr','Slope Calculation Method',
options=['Atr','Stdev','Linreg'])
show = input(true,'Show Only Confirmed Breakouts')
//----
upper = 0.,lower = 0.
slope_ph = 0.,slope_pl = 0.
src = close
n = bar_index
//----
ph = ta.pivothigh(slopeLength,slopeLength)
pl = ta.pivotlow(slopeLength,slopeLength)
slope = switch method
'Atr' => ta.atr(slopeLength)/slopeLength*k
'Stdev' => ta.stdev(src,slopeLength)/slopeLength*k
'Linreg' => math.abs(ta.sma(src*bar_index,slopeLength)-
ta.sma(src,slopeLength)*ta.sma(bar_index,slopeLength))/ta.variance(n,slopeLength)/
2*k

slope_ph := ph ? slope : slope_ph[1]


slope_pl := pl ? slope : slope_pl[1]

upper := ph ? ph : upper[1] - slope_ph


lower := pl ? pl : lower[1] + slope_pl
//----
single_upper = 0
single_lower = 0
single_upper := src[slopeLength] > upper ? 0 : ph ? 1 : single_upper[1]
single_lower := src[slopeLength] < lower ? 0 : pl ? 1 : single_lower[1]
upper_breakout = single_upper[1] and src[slopeLength] > upper and (show ? src >
src[slopeLength] : 1)
lower_breakout = single_lower[1] and src[slopeLength] < lower and (show ? src <
src[slopeLength] : 1)
plotshape(upper_breakout ? low[slopeLength] : na,"Upper
Break",shape.labelup,location.absolute,#26a69a,-
slopeLength,text="B",textcolor=color.white,size=size.tiny)
plotshape(lower_breakout ? high[slopeLength] : na,"Lower
Break",shape.labeldown,location.absolute,#ef5350,-
slopeLength,text="S",textcolor=color.white,size=size.tiny)
//----
var line up_l = na
var line dn_l = na
var label recent_up_break = na
var label recent_dn_break = na

if ph[1]
line.delete(up_l[1])
label.delete(recent_up_break[1])

up_l := line.new(n-slopeLength-1,ph[1],n-slopeLength,upper,color=#26a69a,
extend=extend.right,style=line.style_dashed)
if pl[1]
line.delete(dn_l[1])
label.delete(recent_dn_break[1])

dn_l := line.new(n-slopeLength-1,pl[1],n-slopeLength,lower,color=#ef5350,
extend=extend.right,style=line.style_dashed)

if ta.crossover(src,upper-slope_ph*slopeLength)
label.delete(recent_up_break[1])
recent_up_break := label.new(n,low,'B',color=#26a69a,
textcolor=color.white,style=label.style_label_up,size=size.small)

if ta.crossunder(src,lower+slope_pl*slopeLength)
label.delete(recent_dn_break[1])
recent_dn_break := label.new(n,high,'B',color=#ef5350,
textcolor=color.white,style=label.style_label_down,size=size.small)

//----
plot(upper,'Upper',color = ph ? na : #26a69a,offset=-slopeLength)
plot(lower,'Lower',color = pl ? na : #ef5350,offset=-slopeLength)

alertcondition(ta.crossover(src,upper-slope_ph*slopeLength),'Upper Breakout','Price
broke upper trendline')
alertcondition(ta.crossunder(src,lower+slope_pl*slopeLength),'Lower
Breakout','Price broke lower trendline')
//------------------------------------------------------------------
settings = "Settings"
zigzag_len = input.int(9, "ZigZag Length", group=settings)
show_zigzag = input.bool(true, "Show Zigzag", group=settings)
fib_factor = input.float(0.33, "Fib Factor for breakout confirmation", 0, 1, 0.01,
group=settings)

tooltip_text = "Some timeframes may not be displayed in current timeframe. Zigzag


lines only shows in current timeframe."
time_frame= input.string("Chart", "Timeframe", ["Chart", "5m", "15m", "30m", "1h",
"2h", "4h", "D"], tooltip=tooltip_text)

tf = switch time_frame
"5m" => "5"
"15m" => "15"
"30m" => "30"
"1h" => "60"
"2h" => "120"
"4h" => "240"
"D" => "D"
=> timeframe.period

text_size = input.string(size.tiny, "Text Size", [size.tiny, size.small,


size.normal, size.large, size.huge])

bu_ob_inline_color = "Bu-OB Colors"


be_ob_inline_color = "Be-OB Colors"
bu_bb_inline_color = "Bu-BB Colors"
be_bb_inline_color = "Be-BB Colors"

bu_ob_display_settings = "Bu-OB Display Settings"


bu_ob_color = input.color(color.new(color.green, 70), "Color",
group=bu_ob_display_settings, inline=bu_ob_inline_color)
bu_ob_border_color = input.color(color.green, "Border Color",
group=bu_ob_display_settings, inline=bu_ob_inline_color)
bu_ob_text_color = input.color(color.green, "Text Color",
group=bu_ob_display_settings, inline=bu_ob_inline_color)

be_ob_display_settings = "Be-OB Display Settings"


be_ob_color = input.color(color.new(color.red, 70), "Color",
group=be_ob_display_settings, inline=be_ob_inline_color)
be_ob_border_color = input.color(color.red, "Border Color",
group=be_ob_display_settings, inline=be_ob_inline_color)
be_ob_text_color = input.color(color.red, "Text Color",
group=be_ob_display_settings, inline=be_ob_inline_color)

bu_bb_display_settings = "Bu-BB & Bu-MB Display Settings"


bu_bb_color = input.color(color.new(color.green, 70), "Color",
group=bu_bb_display_settings, inline=bu_bb_inline_color)
bu_bb_border_color = input.color(color.green, "Border Color",
group=bu_bb_display_settings, inline=bu_bb_inline_color)
bu_bb_text_color = input.color(color.green, "Text Color",
group=bu_bb_display_settings, inline=bu_bb_inline_color)

be_bb_display_settings = "Be-BB & Be-MB Display Settings"


be_bb_color = input.color(color.new(color.red, 70), "Color",
group=be_bb_display_settings, inline=be_bb_inline_color)
be_bb_border_color = input.color(color.red, "Border Color",
group=be_bb_display_settings, inline=be_bb_inline_color)
be_bb_text_color = input.color(color.red, "Text Color",
group=be_bb_display_settings, inline=be_bb_inline_color)

var float[] high_points_arr = array.new_float(5)


var int[] high_index_arr = array.new_int(5)
var float[] low_points_arr = array.new_float(5)
var int[] low_index_arr = array.new_int(5)
var box[] bu_ob_boxes = array.new_box(5)
var box[] be_ob_boxes = array.new_box(5)
var box[] bu_bb_boxes = array.new_box(5)
var box[] be_bb_boxes = array.new_box(5)

f_get_high(ind) =>
[array.get(high_points_arr, array.size(high_points_arr) - 1 - ind),
array.get(high_index_arr, array.size(high_index_arr) - 1 - ind)]

f_get_low(ind) =>
[array.get(low_points_arr, array.size(low_points_arr) - 1 - ind),
array.get(low_index_arr, array.size(low_index_arr) - 1 - ind)]

f_main1() =>
to_up = high >= ta.highest(zigzag_len)
to_down = low <= ta.lowest(zigzag_len)

trend = 1
trend := nz(trend[1], 1)
trend := trend == 1 and to_down ? -1 : trend == -1 and to_up ? 1 : trend

last_trend_up_since = ta.barssince(to_up[1])
low_val = ta.lowest(nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1))
low_index = bar_index - ta.barssince(low_val == low)

last_trend_down_since = ta.barssince(to_down[1])
high_val = ta.highest(nz(last_trend_down_since > 0 ? last_trend_down_since : 1,
1))
high_index = bar_index - ta.barssince(high_val == high)

if ta.change(trend) != 0
if trend == 1
array.push(low_points_arr, low_val)
array.push(low_index_arr, low_index)
if trend == -1
array.push(high_points_arr, high_val)
array.push(high_index_arr, high_index)

[h0, h0i] = f_get_high(0)


[h1, h1i] = f_get_high(1)

[l0, l0i] = f_get_low(0)


[l1, l1i] = f_get_low(1)

market = 1
market := nz(market[1], 1)
last_l0 = ta.valuewhen(ta.change(market) != 0, l0, 0)
last_h0 = ta.valuewhen(ta.change(market) != 0, h0, 0)
market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and
l0 < l1 - math.abs(h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 >
h1 + math.abs(h1 - l0) * fib_factor ? 1 : market

// For alert
alert_market = 1
alert_market := nz(alert_market[1], 1)
alert_market := last_l0 == l0 or last_h0 == h0 ? alert_market : alert_market ==
1 and trend == -1 and close < l0 and close < l0 - math.abs(h0 - l0) * fib_factor ?
-1 : alert_market == -1 and trend == 1 and close > h0 and close > h0 + math.abs(h0
- l0) * fib_factor ? 1 : alert_market
bu_ob_index = bar_index
bu_ob_index := nz(bu_ob_index[1], bar_index)
for i=h1i to l0i[zigzag_len]
index = bar_index - i
if open[index] > close[index]
bu_ob_index := bar_index[index]

bu_ob_since = bar_index - bu_ob_index

be_ob_index = bar_index
be_ob_index := nz(be_ob_index[1], bar_index)
for i=l1i to h0i[zigzag_len]
index = bar_index - i
if open[index] < close[index]
be_ob_index := bar_index[index]

be_ob_since = bar_index - be_ob_index

be_bb_index = bar_index
be_bb_index := nz(be_bb_index[1], bar_index)
for i=h1i - zigzag_len to l1i
index = bar_index - i
if open[index] > close[index]
be_bb_index := bar_index[index]

be_bb_since = bar_index - be_bb_index

bu_bb_index = bar_index
bu_bb_index := nz(bu_bb_index[1], bar_index)
for i=l1i - zigzag_len to h1i
index = bar_index - i
if open[index] < close[index]
bu_bb_index := bar_index[index]

bu_bb_since = bar_index - bu_bb_index

bu_ob_since_high = high[bu_ob_since]
bu_ob_since_low = low[bu_ob_since]
be_ob_since_high = high[be_ob_since]
be_ob_since_low = low[be_ob_since]
be_bb_since_high = high[be_bb_since]
be_bb_since_low = low[be_bb_since]
bu_bb_since_high = high[bu_bb_since]
bu_bb_since_low = low[bu_bb_since]

[trend, h0i, h0, l0i, l0, market, h1i, h1, l1i, l1, bu_ob_since_high,
bu_ob_since_low, be_ob_since_high, be_ob_since_low]

f_main2() =>
to_up = high >= ta.highest(zigzag_len)
to_down = low <= ta.lowest(zigzag_len)

trend = 1
trend := nz(trend[1], 1)
trend := trend == 1 and to_down ? -1 : trend == -1 and to_up ? 1 : trend
last_trend_up_since = ta.barssince(to_up[1])
low_val = ta.lowest(nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1))
low_index = bar_index - ta.barssince(low_val == low)

last_trend_down_since = ta.barssince(to_down[1])
high_val = ta.highest(nz(last_trend_down_since > 0 ? last_trend_down_since : 1,
1))
high_index = bar_index - ta.barssince(high_val == high)

if ta.change(trend) != 0
if trend == 1
array.push(low_points_arr, low_val)
array.push(low_index_arr, low_index)
if trend == -1
array.push(high_points_arr, high_val)
array.push(high_index_arr, high_index)

[h0, h0i] = f_get_high(0)


[h1, h1i] = f_get_high(1)

[l0, l0i] = f_get_low(0)


[l1, l1i] = f_get_low(1)

market = 1
market := nz(market[1], 1)
last_l0 = ta.valuewhen(ta.change(market) != 0, l0, 0)
last_h0 = ta.valuewhen(ta.change(market) != 0, h0, 0)
market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and
l0 < l1 - math.abs(h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 >
h1 + math.abs(h1 - l0) * fib_factor ? 1 : market

// For alert
alert_market = 1
alert_market := nz(alert_market[1], 1)
alert_market := last_l0 == l0 or last_h0 == h0 ? alert_market : alert_market ==
1 and trend == -1 and close < l0 and close < l0 - math.abs(h0 - l0) * fib_factor ?
-1 : alert_market == -1 and trend == 1 and close > h0 and close > h0 + math.abs(h0
- l0) * fib_factor ? 1 : alert_market

bu_ob_index = bar_index
bu_ob_index := nz(bu_ob_index[1], bar_index)
for i=h1i to l0i[zigzag_len]
index = bar_index - i
if open[index] > close[index]
bu_ob_index := bar_index[index]

bu_ob_since = bar_index - bu_ob_index

be_ob_index = bar_index
be_ob_index := nz(be_ob_index[1], bar_index)
for i=l1i to h0i[zigzag_len]
index = bar_index - i
if open[index] < close[index]
be_ob_index := bar_index[index]

be_ob_since = bar_index - be_ob_index

be_bb_index = bar_index
be_bb_index := nz(be_bb_index[1], bar_index)
for i=h1i - zigzag_len to l1i
index = bar_index - i
if open[index] > close[index]
be_bb_index := bar_index[index]

be_bb_since = bar_index - be_bb_index

bu_bb_index = bar_index
bu_bb_index := nz(bu_bb_index[1], bar_index)
for i=l1i - zigzag_len to h1i
index = bar_index - i
if open[index] < close[index]
bu_bb_index := bar_index[index]

bu_bb_since = bar_index - bu_bb_index

bu_ob_since_high = high[bu_ob_since]
bu_ob_since_low = low[bu_ob_since]
be_ob_since_high = high[be_ob_since]
be_ob_since_low = low[be_ob_since]
be_bb_since_high = high[be_bb_since]
be_bb_since_low = low[be_bb_since]
bu_bb_since_high = high[bu_bb_since]
bu_bb_since_low = low[bu_bb_since]

[alert_market, be_bb_since_high, be_bb_since_low, bu_bb_since_high,


bu_bb_since_low, bu_ob_index, bu_bb_index, be_ob_index, be_bb_index]

[trend, h0i, h0, l0i, l0, market, h1i, h1, l1i, l1, bu_ob_since_high,
bu_ob_since_low, be_ob_since_high, be_ob_since_low] =
request.security(syminfo.tickerid, tf, f_main1())
[alert_market, be_bb_since_high, be_bb_since_low, bu_bb_since_high,
bu_bb_since_low, bu_ob_index, bu_bb_index, be_ob_index, be_bb_index] =
request.security(syminfo.tickerid, tf, f_main2())

// Be_bb_since olanlar değişecek be_ob_index ler eklenecek

if ta.change(trend) != 0 and show_zigzag


if trend == 1
line.new(h0i, h0, l0i, l0)
if trend == -1
line.new(l0i, l0, h0i, h0)

if ta.change(market) != 0
if market == 1
line.new(h1i, h1, h0i, h1, color=color.green, width=2)
label.new(int(math.avg(h1i, l0i)), h1, "MSB", color=color.new(color.black,
100), style=label.style_label_down, textcolor=color.green, size=size.small)
bu_ob = box.new(bu_ob_index, bu_ob_since_high, bar_index + 10,
bu_ob_since_low, bgcolor=bu_ob_color, border_color=bu_ob_border_color, text="Bu-
OB", text_color=bu_ob_text_color, text_halign=text.align_right,
text_size=text_size)
bu_bb = box.new(bu_bb_index, bu_bb_since_high, bar_index + 10,
bu_bb_since_low, bgcolor=bu_bb_color, border_color=bu_bb_border_color, text=l0 < l1
? "Bu-BB" : "Bu-MB", text_color=bu_bb_text_color, text_halign=text.align_right,
text_size=text_size)
array.push(bu_ob_boxes, bu_ob)
array.push(bu_bb_boxes, bu_bb)
if market == -1
line.new(l1i, l1, l0i, l1, color=color.red, width=2)
label.new(int(math.avg(l1i, h0i)), l1, "MSB", color=color.new(color.black,
100), style=label.style_label_up, textcolor=color.red, size=size.small)
be_ob = box.new(be_ob_index, be_ob_since_high, bar_index + 10,
be_ob_since_low, bgcolor=be_ob_color, border_color=be_ob_border_color, text="Be-
OB", text_color=be_ob_text_color, text_halign=text.align_right,
text_size=text_size)
be_bb = box.new(be_bb_index, be_bb_since_high, bar_index + 10,
be_bb_since_low, bgcolor=be_bb_color, border_color=be_bb_border_color, text=h0 > h1
? "Be-BB" : "Be-MB", text_color=be_bb_text_color, text_halign=text.align_right,
text_size=text_size)
array.push(be_ob_boxes, be_ob)
array.push(be_bb_boxes, be_bb)

for bull_ob in bu_ob_boxes


bottom = box.get_bottom(bull_ob)
if close < bottom
box.delete(bull_ob)
else if array.size(bu_ob_boxes) == 5
box.delete(array.shift(bu_ob_boxes))
else
box.set_right(bull_ob, bar_index + 10)

for bear_ob in be_ob_boxes


top = box.get_top(bear_ob)
if close > top
box.delete(bear_ob)
else if array.size(be_ob_boxes) == 5
box.delete(array.shift(be_ob_boxes))
else
box.set_right(bear_ob, bar_index + 10)

for bear_bb in be_bb_boxes


top = box.get_top(bear_bb)
if close > top
box.delete(bear_bb)
else if array.size(be_bb_boxes) == 5
box.delete(array.shift(be_bb_boxes))
else
box.set_right(bear_bb, bar_index + 10)

for bull_bb in bu_bb_boxes


bottom = box.get_bottom(bull_bb)
if close < bottom
box.delete(bull_bb)
else if array.size(bu_bb_boxes) == 5
box.delete(array.shift(bu_bb_boxes))
else
box.set_right(bull_bb, bar_index + 10)

if ta.change(alert_market) != 0
alert("MSB", alert.freq_once_per_bar)
//---------------------------------------------------------------------------------
-------------
// GANN Levels
var totLn = 0.0
var totLnSqr = 0.0
var lnAvg = 0.0
var lnSqrAvg = 0.0
var variance = 0.0
var dailyVolatility = 0.0
var price = 0.0
var priceRange = 0.0

oPeN = request.security(syminfo.tickerid, 'D', open,


lookahead=barmerge.lookahead_on)
prevHigh = request.security(syminfo.tickerid, 'D', high[1],
lookahead=barmerge.lookahead_on)
prevLow = request.security(syminfo.tickerid, 'D', low[1],
lookahead=barmerge.lookahead_on)
prevCloSe = request.security(syminfo.tickerid, 'D', close[1],
lookahead=barmerge.lookahead_on)

lowerTimeframe = timeframe.period == '1' or timeframe.period == '2' or


timeframe.period == '3' or timeframe.period == '5' or timeframe.period == '10' or
timeframe.period == '15'

c1 = oPeN > prevHigh or oPeN < prevLow ? oPeN : request.security(syminfo.tickerid,


'D', close[1], lookahead=barmerge.lookahead_on)
c2 = request.security(syminfo.tickerid, 'D', close[2],
lookahead=barmerge.lookahead_on)
c3 = request.security(syminfo.tickerid, 'D', close[3],
lookahead=barmerge.lookahead_on)
c4 = request.security(syminfo.tickerid, 'D', close[4],
lookahead=barmerge.lookahead_on)
c5 = request.security(syminfo.tickerid, 'D', close[5],
lookahead=barmerge.lookahead_on)
c6 = request.security(syminfo.tickerid, 'D', close[6],
lookahead=barmerge.lookahead_on)
c7 = request.security(syminfo.tickerid, 'D', close[7],
lookahead=barmerge.lookahead_on)
c8 = request.security(syminfo.tickerid, 'D', close[8],
lookahead=barmerge.lookahead_on)
c9 = request.security(syminfo.tickerid, 'D', close[9],
lookahead=barmerge.lookahead_on)
c10 = request.security(syminfo.tickerid, 'D', close[10],
lookahead=barmerge.lookahead_on)

truncate(number, decimals) =>


factor = math.pow(10, decimals)
int(number * factor) / factor

calculateLN() =>
tot = 0.0
tot := math.log(c1 / c2) + math.log(c2 / c3) + math.log(c3 / c4) +
math.log(c4 / c5) + math.log(c5 / c6) + math.log(c6 / c7) + math.log(c7 / c8) +
math.log(c8 / c9) + math.log(c9 / c10)
tot

calculateLNSquare() =>
tot = 0.0
tot := math.pow(math.log(c1 / c2), 2) + math.pow(math.log(c2 / c3), 2) +
math.pow(math.log(c3 / c4), 2) + math.pow(math.log(c4 / c5), 2) +
math.pow(math.log(c5 / c6), 2) + math.pow(math.log(c6 / c7), 2) +
math.pow(math.log(c7 / c8), 2) + math.pow(math.log(c8 / c9), 2) +
math.pow(math.log(c9 / c10), 2)
tot

calculatePivot() =>
(prevHigh + prevLow + prevCloSe) / 3

degreeFactor(angle) =>
if angle == 1
3.75 / 180
else
if angle == 2
7.5 / 180
else
if angle == 3
15.00 / 180
else
if angle == 4
18.75 / 180
else
if angle == 5
26.25 / 180
else
if angle == 6
45.00 / 180
else
if angle == 7
63.75 / 180
else
if angle == 8
71.25 / 180
else
if angle == 9
75.00 / 180
else
if angle == 10
82.50 / 180
else
86.25 / 180

getCycleLevels(cycleNo, prevCycleHigh, prevCycleLow, pRange) =>


if cycleNo == 1
buyAbove = math.pow(math.sqrt(pRange) + degreeFactor(3), 2) *
degreeFactor(3) + prevCycleHigh
majorResistance = math.pow(math.sqrt(pRange) + degreeFactor(6), 2) *
degreeFactor(6) + prevCycleHigh
buyTarget = math.pow(math.sqrt(pRange) + degreeFactor(11), 2) *
degreeFactor(11) + prevCycleHigh
sellBelow = prevCycleHigh - math.pow(math.sqrt(pRange) - degreeFactor(3),
2) * degreeFactor(3)
majorSupport = prevCycleHigh - math.pow(math.sqrt(pRange) -
degreeFactor(6), 2) * degreeFactor(6)
sellTarget = prevCycleHigh - math.pow(math.sqrt(pRange) - degreeFactor(11),
2) * degreeFactor(11)
[buyAbove, majorResistance, buyTarget, sellBelow, majorSupport, sellTarget]
else
majorResistance = math.pow(math.sqrt(pRange) + degreeFactor(6), 2) *
degreeFactor(6) + prevCycleHigh
buyTarget = math.pow(math.sqrt(pRange) + degreeFactor(11), 2) *
degreeFactor(11) + prevCycleHigh
majorSupport = prevCycleLow - math.pow(math.sqrt(pRange) - degreeFactor(6),
2) * degreeFactor(6)
sellTarget = prevCycleLow - math.pow(math.sqrt(pRange) - degreeFactor(11),
2) * degreeFactor(11)
[majorResistance, buyTarget, majorSupport, sellTarget, 0.0, 0.0]

pivot = calculatePivot()

totLn := calculateLN()
totLnSqr := calculateLNSquare()
lnAvg := totLn / 9
lnSqrAvg := totLnSqr / 9
variance := lnSqrAvg - math.pow(lnAvg, 2)
dailyVolatility := math.sqrt(variance)
price := c1
priceRange := dailyVolatility * price

//Cycle One
[buyAbove, majorResistane1, buytarget1, sellBelow, majorSupport1, sellTarget1] =
getCycleLevels(1, price, 0.0, priceRange)

//Cycle Tw0
[majorResistane2, buytarget2, majorSupport2, sellTarget2, dummy1, dummy2] =
getCycleLevels(2, buytarget1, sellTarget1, priceRange)

//Cycle Three
[majorResistane3, buytarget3, majorSupport3, sellTarget3, dummy3, dummy4] =
getCycleLevels(3, buytarget2, sellTarget2, priceRange)

//Cycle Four
[majorResistane4, buytarget4, majorSupport4, sellTarget4, dummy5, dummy6] =
getCycleLevels(4, buytarget3, sellTarget3, priceRange)

//Cycle Five
[majorResistane5, buytarget5, majorSupport5, sellTarget5, dummy7, dummy8] =
getCycleLevels(5, buytarget4, sellTarget4, priceRange)

plot(series=lowerTimeframe and showBASB ? buyAbove : na, title='Buy Above',


color=pivot[1] != pivot and lowerTimeframe ? na : color.lime,
style=plot.style_linebr, linewidth=2, transp=0)
plot(series=lowerTimeframe and showBASB ? sellBelow : na, title='Sell Below',
color=pivot[1] != pivot and lowerTimeframe ? na : color.red,
style=plot.style_linebr, linewidth=2, transp=0)

plot(series=lowerTimeframe and showLevels ? majorResistane1 : na, title='Major


Resistance1', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? buytarget1 : na, title='TGT1',
color=pivot[1] != pivot and lowerTimeframe ? na : color.green,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorSupport1 : na, title='Major
Support1', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? sellTarget1 : na, title='TGT1',
color=pivot[1] != pivot and lowerTimeframe ? na : color.red,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorResistane2 : na, title='Major
Resistance2', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? buytarget2 : na, title='TGT2',
color=pivot[1] != pivot and lowerTimeframe ? na : color.green,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorSupport2 : na, title='Major
Support2', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? sellTarget2 : na, title='TGT2',
color=pivot[1] != pivot and lowerTimeframe ? na : color.red,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorResistane3 : na, title='Major
Resistance3', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? buytarget3 : na, title='TGT3',
color=pivot[1] != pivot and lowerTimeframe ? na : color.green,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorSupport3 : na, title='Major
Support3', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? sellTarget3 : na, title='TGT3',
color=pivot[1] != pivot and lowerTimeframe ? na : color.red,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorResistane4 : na, title='Major
Resistance4', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? buytarget4 : na, title='TGT4',
color=pivot[1] != pivot and lowerTimeframe ? na : color.green,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorSupport4 : na, title='Major
Support4', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? sellTarget4 : na, title='TGT4',
color=pivot[1] != pivot and lowerTimeframe ? na : color.red,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorResistane5 : na, title='Major
Resistance5', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? buytarget5 : na, title='TGT5',
color=pivot[1] != pivot and lowerTimeframe ? na : color.green,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? majorSupport5 : na, title='Major
Support5', color=pivot[1] != pivot and lowerTimeframe ? na : color.gray,
style=plot.style_linebr, linewidth=1, transp=0)
plot(series=lowerTimeframe and showLevels ? sellTarget5 : na, title='TGT5',
color=pivot[1] != pivot and lowerTimeframe ? na : color.red,
style=plot.style_linebr, linewidth=1, transp=0)

//---------------------------------------------------------------------------------
----------------------
// Vibreation Numbers
to_d = request.security(syminfo.tickerid, 'D', open[1], barmerge.gaps_off,
barmerge.lookahead_on)
th_d = request.security(syminfo.tickerid, 'D', high[1], barmerge.gaps_off,
barmerge.lookahead_on)
tl_d = request.security(syminfo.tickerid, 'D', low[1], barmerge.gaps_off,
barmerge.lookahead_on)
tc_d = request.security(syminfo.tickerid, 'D', close[1], barmerge.gaps_off,
barmerge.lookahead_on)
oTime = timestamp(year,month,dayofmonth,00,00)
cTime = timestamp(year,month,dayofmonth,24,00)

len1 = tl_d

// if(vibSource == "open")
// len1 := to_d
// if(vibSource == "high")
// len1 := th_d
// if(vibSource == "low")
// len1 := tl_d
// if(vibSource == "close")
// len1 := tc_d

sqr = math.sqrt(len1)
isqr = int(sqr)
vibl1 = (isqr - 2) * (isqr - 2)
vibl2 = (isqr - 1) * (isqr - 1)
vibl3m180 = (isqr - 0.5) * (isqr - 0.5)
vibl3 = isqr * isqr
vibl3p180 = (isqr + 0.5) * (isqr + 0.5)
vibl4 = (isqr + 1) * (isqr + 1)
vibl5 = (isqr + 2) * (isqr + 2)
vibl6 = (isqr - 3) * (isqr - 3)
vibl7 = (isqr - 4) * (isqr - 4)

vibl1_line = showVib ? line.new(oTime, vibl1, cTime, vibl1, xloc=xloc.bar_time,


color=color.red, extend=extend.both, style=line.style_solid, width=2) : na
vibl2_line = showVib ? line.new(oTime, vibl2, cTime, vibl2, xloc=xloc.bar_time,
color=color.red, extend=extend.both, style=line.style_solid, width=2) : na
vibl3_line = showVib ? line.new(oTime, vibl3, cTime, vibl3, xloc=xloc.bar_time,
color=color.red, extend=extend.both, style=line.style_solid, width=2) : na
vibl3m180_line = showVib ? line.new(oTime, vibl3m180, cTime, vibl3m180,
xloc=xloc.bar_time, color=color.maroon, extend=extend.both, style=line.style_solid,
width=2) : na
vibl3p180_line = showVib ? line.new(oTime, vibl3p180, cTime, vibl3p180,
xloc=xloc.bar_time, color=color.maroon, extend=extend.both, style=line.style_solid,
width=2) : na
vibl4_line = showVib ? line.new(oTime, vibl4, cTime, vibl4, xloc=xloc.bar_time,
color=color.red, extend=extend.both, style=line.style_solid, width=2) : na
vibl5_line = showVib ? line.new(oTime, vibl5, cTime, vibl5, xloc=xloc.bar_time,
color=color.red, extend=extend.both, style=line.style_solid, width=2) : na
vibl6_line = showVib ? line.new(oTime, vibl6, cTime, vibl6, xloc=xloc.bar_time,
color=color.red, extend=extend.both, style=line.style_solid, width=2) : na
vibl7_line = showVib ? line.new(oTime, vibl7, cTime, vibl7, xloc=xloc.bar_time,
color=color.red, extend=extend.both, style=line.style_solid, width=2) : na

You might also like