Pivotboss (CPR, Camarilla, Market Profile)

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

//@version=4

study("D, W, M_CPR + Camarilla + Value Area _", shorttitle="PivotBoss_v4.0",


overlay=true)

getSeries(e, timeFrame) => security(syminfo.tickerid, timeFrame, e,


lookahead=barmerge.lookahead_on)
session_timeframe = input(title="Value Area Resolution", defval="D",
options=["D","W","M","125"])

//Previous D datas
PrevDClose = getSeries(close[1], 'D')
PrevDOpen = getSeries(open[1], 'D')
PrevDHigh = getSeries(high[1], 'D')
PrevDLow = getSeries(low[1], 'D')

//Daily CPR
DPivot = (PrevDHigh + PrevDLow + PrevDClose) / 3.0
DBC = (PrevDHigh + PrevDLow) / 2.0
DTC = (DPivot - DBC) + DPivot
DR1 = (2 * DPivot) - PrevDLow
DS1 = (2 * DPivot) - PrevDHigh
DR2 = DPivot + (PrevDHigh - PrevDLow)
DS2 = DPivot - (PrevDHigh - PrevDLow)
DR3 = PrevDHigh + 2 * (DPivot - PrevDLow)
DS3 = PrevDLow - 2 * (PrevDHigh - DPivot)
DR4 = DR3 + (DR2 - DR1)
DS4 = DS3 - (DS1 - DS2)

//Daily Camarilla
dh5 = (PrevDHigh/PrevDLow) * PrevDClose
dh4 = PrevDClose + (PrevDHigh - PrevDLow) * 1.1 / 2.0
dh3 = PrevDClose + (PrevDHigh - PrevDLow) * 1.1 / 4.0
dl3 = PrevDClose - (PrevDHigh - PrevDLow) * 1.1 / 4.0
dl4 = PrevDClose - (PrevDHigh - PrevDLow) * 1.1 / 2.0
dl5 = PrevDClose - (dh5 - PrevDClose)

DCPR = input(false, title="Show Daily CPR")


DSR = input(false, title="Show Daily Support/Resistance")
PrevDHL = input(false, title="Show Previous Day High / Low")
DCAM = input(false, title="Show Daily Camarilla")

plot(DCPR and DPivot and (timeframe.isintraday) ? DPivot : na, title="PP",


color=color.aqua, linewidth=2, style=plot.style_stepline, offset=0, transp=0)
p1=plot(DCPR and DBC and (timeframe.isintraday) ? DBC : na, title="BCP",
color=color.aqua, linewidth=2, style=plot.style_stepline, offset=0, transp=10)
p2=plot(DCPR and DTC and (timeframe.isintraday) ? DTC : na, title="TC",
color=color.aqua, linewidth=2, style=plot.style_stepline, offset=0, transp=10)
fill(p1,p2)
plot(DSR and DR1 and (timeframe.isintraday) ? DR1 : na, title="R1",
color=color.red, linewidth=2, style=plot.style_stepline, offset=0, transp=0)
plot(DSR and DS1 and (timeframe.isintraday) ? DS1 : na, title="S1",
color=color.green, linewidth=2, style=plot.style_stepline, offset=0, transp=0)
plot(DSR and DR2 and (timeframe.isintraday) ? DR2 : na, title="R2",
color=color.red, linewidth=2, style=plot.style_stepline, offset=0, transp=20)
plot(DSR and DS2 and (timeframe.isintraday) ? DS2 : na, title="S2",
color=color.green, linewidth=2, style=plot.style_stepline, offset=0, transp=20)
plot(DSR and DR3 and (timeframe.isintraday) ? DR3 : na, title="R3",
color=color.red, linewidth=2, style=plot.style_stepline, offset=0, transp=40)
plot(DSR and DS3 and (timeframe.isintraday) ? DS3 : na, title="S3",
color=color.green, linewidth=2, style=plot.style_stepline, offset=0, transp=40)
plot(DSR and DR4 and (timeframe.isintraday) ? DR4 : na, title="R4",
color=color.red, linewidth=2, style=plot.style_stepline, offset=0, transp=60)
plot(DSR and DS4 and (timeframe.isintraday) ? DS4 : na, title="S4",
color=color.green, linewidth=2, style=plot.style_stepline, offset=0, transp=60)
plot(PrevDHL and PrevDHigh and (timeframe.isintraday) ? PrevDHigh : na,
title="PrevDHigh", color=color.white, linewidth=2, style=plot.style_stepline,
offset=0, transp=0)
plot(PrevDHL and PrevDLow and (timeframe.isintraday) ? PrevDLow : na,
title="PrevDLow", color=color.white, linewidth=2, style=plot.style_stepline,
offset=0, transp=0)
plot(DCAM and dh5 and (timeframe.isintraday) ? dh5 : na, title="H5",
color=color.maroon, linewidth=2, style=plot.style_stepline, offset=0, transp=60)
plot(DCAM and dh4 and (timeframe.isintraday) ? dh4 : na, title="H4",
color=color.maroon, linewidth=2, style=plot.style_stepline, offset=0, transp=40)
plot(DCAM and dh3 and (timeframe.isintraday) ? dh3 : na, title="H3",
color=color.maroon, linewidth=2, style=plot.style_stepline, offset=0, transp=0)
plot(DCAM and dl3 and (timeframe.isintraday) ? dl3 : na, title="L3",
color=color.olive, linewidth=2, style=plot.style_stepline, offset=0, transp=0)
plot(DCAM and dl4 and (timeframe.isintraday) ? dl4 : na, title="L4",
color=color.olive, linewidth=2, style=plot.style_stepline, offset=0, transp=40)
plot(DCAM and dl3 and (timeframe.isintraday) ? dl5 : na, title="L5",
color=color.olive, linewidth=2, style=plot.style_stepline, offset=0, transp=60)

