You are on page 1of 7

//@version=4

study(title="The Shelby indictor", overlay=true)


pivottimeframe = input(title="Pivot Resolution", defval="D", options=["D", "W",
"M"])
dp = input(true, title="Show Floor Pivots")
cp = input(true, title="Show Camarilla Pivots")
hl = input(true, title="Show M, W, D Highs/Lows")

//dp in the prefix implies daily pivot calculation


dpopen = security(syminfo.tickerid, pivottimeframe, open[1], barmerge.gaps_off,
barmerge.lookahead_on)
dphigh = security(syminfo.tickerid, pivottimeframe, high[1], barmerge.gaps_off,
barmerge.lookahead_on)
dplow = security(syminfo.tickerid, pivottimeframe, low[1], barmerge.gaps_off,
barmerge.lookahead_on)
dpclose = security(syminfo.tickerid, pivottimeframe, close[1], barmerge.gaps_off,
barmerge.lookahead_on)
dprange = dphigh - dplow

//Expanded Floor Pivots Formula


pivot = (dphigh + dplow + dpclose) / 3.0
bc = (dphigh + dplow) / 2.0
tc = pivot - bc + pivot

//Expanded Camarilla Pivots Formula


h3 = dpclose + dprange * (1.1 / 4)
h4 = dpclose + dprange * (1.1 / 2)
h5 = dphigh / dplow * dpclose
l3 = dpclose - dprange * (1.1 / 4)
l4 = dpclose - dprange * (1.1 / 2)
l5 = dpclose - (h5 - dpclose)

//m,w,d in the prefix implies monthly, weekly and daily


mhigh = security(syminfo.tickerid, "M", high[1], lookahead=barmerge.lookahead_on)
mlow = security(syminfo.tickerid, "M", low[1], lookahead=barmerge.lookahead_on)
whigh = security(syminfo.tickerid, "W", high[1], lookahead=barmerge.lookahead_on)
wlow = security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)
dhigh = security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
dlow = security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
//dclose = security(tickerid, "D", close[1], lookahead=barmerge.lookahead_on)

//Plotting
plot(dp and tc ? (tc >= bc ? tc : bc) : na, title="TC", color=tc != tc[1] ? na :
color.black, transp=0)
plot(dp and pivot ? pivot : na, title="Pivot", color=pivot != pivot[1] ? na :
color.black, transp=0)
plot(dp and bc ?(tc >= bc ? bc : tc) : na, title="BC", color=bc != bc[1] ? na :
color.black, transp=0)
plot(cp and h5 ? h5 : na, title="H5", color=h5 != h5[2] ? na : color.black,
transp=0)
plot(cp and h4 ? h4 : na, title="H4", color=h4 != h4[2] ? na : color.black,
transp=0)
plot(cp and h3 ? h3 : na, title="H3", color=h3 != h3[2] ? na : color.black,
transp=0)
plot(cp and l3 ? l3 : na, title="L3", color=l3 != l3[2] ? na : color.black,
transp=0)
plot(cp and l4 ? l4 : na, title="L4", color=l4 != l4[2] ? na : color.black,
transp=0)
plot(cp and l5 ? l5 : na, title="L5", color=l5 != l5[2] ? na : color.black,
transp=0)

