PivotBoss ADR Levels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © G-iOS

//@version=4

study(title="PivotBoss ADR MZ PEMA Targets", shorttitle="PB_ADR/MZ/PEMA", overlay = true, max_bars_back=4000)
 

 
// Rounding levels to min tick
nround(x) =>
    n = round(x / syminfo.mintick) * syminfo.mintick
    
period = "D"

//Input

dp = input(true, title="Pivot Range", group = "PivotBoss")


Bu = input(title = 'Bull Target ', defval = true, type = input.bool, group = "PivotBoss" )
Br = input(title = 'Bear Target ', defval = true, type = input.bool, group = "PivotBoss" )

cp = input(false, " CAMARILLA ",type=input.bool, inline="cam",group="PivotBoss")

HL = input(title = 'Show High & Low ', defval = true, type = input.bool, group = "OHLC" )

dl = input(false, title="Show Yesterday OHLC", group = "OHLC")

label_size = input("normal", options=["auto", "tiny", "small", "normal", "large", "huge"], title="Label size", group = "PivotBoss")
l_size = label_size == "auto" ? size.auto : label_size == "tiny" ? size.tiny : label_size == "small" ? size.small : label_size == "normal" ? size.normal : label_size == "large" ? size.large : size.huge

display_value       = true

//Calculation

dhigh = security(syminfo.tickerid, period , high, lookahead=barmerge.lookahead_on)
dlow = security(syminfo.tickerid, period , low, lookahead=barmerge.lookahead_on)

// ADR POINTS 

 
//B1 = 0.0, B2 = 0.0, B0 = 0.0, B5 = 0.0, B6 = 0.0, B7 = 0.0, B8 = 0.0,B9 = 0.0,B3 = 0.0
//B4 = 0.0, ADR = 0.0 
//color1 = color.green, 
//bars_sinse1 = 0
dayrange =  dhigh - dlow

dailyHigh1  = security(syminfo.tickerid,"D" , high[1],lookahead=barmerge.lookahead_on)
dailyLow1   = security(syminfo.tickerid,"D" , low [1],lookahead=barmerge.lookahead_on)
dailyHigh2  = security(syminfo.tickerid,"D" , high[2],lookahead=barmerge.lookahead_on)
dailyLow2   = security(syminfo.tickerid,"D" , low [2],lookahead=barmerge.lookahead_on)
dailyHigh3  = security(syminfo.tickerid,"D" , high[3],lookahead=barmerge.lookahead_on)
dailyLow3   = security(syminfo.tickerid,"D" , low [3],lookahead=barmerge.lookahead_on)
dailyHigh4  = security(syminfo.tickerid,"D" , high[4],lookahead=barmerge.lookahead_on)
dailyLow4   = security(syminfo.tickerid,"D" , low [4],lookahead=barmerge.lookahead_on)
dailyHigh5  = security(syminfo.tickerid,"D" , high[5],lookahead=barmerge.lookahead_on)
dailyLow5   = security(syminfo.tickerid,"D" , low [5],lookahead=barmerge.lookahead_on)
dailyHigh6  = security(syminfo.tickerid,"D" , high[6],lookahead=barmerge.lookahead_on)
dailyLow6   = security(syminfo.tickerid,"D" , low [6],lookahead=barmerge.lookahead_on)
dailyHigh7  = security(syminfo.tickerid,"D" , high[7],lookahead=barmerge.lookahead_on)
dailyLow7   = security(syminfo.tickerid,"D" , low [7],lookahead=barmerge.lookahead_on)
dailyHigh8  = security(syminfo.tickerid,"D" , high[8],lookahead=barmerge.lookahead_on)
dailyLow8   = security(syminfo.tickerid,"D" , low [8],lookahead=barmerge.lookahead_on)
dailyHigh9  = security(syminfo.tickerid,"D" , high[9],lookahead=barmerge.lookahead_on)
dailyLow9   = security(syminfo.tickerid,"D" , low [9],lookahead=barmerge.lookahead_on)

dayrange1 = dailyHigh1 - dailyLow1
dayrange2 = dailyHigh2 - dailyLow2
dayrange3 = dailyHigh3 - dailyLow3
dayrange4 = dailyHigh4 - dailyLow4
dayrange5 = dailyHigh5 - dailyLow5
dayrange6 = dailyHigh6 - dailyLow6
dayrange7 = dailyHigh7 - dailyLow7
dayrange8 = dailyHigh8 - dailyLow8
dayrange9 = dailyHigh9 - dailyLow9