//Previous W datas
PrevWClose = getSeries(close[1], 'W')
PrevWOpen = getSeries(open[1], 'W')
PrevWHigh = getSeries(high[1], 'W')
PrevWLow = getSeries(low[1], 'W')

//Weekly CPR
WPivot = (PrevWHigh + PrevWLow + PrevWClose) / 3
WBC = (PrevWHigh + PrevWLow) / 2
WTC = (WPivot - WBC ) + WPivot
WR1 = (2 * WPivot) - PrevWLow
WS1 = (2 * WPivot) - PrevWHigh
WR2 = WPivot + (PrevWHigh - PrevWLow)
WS2 = WPivot - (PrevWHigh - PrevWLow)
WR3 = PrevWHigh + 2 * (WPivot - PrevWLow)
WS3 = PrevWLow - 2 * (PrevWHigh - WPivot)
WR4 = WR3 + (WR2 - WR1 )
WS4 = WS3 - (WS1 - WS2 )

//Weekly Camarilla
wh5 = (PrevWHigh/PrevWLow) * PrevWClose
wh4 = PrevWClose + (PrevWHigh - PrevWLow) * 1.1 / 2.0
wh3 = PrevWClose + (PrevWHigh - PrevWLow) * 1.1 / 4.0
wl3 = PrevWClose - (PrevWHigh - PrevWLow) * 1.1 / 4.0
wl4 = PrevWClose - (PrevWHigh - PrevWLow) * 1.1 / 2.0
wl5 = PrevWClose - (wh5 - PrevWClose)

WCPR = input(true, title="Show Weekly CPR Range")


WSR = input(true, title="Show Weekly Support/Resistance")
PrevWHL = input(true, title="Show Previous Week High / Low")
WCAM = input(true, title="Show Weekly Camarilla")