plot((timeframe.isintraday or timeframe.isdaily or timeframe.isweekly) and hl ?


mhigh : na, title="Monthly High", style=plot.style_circles, color=#FF7F00,
transp=0)
plot((timeframe.isintraday or timeframe.isdaily or timeframe.isweekly) and hl ?
mlow : na, title="Monthly Low", style=plot.style_circles, color=#FF7F00, transp=0)
plot((timeframe.isintraday or timeframe.isdaily) and hl ? whigh : na, title="Weekly
High", style=plot.style_circles, color=#FF7F00, transp=0)
plot((timeframe.isintraday or timeframe.isdaily) and hl ? wlow : na, title="Weekly
Low", style=plot.style_circles, color=#FF7F00, transp=0)
plot(timeframe.isintraday and hl ? dhigh : na, title="PDH",
style=plot.style_circles, color=#FF7F00, transp=0)
plot(timeframe.isintraday and hl ? dlow : na, title="PDL",
style=plot.style_circles, color=#FF7F00, transp=0)
//plot(isintraday and hl ? dclose : na, title="Daily Close",style=circles,
color=#FF7F00, transp=0)
// ||-- Inputs:
session_timeframe = input("D" , options = ["D" , "W" , "M"])
percent_of_tpo = input(0.70)
tf_high = high
tf_low = low
tf_close = close
// ||-- Bars since session started:
session_bar_counter = bar_index - valuewhen(change(time(session_timeframe)) != 0,
bar_index, 0)
//plot(session_bar_counter)
// ||-- session high, low, range:
session_high = tf_high
session_low = tf_low
session_range = tf_high - tf_low

session_high := nz(session_high[1], tf_high)


session_low := nz(session_low[1], tf_low)
session_range := nz(session_high - session_low, 0.0)

// ||-- recalculate session high, low and range:


if session_bar_counter == 0
session_high := tf_high
session_low := tf_low
session_range := tf_high - tf_low
session_range
if tf_high > session_high[1]
session_high := tf_high
session_range := session_high - session_low
session_range
if tf_low < session_low[1]
session_low := tf_low
session_range := session_high - session_low
session_range
//plot(series=session_high, title='Session High', color=blue)
//plot(series=session_low, title='Session Low', color=blue)
//plot(series=session_range, title='Session Range', color=black)
// ||-- define tpo section range:
tpo_section_range = session_range / 21
// ||-- function to get the frequency a specified range is visited:
f_frequency_of_range(_src, _upper_range, _lower_range, _length) =>
_adjusted_length = _length < 1 ? 1 : _length
_frequency = 0
for _i = 0 to _adjusted_length - 1 by 1
if _src[_i] >= _lower_range and _src[_i] <= _upper_range
_frequency := _frequency + 1
_frequency
_return = nz(_frequency, 0) // _adjusted_length
_return
// ||-- frequency the tpo range is visited:
tpo_00 = f_frequency_of_range(tf_close, session_high, session_high -
tpo_section_range * 1, session_bar_counter)
tpo_01 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 1,
session_high - tpo_section_range * 2, session_bar_counter)
tpo_02 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 2,
session_high - tpo_section_range * 3, session_bar_counter)
tpo_03 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 3,
session_high - tpo_section_range * 4, session_bar_counter)
tpo_04 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 4,
session_high - tpo_section_range * 5, session_bar_counter)
tpo_05 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 5,
session_high - tpo_section_range * 6, session_bar_counter)
tpo_06 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 6,
session_high - tpo_section_range * 7, session_bar_counter)
tpo_07 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 7,
session_high - tpo_section_range * 8, session_bar_counter)
tpo_08 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 8,
session_high - tpo_section_range * 9, session_bar_counter)
tpo_09 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 9,
session_high - tpo_section_range * 10, session_bar_counter)
tpo_10 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 10,
session_high - tpo_section_range * 11, session_bar_counter)
tpo_11 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 11,
session_high - tpo_section_range * 12, session_bar_counter)
tpo_12 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 12,
session_high - tpo_section_range * 13, session_bar_counter)
tpo_13 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 13,
session_high - tpo_section_range * 14, session_bar_counter)
tpo_14 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 14,
session_high - tpo_section_range * 15, session_bar_counter)
tpo_15 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 15,
session_high - tpo_section_range * 16, session_bar_counter)
tpo_16 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 16,
session_high - tpo_section_range * 17, session_bar_counter)
tpo_17 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 17,
session_high - tpo_section_range * 18, session_bar_counter)
tpo_18 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 18,
session_high - tpo_section_range * 19, session_bar_counter)
tpo_19 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 19,
session_high - tpo_section_range * 20, session_bar_counter)
tpo_20 = f_frequency_of_range(tf_close, session_high - tpo_section_range * 20,
session_high - tpo_section_range * 21, session_bar_counter)
// ||-- function to retrieve a specific tpo value
f_get_tpo_count_1(_value) =>
_return = 0.0
if _value == 0
_return := tpo_00
_return
if _value == 1
_return := tpo_01
_return
if _value == 2
_return := tpo_02
_return
if _value == 3
_return := tpo_03
_return
if _value == 4
_return := tpo_04
_return
if _value == 5
_return := tpo_05
_return
if _value == 6
_return := tpo_06
_return
if _value == 7
_return := tpo_07
_return
if _value == 8
_return := tpo_08
_return
if _value == 9
_return := tpo_09
_return
if _value == 10
_return := tpo_10
_return
if _value == 11
_return := tpo_11
_return
if _value == 12
_return := tpo_12
_return
if _value == 13
_return := tpo_13
_return
if _value == 14
_return := tpo_14
_return
if _value == 15
_return := tpo_15
_return
if _value == 16
_return := tpo_16
_return
if _value == 17
_return := tpo_17
_return
if _value == 18
_return := tpo_18
_return
if _value == 19
_return := tpo_19
_return
if _value == 20
_return := tpo_20
_return
_return
f_get_tpo_count_2(_value) =>
_return = 0.0
if _value == 0
_return := tpo_00
_return
if _value == 1
_return := tpo_01
_return
if _value == 2
_return := tpo_02
_return
if _value == 3
_return := tpo_03
_return
if _value == 4
_return := tpo_04
_return
if _value == 5
_return := tpo_05
_return
if _value == 6
_return := tpo_06
_return
if _value == 7
_return := tpo_07
_return
if _value == 8
_return := tpo_08
_return
if _value == 9
_return := tpo_09
_return
if _value == 10
_return := tpo_10
_return
if _value == 11
_return := tpo_11
_return
if _value == 12
_return := tpo_12
_return
if _value == 13
_return := tpo_13
_return
if _value == 14
_return := tpo_14
_return
if _value == 15
_return := tpo_15
_return
if _value == 16
_return := tpo_16
_return
if _value == 17
_return := tpo_17
_return
if _value == 18
_return := tpo_18
_return
if _value == 19
_return := tpo_19
_return
if _value == 20
_return := tpo_20
_return
_return