adr_10 = (dayrange1+dayrange2+dayrange3+dayrange4+dayrange5+dayrange6+dayrange7+dayrange8+dayrange9+dayrange)/10


B0 = dlow + (adr_10*0.25)
B1 = dlow + (adr_10*0.5)
B2 = dlow + (adr_10*0.75)
B3 = (dlow + adr_10)
B4 = dlow + (adr_10*1.25)
    
B5 = dhigh - (adr_10*0.25)
B6 = dhigh - (adr_10*0.5)
B7 = dhigh - (adr_10*0.75)
B8 = (dhigh - adr_10)
B9 = dhigh - (adr_10*1.25)


//Plotting

plot( HL ? dlow : na , title="DLow", style = plot.style_circles, color=color.green, transp=0)
plot( HL ? dhigh : na, title="DHigh", style = plot.style_circles, color=color.red, transp=0)


plot(   Bu ? B0 : na , title="R25", color=B0 != B0[1] ? na : color.orange, linewidth=2,transp=0)
plot(   Bu ? B1 : na, title="R50", color=B1 != B1[1] ? na : color.green, linewidth=2, transp=0)
plot(   Bu ? B2 : na, title="R75", color=B2 != B2[1] ? na : color.green, linewidth=2, transp=0)
plot(   Bu ? B3 : na, title="R100", color=B3 != B3[1] ? na : color.white, linewidth=2, transp=0)
plot(   Bu ? B4 : na, title="R125", color=B4 != B4[1] ? na : color.blue, linewidth=2, transp=0)

plot(   Br ? B5 : na, title="S25", color=B5 != B5[1] ? na : color.orange, linewidth=2, transp=0)
plot(   Br ? B6 : na , title="S50", color=B6 != B6[1] ? na : color.red, linewidth=2, transp=0)
plot(   Br ? B7 : na , title="S75", color=B7 != B7[1] ? na : color.red, linewidth=2, transp=0)
plot(   Br ? B8 : na , title="S100", color=B8 != B8[1] ? na : color.white, linewidth=2, transp=0)
plot(   Br ? B9 : na , title="S125", color=B9 != B9[1] ? na : color.blue, linewidth=2, transp=0)


label_vpp = label.new(bar_index, dhigh, text= HL ? ("                                                                                                                                                             HOD" + " " + tostring(nround(dhigh))) : "                                        ", style= label.style_none, textcolor = color.red, size= l_size)
label.delete(label_vpp[1])
label_vr2 = label.new(bar_index, dlow, text= HL ? ("                                                                                                                                                              LOD" + " " + tostring(nround(dlow))) : "                                         ", style= label.style_none, textcolor = color.green, size= l_size)
label.delete(label_vr2[1])

label_vs0 = label.new(bar_index, B0, text= Bu ? ("                                                                            R-25% Scaling" + " " + tostring(nround(B0))) : "                  ", style= label.style_none, textcolor = color.orange,size= l_size)
label.delete(label_vs0[1])
label_vs1 = label.new(bar_index, B1, text= Bu ? ("                                                                            50% Scaling" + " " + tostring(nround(B1))) : "                  ", style= label.style_none, textcolor = color.green ,size= l_size)
label.delete(label_vs1[1])
label_vs2 = label.new(bar_index, B2, text= Bu ? ("                                                                            75% Primary" + " " + tostring(nround(B2))) : "                  ", style= label.style_none, textcolor = color.green,size= l_size)
label.delete(label_vs2[1])
label_vs3 = label.new(bar_index, B3, text= Bu ? ("                                                                                 100% Secondary" + " " + tostring(nround(B3))) : "                  ", style= label.style_none, textcolor = color.white,size= l_size)
label.delete(label_vs3[1])
label_vs4 = label.new(bar_index, B4, text= Bu ? ("                                                                                125% Extended" + " " + tostring(nround(B4))) : "                  ", style= label.style_none, textcolor = color.blue,size= l_size)
label.delete(label_vs4[1])