plot(WCPR and WPivot and (timeframe.isintraday or timeframe.isdaily) ? WPivot : na,


title="WPP", color=color.fuchsia, linewidth=2, style=plot.style_circles, offset=0,
transp=35)
p3=plot(WCPR and WBC and (timeframe.isintraday or timeframe.isdaily) ? WBC : na,
title="WBC", color=color.fuchsia, linewidth=2, style=plot.style_circles, offset=0,
transp=65)
p4=plot(WCPR and WTC and (timeframe.isintraday or timeframe.isdaily) ? WTC : na,
title="WTC", color=color.fuchsia, linewidth=2, style=plot.style_circles, offset=0,
transp=65)
fill(p3,p4, color=color.gray)
plot(WSR and WR1 and (timeframe.isintraday or timeframe.isdaily) ? WR1 : na,
title="WR1", color=color.red, linewidth=2, style=plot.style_circles, offset=0,
transp=20)
plot(WSR and WS1 and (timeframe.isintraday or timeframe.isdaily) ? WS1 : na,
title="WS1", color=color.green, linewidth=2, style=plot.style_circles, offset=0,
transp=20)
plot(WSR and WR2 and (timeframe.isintraday or timeframe.isdaily) ? WR2 : na,
title="WR2", color=color.red, linewidth=2, style=plot.style_circles, offset=0,
transp=40)
plot(WSR and WS2 and (timeframe.isintraday or timeframe.isdaily) ? WS2 : na,
title="WS2", color=color.green, linewidth=2, style=plot.style_circles, offset=0,
transp=40)
plot(WSR and WR3 and (timeframe.isintraday or timeframe.isdaily) ? WR3 : na,
title="WR3", color=color.red, linewidth=2, style=plot.style_circles, offset=0,
transp=60)
plot(WSR and WS3 and (timeframe.isintraday or timeframe.isdaily) ? WS3 : na,
title="WS3", color=color.green, linewidth=2, style=plot.style_circles, offset=0,
transp=60)
plot(WSR and WR4 and (timeframe.isintraday or timeframe.isdaily) ? WR4 : na,
title="WR4", color=color.red, linewidth=2, style=plot.style_circles, offset=0,
transp=80)
plot(WSR and WS4 and (timeframe.isintraday or timeframe.isdaily) ? WS4 : na,
title="WS4", color=color.green, linewidth=2, style=plot.style_circles, offset=0,
transp=80)
plot(PrevWHL and PrevWHigh and (timeframe.isintraday or timeframe.isdaily) ?
PrevWHigh : na, title="PrevWHigh", color=color.white, linewidth=2,
style=plot.style_circles, offset=0, transp=0)
plot(PrevWHL and PrevWLow and (timeframe.isintraday or timeframe.isdaily) ?
PrevWLow : na, title="PrevWLow", color=color.white, linewidth=2,
style=plot.style_circles, offset=0, transp=0)
plot(WCAM and wh5 and (timeframe.isintraday or timeframe.isdaily) ? wh5 : na,
title="WH5", color=color.maroon, linewidth=2, style=plot.style_circles, transp=60)
plot(WCAM and wh4 and (timeframe.isintraday or timeframe.isdaily) ? wh4 : na,
title="WH4", color=color.maroon, linewidth=2, style=plot.style_circles, transp=40)
plot(WCAM and wh3 and (timeframe.isintraday or timeframe.isdaily) ? wh3 : na,
title="Wh3", color=color.maroon, linewidth=2, style=plot.style_circles,transp=0)
plot(WCAM and wl3 and (timeframe.isintraday or timeframe.isdaily) ? wl3 : na,
title="WL3", color=color.olive, linewidth=2, style=plot.style_circles,transp=0)
plot(WCAM and wl4 and (timeframe.isintraday or timeframe.isdaily) ? wl4 : na,
title="WL4", color=color.olive, linewidth=2, style=plot.style_circles, transp=40)
plot(WCAM and wl3 and (timeframe.isintraday or timeframe.isdaily) ? wl5 : na,
title="WL5", color=color.olive, linewidth=2, style=plot.style_circles, transp=60)

//Previous M datas
PrevMClose = getSeries(close[1], 'M')
PrevMOpen = getSeries(open[1], 'M')
PrevMHigh = getSeries(high[1], 'M')
PrevMLow = getSeries(low[1], 'M')

//Monthly CPR
MPivot = (PrevMHigh + PrevMLow + PrevMClose) / 3
MBC = (PrevMHigh + PrevMLow) / 2
MTC = (MPivot - MBC ) + MPivot
MR1 = (2 * MPivot) - PrevMLow
MS1 = (2 * MPivot) - PrevMHigh
MR2 = MPivot + (PrevMHigh - PrevMLow)
MS2 = MPivot - (PrevMHigh - PrevMLow)
MR3 = PrevMHigh + 2 * (MPivot - PrevMLow)
MS3 = PrevMLow - 2 * (PrevMHigh - MPivot)
MR4 = MR3 + (MR2 - MR1 )
MS4 = MS3 - (MS1 - MS2 )

//Monthly Camarilla
mh5 = (PrevMHigh/PrevMLow) * PrevMClose
mh4 = PrevMClose + (PrevMHigh - PrevMLow) * 1.1 / 2.0
mh3 = PrevMClose + (PrevMHigh - PrevMLow) * 1.1 / 4.0
ml3 = PrevMClose - (PrevMHigh - PrevMLow) * 1.1 / 4.0
ml4 = PrevMClose - (PrevMHigh - PrevMLow) * 1.1 / 2.0
ml5 = PrevMClose - (mh5 - PrevMClose)

