Professional Documents
Culture Documents
ViPeR MS BO
ViPeR MS BO
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
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)
tf = switch time_frame
"5m" => "5"
"15m" => "15"
"30m" => "30"
"1h" => "60"
"2h" => "120"
"4h" => "240"
"D" => "D"
=> timeframe.period
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)
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]
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_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]
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_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)
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]
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_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]
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_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] =
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())
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)
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
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
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)
//---------------------------------------------------------------------------------
----------------------
// 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)