tpo_sum = 0.0
current_poc_position = 0.0
current_poc_value = 0.0
for _i = 0 to 20 by 1
_get_tpo_value = f_get_tpo_count_1(_i)
tpo_sum := tpo_sum + _get_tpo_value
if _get_tpo_value > current_poc_value
current_poc_position := _i
current_poc_value := _get_tpo_value
current_poc_value
//plot(series=tpo_sum, title='tpo_sum', color=red)
poc_upper = session_high - tpo_section_range * current_poc_position
poc_lower = session_high - tpo_section_range * (current_poc_position + 1)
//plot(series=poc_upper, title='POC Upper', color=black)
//plot(series=poc_lower, title='POC Lower', color=black)
//plot(series=current_poc_position, title='current_poc_position', color=blue)
//plot(series=current_poc_value, title='current_poc_value', color=blue)

// ||-- get value area high/low


vah_position = current_poc_position
val_position = current_poc_position
current_sum = current_poc_value

for _i = 0 to 20 by 1
if current_sum < tpo_sum * percent_of_tpo
vah_position := max(0, vah_position - 1)
current_sum := current_sum + f_get_tpo_count_2(round(vah_position))
current_sum
if current_sum < tpo_sum * percent_of_tpo
val_position := min(20, val_position + 1)
current_sum := current_sum + f_get_tpo_count_2(round(val_position))
current_sum

vah_value = session_high - tpo_section_range * vah_position


val_value = session_high - tpo_section_range * (val_position + 1)

//plot(series=vah_value, title='VAH', color=color.navy)


//plot(series=val_value, title='VAL', color=color.navy)
//plot(series=current_sum, title='SUM', color=color.red)
//plot(series=valuewhen(session_bar_counter == 0, vah_value[1], 0), title='VAH',
color=color.navy, trackprice=true, offset=1, show_last=1)
//plot(series=valuewhen(session_bar_counter == 0, val_value[1], 0), title='VAL',
color=color.navy, trackprice=true, offset=1, show_last=1)

f_gapper(_return_value) =>
_return = _return_value
if session_bar_counter == 0
_return := na
_return
_return

plot(series=f_gapper(valuewhen(session_bar_counter == 0, vah_value[1], 0)),


title='VAH', color=color.green, linewidth=2, style=plot.style_linebr, transp=0)
plot(series=f_gapper(valuewhen(session_bar_counter == 0, val_value[1], 0)),
title='VAL', color=color.red, linewidth=2, style=plot.style_linebr, transp=0)
plot(series=f_gapper(valuewhen(session_bar_counter == 0, poc_upper[1], 0)),
title='POC Upper', color=color.black, linewidth=2, style=plot.style_linebr,
transp=0)
plot(series=f_gapper(valuewhen(session_bar_counter == 0, poc_lower[1], 0)),
title='POC Lower', color=color.black, linewidth=2, style=plot.style_linebr,
transp=0)

// Analysis

openabove = f_gapper(valuewhen(session_bar_counter == 0, vah_value[1], 0)) <


valuewhen(session_bar_counter == 0, open, 0)
openbelow = f_gapper(valuewhen(session_bar_counter == 0, val_value[1], 0)) >
valuewhen(session_bar_counter == 0, open, 0)
openbetween = (f_gapper(valuewhen(session_bar_counter == 0, vah_value[1], 0)) >
valuewhen(session_bar_counter == 0, open, 0)) and
(f_gapper(valuewhen(session_bar_counter == 0, val_value[1], 0)) <
valuewhen(session_bar_counter == 0, open, 0))

You might also like