//MPivot = input(true, title="Show Mly Pivot")


MCPR = input(false, title="Show Monthly CPR Range")
MSR = input(false, title="Show Monthly Support/Resistance")
PrevMHL = input(false, title="Show Previous Month High / Low")
MCAM = input(false, title="Show Monthly Camarilla")

plot(MCPR and MPivot and (timeframe.isintraday or timeframe.isdaily or


timeframe.isweekly) ? MPivot : na, title="MPP", color=color.orange, linewidth=2,
style=plot.style_cross, offset=0, transp=35)
p5=plot(MCPR and MBC and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MBC : na, title="MBC", color=color.orange, linewidth=2,
style=plot.style_cross, offset=0, transp=65)
p6=plot(MCPR and MTC and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MTC : na, title="MTC", color=color.orange, linewidth=2,
style=plot.style_cross, offset=0, transp=65)
fill(p5,p6)
plot(MSR and MR1 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MR1 : na, title="MR1", color=color.red, linewidth=2,
style=plot.style_cross, offset=0, transp=20)
plot(MSR and MS1 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MS1 : na, title="MS1", color=color.green, linewidth=2,
style=plot.style_cross, offset=0, transp=20)
plot(MSR and MR2 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MR2 : na, title="MR2", color=color.red, linewidth=2,
style=plot.style_cross, offset=0, transp=40)
plot(MSR and MS2 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MS2 : na, title="MS2", color=color.green, linewidth=2,
style=plot.style_cross, offset=0, transp=40)
plot(MSR and MR3 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MR3 : na, title="MR3", color=color.red, linewidth=2,
style=plot.style_cross, offset=0, transp=60)
plot(MSR and MS3 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MS3 : na, title="MS3", color=color.green, linewidth=2,
style=plot.style_cross, offset=0, transp=60)
plot(MSR and MR4 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MR4 : na, title="MR4", color=color.red, linewidth=2,
style=plot.style_cross, offset=0, transp=80)
plot(MSR and MS4 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? MS4 : na, title="MS4", color=color.green, linewidth=2,
style=plot.style_cross, offset=0, transp=80)
plot(PrevMHL and PrevMHigh and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? PrevMHigh : na, title="PrevMHigh", color=color.white,
linewidth=2, style=plot.style_cross, offset=0, transp=0)
plot(PrevMHL and PrevMLow and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? PrevMLow : na, title="PrevMLow", color=color.white,
linewidth=2, style=plot.style_cross, offset=0, transp=0)
plot(MCAM and mh5 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? mh5 : na, title="mh5", color=color.maroon, linewidth=2,
style=plot.style_cross, offset=0, transp=60)
plot(MCAM and mh4 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? mh4 : na, title="mh4", color=color.maroon, linewidth=2,
style=plot.style_cross, offset=0, transp=40)
plot(MCAM and mh3 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? mh3 : na, title="mh3", color=color.maroon, linewidth=2,
style=plot.style_cross, offset=0, transp=20)
plot(MCAM and ml3 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? ml3 : na, title="ml3", color=color.olive, linewidth=2,
style=plot.style_cross, offset=0, transp=20)
plot(MCAM and ml4 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? ml4 : na, title="ml4", color=color.olive, linewidth=2,
style=plot.style_cross, offset=0, transp=40)
plot(MCAM and ml3 and (timeframe.isintraday or timeframe.isdaily or
timeframe.isweekly) ? ml5 : na, title="ml5", color=color.olive, linewidth=2,
style=plot.style_cross, offset=0, transp=60)

// ||-- Inputs:

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=(valuewhen(session_bar_counter == 0, vah_value[1], 0)), title='VAH',


color=color.orange, linewidth=2, style=plot.style_stepline, transp=0)
plot(series=(valuewhen(session_bar_counter == 0, val_value[1], 0)), title='VAL',
color=color.orange, linewidth=2, style=plot.style_stepline, transp=0)
p7=plot(series=(valuewhen(session_bar_counter == 0, poc_upper[1], 0)),
title='POC_U', color=color.yellow, linewidth=3, style=plot.style_stepline,
transp=0)
p8=plot(series=(valuewhen(session_bar_counter == 0, poc_lower[1], 0)),
title='POC_L', color=color.yellow, linewidth=3, style=plot.style_stepline,
transp=0)
fill(p7, p8, color=color.yellow)

You might also like