label_vt0 = label.new(bar_index, B5, text= Br ? ("                                                                            S-25% Scaling" + " " + tostring(nround(B5))) : "                  ", style= label.style_none, textcolor = color.orange,size= l_size)
label.delete(label_vt0[1])
label_vt1 = label.new(bar_index, B6, text= Br  ? ("                                                                            50% Scaling" + " " + tostring(nround(B6))) : "                  ", style= label.style_none, textcolor = color.red,size= l_size)
label.delete(label_vt1[1])
label_vt2 = label.new(bar_index, B7, text= Br ? ("                                                                            75% Primary" + " " + tostring(nround(B7))) : "                  ", style= label.style_none, textcolor = color.red,size= l_size)
label.delete(label_vt2[1])
label_vt3 = label.new(bar_index, B8, text= Br ? ("                                                                                100% Secondary" + " " + tostring(nround(B8))) : "                  ", style= label.style_none, textcolor = color.white,size= l_size)
label.delete(label_vt3[1])
label_vt4 = label.new(bar_index, B9, text= Br ? ("                                                                                125% Extended" + " " + tostring(nround(B9))) : "                  ", style= label.style_none, textcolor = color.blue,size= l_size)
label.delete(label_vt4[1])




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

is_today = year == year(timenow) and month == month(timenow) and dayofmonth == dayofmonth(timenow)


//PEMA

p = input(true, title="Show PEMA", group = "PEMA")
TLineEMA = input(8, minval=1, title="Trigger Line", group = "PEMA")
FastMA = input(defval=13, minval=1, title="Fast Line", group = "PEMA")
MiddleMA = input(defval=21, minval=1, title="Middle Line", group = "PEMA")
MiddleMA1 = input(defval=34, minval=1, title="Middle 2 Line", group = "PEMA")
SlowMA = input(defval=55, minval=1, title="Slow Line", group = "PEMA")

fPivot = ((high + low + close)/3)

ema0  = ema(fPivot, TLineEMA)
ema1 = ema(fPivot,FastMA)
ema2 = ema(fPivot,MiddleMA)
ema3 = ema(fPivot,MiddleMA1)
ema4 = ema(fPivot,SlowMA)

plot( p ? ema0 : na, color=color.red, title="T-Line EMA", linewidth=1)
p11=plot(p and ema1 ? ema1:na,color=color.new(color.fuchsia, 0), style=plot.style_line,title='Fast', linewidth=1)
p22=plot(p and ema2 ? ema2:na,color=color.new(color.green, 0),style=plot.style_line, title='Middle',linewidth=1)
p33=plot(p and ema3 ? ema3:na,color=color.new(color.blue, 0), style=plot.style_line, title='Middle 2',linewidth=1,display= display.none)
p44=plot(p and ema4 ? ema4:na,color=color.new(color.gray, 0), style=plot.style_line, title='Slow',linewidth=1,display= display.none)

//fill(p11, p33, color=ema8>ema21 ? color.green:color.red, transp=90, editable=true )


// Money Zone Levels
//  ||--    Inputs:


mz = input(false, title="Money Zone Levels", group = "Money Zone")
dmz = input(false, title="Dev. Money Zone Levels", group = "Money Zone")

session_timeframe = input("D" , options = ["D" , "W" , "M"], group = "Money Zone")
percent_of_tpo = input(0.70,group = "Money Zone")

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
//Modified by Naga Chaitanya:)
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=current_poc_position, title='current_poc_position', color=color.blue)
//plot(series=current_poc_value, title='current_poc_value', color=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=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

series1=f_gapper(valuewhen(session_bar_counter == 0, vah_value[1], 0))
series2=f_gapper(valuewhen(session_bar_counter == 0, val_value[1], 0))
series3=f_gapper(valuewhen(session_bar_counter == 0, poc_upper[1], 0))
series4=f_gapper(valuewhen(session_bar_counter == 0, poc_lower[1], 0))


//Plotting

plot(mz and series1 ? series1:na, title='MZ: VAH', color=color.new(color.green, 10), linewidth=3, style=plot.style_cross, transp=0)
plot(mz and series2 ? series2:na, title='MZ: VAL', color=color.new(color.red, 10), linewidth=3, style=plot.style_cross, transp=0)
plot(mz and series3 ? series3:na, title='MZ: POC Upper', color=color.new(color.white, 10), linewidth=3, style=plot.style_cross, transp=0)
plot(mz and series4 ? series4:na, title='MZ: POC Lower', color=color.new(color.yellow, 10), linewidth=3, style=plot.style_cross, transp=0)

