Next Day CPR Indicator for Tradingview
//@version=4 study(title="RS- Central Pivot Range", shorttitle="RS-Next Day CPR ", overlay=true) daily_cpr = input (title=" Number of Daily CPR Look Back", type= input.integer , defval=20, minval=0) showTomorrow = input(defval=true, title='Show Tomorrows CPR') Tomorrow_cpr = input (title="Number of Next Day CPR Look Back", type= input.integer , defval=4, minval=0) todayClose = security( syminfo.tickerid , 'D', close,gaps = barmerge.gaps_off, lookahead=barmerge.lookahead_on) todayHigh = security( syminfo.tickerid , 'D', high,gaps = barmerge.gaps_off, lookahead=barmerge.lookahead_on) todayLow = security( syminfo.tickerid , 'D', low,gaps = barmerge.gaps_off, lookahead=barmerge.lookahead_on) new_bar(res) => change(time(res)) != 0 new_period(condition, src) => result = 0.0 result := condition ? src : result[1] result pivot = (high + low + close) / 3.0 bc = (high + low) / 2.0 tc = (pivot - bc) + pivot R1 = (2*pivot) - low S1 = (2*pivot) - high R2 = pivot + ( high - low) S2 = pivot - ( high - low) R3 = high + (2*(pivot - low)) S3 = low - (2*(high - pivot )) PH = high PL= low Nextpivot = (todayClose + todayHigh + todayLow)/3 Nextbc = (todayHigh + todayLow) / 2.0 Nexttc = (Nextpivot - Nextbc) + Nextpivot NextR1 = (Nextpivot*2) - todayLow NextR2 = Nextpivot+ (todayHigh-todayLow) NextR3 = todayHigh + (2*(Nextpivot-todayLow)) NextS1 = (Nextpivot*2) - todayHigh NextS2 = Nextpivot- (todayHigh-todayLow) NextS3 = todayLow - (2*(todayHigh-Nextpivot)) NextH = todayHigh NextL = todayLow //Daily Central Pivot Range dpp = security( syminfo.tickerid , 'D', pivot[1], lookahead=barmerge.lookahead_on) dbc = security( syminfo.tickerid , 'D', bc[1], lookahead=barmerge.lookahead_on) dtc = security( syminfo.tickerid , 'D', tc[1], lookahead=barmerge.lookahead_on) dR1= security( syminfo.tickerid , 'D', R1[1], lookahead=barmerge.lookahead_on) dS1 = security( syminfo.tickerid , 'D', S1[1], lookahead=barmerge.lookahead_on) dR2 = security( syminfo.tickerid , 'D', R2[1], lookahead=barmerge.lookahead_on) dS2 = security( syminfo.tickerid , 'D', S2[1], lookahead=barmerge.lookahead_on) dR3 = security( syminfo.tickerid , 'D', R3[1], lookahead=barmerge.lookahead_on) dS3 = security( syminfo.tickerid , 'D', S3[1], lookahead=barmerge.lookahead_on) dPH = security( syminfo.tickerid , 'D', PH[1], lookahead=barmerge.lookahead_on) dPL = security( syminfo.tickerid , 'D', PL[1], lookahead=barmerge.lookahead_on) //Next day Central Pivot Range TcNextpivot = security( syminfo.tickerid , 'D', Nextpivot, lookahead=barmerge.lookahead_on) TcNextbc = security( syminfo.tickerid , 'D', Nextbc, lookahead=barmerge.lookahead_on) TcNexttc = security( syminfo.tickerid , 'D', Nexttc, lookahead=barmerge.lookahead_on) TcNextR1= security( syminfo.tickerid , 'D', NextR1, lookahead=barmerge.lookahead_on) TcNextR2 = security( syminfo.tickerid , 'D', NextR2, lookahead=barmerge.lookahead_on) TcNextR3 = security( syminfo.tickerid , 'D', NextR3, lookahead=barmerge.lookahead_on) TcNextS1 = security( syminfo.tickerid , 'D', NextS1, lookahead=barmerge.lookahead_on) TcNextS2 = security( syminfo.tickerid , 'D', NextS2, lookahead=barmerge.lookahead_on) TcNextS3 = security( syminfo.tickerid , 'D', NextS3, lookahead=barmerge.lookahead_on) TcNextH = security( syminfo.tickerid , 'D', NextH, lookahead=barmerge.lookahead_on) TcNextL = security( syminfo.tickerid , 'D', NextL, lookahead=barmerge.lookahead_on) one_day = 1000 * 60 * 60 * 24 new_day = daily_cpr > 0 and timenow - time < one_day * daily_cpr and new_bar("D") dpp_ = new_period(new_day, dpp) dtc_ = new_period(new_day, dtc) dbc_ = new_period(new_day, dbc) dR1_ = new_period(new_day, dR1) dS1_ = new_period(new_day, dS1) dR2_ = new_period(new_day, dR2) dS2_ = new_period(new_day, dS2) dR3_ = new_period(new_day, dR3) dS3_ = new_period(new_day, dS3) dPH_ = new_period(new_day, dPH) dPL_ = new_period(new_day, dPL) next_day = Tomorrow_cpr > 0 and timenow - time < one_day * Tomorrow_cpr and new_bar("D") Nextpivot_ = new_period(next_day, TcNextpivot) Nextbc_ = new_period(next_day, TcNextbc) Nexttc_ = new_period(next_day, TcNexttc) NextR1_= new_period(next_day, TcNextR1) NextR2_ = new_period(next_day, TcNextR2) NextR3_ = new_period(next_day, TcNextR3) NextS1_ = new_period(next_day, TcNextS1) NextS2_ = new_period(next_day, TcNextS2) NextS3_ = new_period(next_day, TcNextS3) NextH_ = new_period(next_day,TcNextH) NextL_ = new_period(new_day,TcNextL) timeFrames = timeframe.isminutes?timeframe.multiplier:60 offest_count = ceil(375/timeFrames) plot( timeframe.isintraday ? (dtc_ >= dbc_ ? dtc_ : dbc_) : na, title="Daily TC", style= plot.style_circles , color=#641797, linewidth=1) plot( timeframe.isintraday ? dpp_ : na, title="Daily PP", style= plot.style_circles, color=#641797, linewidth=1) plot( timeframe.isintraday ? (dtc_ >= dbc_ ? dbc_ : dtc_) : na, title="Daily BC", style= plot.style_circles, color=#641797, linewidth=1) plot(dR1_ , title='Daily R1', style= plot.style_cross , color=#dd380e, linewidth=1) plot(dR2_ , title='Daily R2', style= plot.style_cross , color=#dd380e, linewidth=1) plot(dR3_ , title='Daily R3', style= plot.style_cross , color=#dd380e, linewidth=1) plot(dS1_ , title='Daily S1', style= plot.style_cross , color=#4CAF50, linewidth=1) plot(dS2_ , title='Daily S2', style= plot.style_cross , color=#4CAF50, linewidth=1) plot(dS3_ , title='Daily S3', style= plot.style_cross , color=#4CAF50, linewidth=1) plot(dPH_ , title='Daily PH', style= plot.style_cross , color=#252222, linewidth=1) plot(dPL_ , title='Daily PL', style= plot.style_cross , color=#252222, linewidth=1) plot( showTomorrow?(Nextbc_ >= Nexttc_? Nextbc_ : Nexttc_): na, title="Next Day TC", style= plot.style_circles , color=#641797, offset=offest_count,linewidth=1) plot( showTomorrow ?(Nextpivot_): na, title="Next Day PP", style= plot.style_circles, color=#641797, offset=offest_count,linewidth=1) plot( showTomorrow ?(Nextbc_ >= Nexttc_? Nexttc_ : Nextbc_): na, title="Tomorrow BC", style= plot.style_circles, offset=offest_count,color=#641797, linewidth=1) plot(showTomorrow?NextR1_:na , title='Next Day R1', style= plot.style_cross , color=#dd380e, offset=offest_count,linewidth=1) plot(showTomorrow?NextR2_:na , title='Next Day R2', style= plot.style_cross , color=#dd380e, offset=offest_count,linewidth=1) plot(showTomorrow?NextR3_:na , title='Next Day R3', style= plot.style_cross , color=#dd380e, offset=offest_count,linewidth=1) plot(showTomorrow?NextS1_:na , title='Next Day S1', style= plot.style_cross , color=#4CAF50, offset=offest_count,linewidth=1) plot(showTomorrow?NextS2_:na , title='Next Day S2', style= plot.style_cross , color=#4CAF50, offset=offest_count,linewidth=1) plot(showTomorrow?NextS3_:na , title='Next Day S3', style= plot.style_cross , color=#4CAF50, offset=offest_count,linewidth=1) plot(showTomorrow?NextH_:na , title='Next Day High', style= plot.style_cross , color=#252222, offset=offest_count,linewidth=1) plot(showTomorrow?NextL_:na , title='Next Day Low', style= plot.style_cross , color=#252222, offset=offest_count,linewidth=1)