label_vah = label.new(bar_index, series1, text=mz ? ("                                                                                                                                                                MZ : VAH" + " " + tostring(nround(series1))) : na, style= label.style_none, textcolor = color.green,size= l_size)
label.delete(label_vah[1])
label_val = label.new(bar_index, series2, text=mz ? ("                                                                                                                                                                MZ : VAL" + " " + tostring(nround(series2))) : na, style= label.style_none, textcolor = color.red,size= l_size)
label.delete(label_val[1])
label_pocu = label.new(bar_index, series3, text=mz ? ("                                                                                                                                                               MZ : POC-U" + " " + tostring(nround(series3))) : na, style= label.style_none, textcolor = color.white,size= l_size)
label.delete(label_pocu[1])
label_pocl = label.new(bar_index, series4, text=mz ? ("                                                                                                                                                               MZ : POC-L" + " " + tostring(nround(series4))) : na, style= label.style_none, textcolor = color.yellow,size= l_size)
label.delete(label_pocl[1])


//Dev 

plot(dmz ? vah_value : na, title='Dev. VAH', color=color.new(color.fuchsia, 30))
plot(dmz ? val_value : na, title='Dev. VAL', color=color.new(color.fuchsia, 30))

plot(dmz ? poc_upper : na, title='Dev. POC Upper', color=color.new (color.white, 30))
plot(dmz ? poc_lower : na, title='Dev. POC Lower', color=color.new (color.gray, 30))

label_dvah = label.new(bar_index, vah_value, text=dmz ? ("                                                                                                                                                                DMZ : VAH" + " " + tostring(nround(vah_value))) : na, style= label.style_none, textcolor = color.green,size= l_size)
label.delete(label_dvah[1])
label_dval = label.new(bar_index, val_value, text=dmz ? ("                                                                                                                                                                DMZ : VAL" + " " + tostring(nround(val_value))) : na, style= label.style_none, textcolor = color.green,size= l_size)
label.delete(label_dval[1])
label_dpocu = label.new(bar_index, poc_upper, text=dmz ? ("                                                                                                                                                                DMZ : POC-U" + " " + tostring(nround(poc_upper))) : na, style= label.style_none, textcolor = color.green,size= l_size)
label.delete(label_dpocu[1])
label_dpocl = label.new(bar_index, poc_lower, text=dmz ? ("                                                                                                                                                                DMZ : POC-L" + " " + tostring(nround(poc_lower))) : na, style= label.style_none, textcolor = color.green,size= l_size)
label.delete(label_dpocl[1])


// 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))



//Previous

pdhigh = security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
pdlow = security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
pdclose = security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
pdopen = security(syminfo.tickerid, "D", open[1], lookahead=barmerge.lookahead_on)


plot(dl and pdhigh ? pdhigh : na, title="Previous Day High", style=plot.style_line, color= pdhigh != pdhigh[1] ? na : color.fuchsia, transp=0)
plot(dl and pdlow ? pdlow : na, title="Previous Day Low", style=plot.style_line, color= pdlow != pdlow[1] ? na : color.fuchsia, transp=0)
plot(dl and pdclose ? pdclose : na, title="Previous Day Close", style=plot.style_circles, color=#FF9800, linewidth = 2, transp=0)
plot(dl and pdopen ? pdopen : na, title="Previous Day open", style=plot.style_circles, color=#FF9800, linewidth = 2, transp=0)


label_dh = dl ? label.new(bar_index, pdhigh, text=display_value ? ("                                                                                                                                                                       yHI"  + " ......." + tostring(nround(pdhigh))) : "........yHI",  style= label.style_none, textcolor=#FF9800, size= l_size) : na
label.delete(label_dh[1])
label_dl = dl ? label.new(bar_index, pdlow, text=display_value ? ("                                                                                                                                                                        yLO"  + " ......." + tostring(nround(pdlow))) : "........yLO",  style= label.style_none, textcolor=#FF9800, size= l_size) : na
label.delete(label_dl[1])
label_dc = dl? label.new(bar_index, pdclose, text=display_value ? ("                                                                                                                                                                      yCL"  + "....... " + tostring(nround(pdclose))) : "........yCL",  style= label.style_none, textcolor=#FF9800, size= l_size) : na
label.delete(label_dc[1])
label_do = dl ? label.new(bar_index, pdopen, text=display_value ? ("                                                                                                                                                                       yOP"  + "......." + tostring(nround(pdopen))) : "........yOP",  style= label.style_none, textcolor=#FF9800, size= l_size) : na
label.delete(label_do[1])

//BB - 3D

BB = input(title = 'Show  BB ', defval = false, type = input.bool, group = "BB - 3D" )

length = input(20,title ="BB Length" ,minval=1, group = "BB - 3D") 
src = input(close, title="Source", group = "BB - 3D")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev", group = "BB - 3D")


basis = sma(src, length)
dev = mult * stdev(src, length)

dev1 = (mult + 1) * stdev(src, length)
dev0 = (mult - 1) * stdev(src, length)

upper = basis + dev
lower = basis - dev

upper1 = basis + dev1
lower1 = basis - dev1


upper0 = basis + dev0
lower0 = basis - dev0



offset = input(0, "Offset", minval = -500, maxval = 500, group = "BB - 3D")

plot(BB ? basis : na, "Basis", color=color.white, offset = offset)

p1 = plot(BB ? upper : na, "Delta U", color=color.red, offset = offset)
p2 = plot(BB ?lower : na, "Delta L", color=color.red, offset = offset)

p3 = plot(BB ? upper1 : na, "Delta 1U", color=color.green, offset = offset)
p4 = plot(BB ?lower1 : na, "Delta 1L", color=color.green, offset = offset)

p5 = plot(BB ? upper0 : na, "Delta -1U", color=color.blue, offset = offset)
p6 = plot(BB ?lower0 : na, "Delta -1L", color=color.blue, offset = offset)

fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

//--------------------------------------------------------------------------------------

//CPR

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


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





label_pp = dp ? label.new(bar_index, pivot, text=display_value ? ("                               P "  + " " ) : "P",  style= label.style_none, textcolor=color.fuchsia, size= l_size) : na
label.delete(label_pp[1])
label_bc = dp ? label.new(bar_index, bc, text=display_value ? ("                                  BC"  + " " ) : "BC",  style= label.style_none, textcolor=color.fuchsia, size= l_size) : na
label.delete(label_bc[1])
label_tc = dp ? label.new(bar_index, tc, text=display_value ? ("                                  TC"  + " " ) : "TC",  style= label.style_none, textcolor=color.fuchsia, size= l_size) : na
label.delete(label_tc[1])


//Plotting
plot(dp and pivot ? pivot : na, title="Pivot", color=pivot != pivot[1] ? na : color.fuchsia, linewidth=2,transp=0)
plot(dp and bc ? bc : na, title="BC", color=bc != bc[1] ? na : color.fuchsia,style = plot.style_circles, linewidth=2,transp=0)
plot(dp and tc ? tc : na, title="TC", color=tc != tc[1] ? na : color.fuchsia, style = plot.style_circles,linewidth=2,transp=0)


//----------------------------------------------------------------------------------------

//Camarilla Pivot





//disp_c_labels = input.bool(false, "Labels", inline="cam",group="SUPPORT AND RESISTANCE")

//h3_show = input.bool(true, "H3", inline="H", group="SUPPORT AND RESISTANCE")
//l3_show = input.bool(true, "L3", inline="L", group="SUPPORT AND RESISTANCE")

//h4_show = input.bool(true, "H4", inline="H", group="SUPPORT AND RESISTANCE")
//l4_show = input.bool(true, "L4", inline="L", group="SUPPORT AND RESISTANCE")

//h5_show = input.bool(true, "H5", inline="H", group="SUPPORT AND RESISTANCE")
//l5_show = input.bool(true, "L5", inline="L", group="SUPPORT AND RESISTANCE")

//h6_show = input.bool(true, "H6", inline="H", group="SUPPORT AND RESISTANCE")
//l6_show = input.bool(true, "L6", inline="L", group="SUPPORT AND RESISTANCE")

//label_size1 = input.string("small", options=["auto", "tiny", "small", "normal", "large", "huge"], title="Label size", group="SUPPORT AND RESISTANCE")

//l_size = label_size1 == "auto" ? size.auto : label_size == "tiny" ? size.tiny : label_size == "small" ? size.small : label_size == "normal" ? size.normal : label_size == "large" ? size.large : size.huge


//Expanded Camarilla Pivots Formula with 5 S&R
    
h1 = dpclose + dprange * (1.1 / 12)
h2 = dpclose + dprange * (1.1 / 6)
h3 = dpclose + dprange * (1.1 / 4)
h4 = dpclose + dprange * (1.1 / 2)

l1 = dpclose - dprange * (1.1 / 12)
l2 = dpclose - dprange * (1.1 / 6)
l3 = dpclose - dprange * (1.1 / 4)
l4 = dpclose - dprange * (1.1 / 2)

h5 = dphigh / dplow * dpclose
l5 = dpclose - (h5 - dpclose)

h6 = h5 + 1.168 * (h5 - h4)
l6 = dpclose - (h6 - dpclose)


//plot(cp  ? h5 : na, title="H5",style = plot.style_linebr, color=h5 != h5[1] ? na : color.blue, transp=0)
plot(cp  ? h4 : na, title="H4", style = plot.style_linebr,color=h4 != h4[1] ? na :color.white, transp=0)
plot(cp  ? h3 : na, title="H3",style = plot.style_linebr, color=h3 != h3[1] ? na :color.red, transp=0)
plot(cp  ? l3 : na, title="L3",style = plot.style_linebr, color=l3 != l3[1] ? na :color.green, transp=0)
plot(cp  ? l4 : na, title="L4", style = plot.style_linebr,color=l4 != l4[1] ? na :color.white, transp=0)
//plot(cp  ? l5 : na, title="L5",style = plot.style_linebr, color=l5 != l5[1] ? na :color.blue, transp=0)

//lot(cp  ? h6 : na, title="H6", style = plot.style_linebr,color=h6 != h6[1] ? na :color.fuchsia, transp=0)
//lot(cp  ? l6 : na, title="L6",style = plot.style_linebr, color=l6 != l6[1] ? na :color.fuchsia, transp=0)

label_h3 = cp ? label.new(bar_index, h3, text=display_value ? ("                    H3"  + " " + tostring(nround(h3))) : "H3",  style= label.style_none, textcolor=color.red, size= l_size) : na
label.delete(label_h3[1])
label_h4 = cp ? label.new(bar_index, h4, text=display_value ? ("                    H4"  + " " + tostring(nround(h4))) : "H4",  style= label.style_none, textcolor=color.white, size= l_size) : na
label.delete(label_h4[1])
label_h5 =  cp ? label.new(bar_index, h5, text=display_value ? ("                    H5"  + " " + tostring(nround(h5))) : "H5",  style= label.style_none, textcolor=color.blue, size= l_size) : na
label.delete(label_h5[1])
label_l3 = cp ? label.new(bar_index, l3, text=display_value ? ("                    L3"  + " " + tostring(nround(l3))) : "L3",  style= label.style_none, textcolor=color.green, size= l_size) : na
label.delete(label_l3[1])
label_l4 = cp ? label.new(bar_index, l4, text=display_value ? ("                    L4"  + " " + tostring(nround(l4))) : "L4",  style= label.style_none, textcolor=color.white, size= l_size) : na
label.delete(label_l4[1])
label_l5 = cp ? label.new(bar_index, l5, text=display_value ? ("                    L5"  + " " + tostring(nround(l5))) : "L5",  style= label.style_none, textcolor=color.blue, size= l_size) : na
label.delete(label_l5[1])

label_l6 = cp ? label.new(bar_index, l6 , text=display_value ? ("                     L6"  + " " + tostring(nround(l6))) : "L6",  style= label.style_none, textcolor=color.fuchsia, size= l_size) : na
label.delete(label_l6[1])
label_h6 = cp ? label.new(bar_index, h6 , text=display_value ? ("                     H6"  + " " + tostring(nround(h6))) : "H6",  style= label.style_none, textcolor=color.fuchsia, size= l_size) : na
label.delete(label_h6[1])










