Pivot Boss Floor Pivots with ATR Dilation and Dynamic Levels For ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hi Everyone,

Can anybody convert the following indicator to thinkscript:

https://www.tradingview.com/script/...-Pivots-with-ATR-Dilation-and-Dynamic-Levels/

Code:
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pranjalchaubey

//Structural Pivots
study(title="[CP]Pivot Boss Floor Pivots with ATR Dilation and Dynamic Levels", shorttitle="[CP]Pivot Boss Floor Pivots", overlay=true, max_labels_count=500)


// User Inputs
//==============================================================================
floor_pivot_timeframe           = input("D",    options=["D", "W", "M", "12M"],             title="Floor Pivot Timeframe",                      group="Floor Pivots")
show_floor_pivots               = input(true,   type=input.bool,                            title="Show Floor Pivots",                          group="Floor Pivots")
show_cpr                        = input(true,   type=input.bool,                            title="Show CPR",                                   group="Floor Pivots")
show_labels                     = input(true,   type=input.bool,                            title="Show Pivot Lables",                          group="Floor Pivots")
show_next_day_pivot             = input(false,  type=input.bool,                            title="Show Next Time Period Pivots",               group="Floor Pivots")

dynamic_pivot_levels            = input(true,   type=input.bool,                            title="Show Floor Pivot Levels Dynamically",        group="Dynamic Pivot Levels")
dynamic_pivot_atr_period        = input(14,     type=input.integer, minval=1, maxval=356,   title="Dynamic Pivot ATR Period",                   group="Dynamic Pivot Levels")
dynamic_pivot_atr_threshold     = input(2.0,    type=input.float,   minval=0.001, maxval=10,title="ATR Threshold for Dynamic Floor Pivots",     group="Dynamic Pivot Levels")

atr_dilation                    = input(true,   type=input.bool,                            title="Use ATR to Dilate Intraday Pivot Levels",    group="ATR Pivot Dilation")
atr_multiplier                  = input(0.05,   type=input.float,   minval=0.001, maxval=10,title="ATR Dilation Factor",                        group="ATR Pivot Dilation")
atr_period                      = input(14,     type=input.integer, minval=1, maxval=356,   title="ATR Period",                                 group="ATR Pivot Dilation")

vis1                            = input(true,                                               title="Enable 1st Moving Average",                  group="Bonus Indicators")
ma1                             = input("SMA", options=["SMA", "EMA", "WMA", "VWMA"],       title="Moving Average Type",                        group="Bonus Indicators")
len1                            = input(13,     type=input.integer, minval=1,               title="Moving Average 1 Length",                    group="Bonus Indicators")
src1                            = input(close,  type=input.source,                          title="Moving Average 1 Source",                    group="Bonus Indicators")
off1                            = input(0,      type=input.integer, minval=-500, maxval=500,title="Moving Average 1 Offset",                    group="Bonus Indicators")
vis2                            = input(true,                                               title="Enable 2nd Moving Average",                  group="Bonus Indicators")
ma2                             = input("SMA", options=["SMA", "EMA", "WMA", "VWMA"],       title="Moving Average Type",                        group="Bonus Indicators")
len2                            = input(21,     type=input.integer, minval=1,               title="Moving Average 2 Length",                    group="Bonus Indicators")
src2                            = input(close,  type=input.source,                          title="Moving Average 2 Source",                    group="Bonus Indicators")
off2                            = input(0,      type=input.integer, minval=-500, maxval=500,title="Moving Average 2 Offset",                    group="Bonus Indicators")
vis3                            = input(true,                                               title="Enable 3rd Moving Average",                  group="Bonus Indicators")
ma3                             = input("SMA", options=["SMA", "EMA", "WMA", "VWMA"],       title="Moving Average Type",                        group="Bonus Indicators")
len3                            = input(55,     type=input.integer, minval=1,               title="Moving Average 3 Length",                    group="Bonus Indicators")
src3                            = input(close,  type=input.source,                          title="Moving Average 3 Source",                    group="Bonus Indicators")
off3                            = input(0,      type=input.integer, minval=-500, maxval=500,title="Moving Average 3 Offset",                    group="Bonus Indicators")
visbb                           = input(true,                                               title="Enable Bollinger Band",                      group="Bonus Indicators")
visbb_basis                     = input(false,                                              title="Show Bollinger Basis",                       group="Bonus Indicators")
lenbb                           = input(20,     type=input.integer, minval=1,               title="BB Length",                                  group="Bonus Indicators")
srcbb                           = input(close,  type=input.source,                          title="BB Source",                                  group="Bonus Indicators")
mult                            = input(2.0,    type=input.float, minval=0.001, maxval=50,  title="BB StdDev",                                  group="Bonus Indicators")
offbb                           = input(0,      type=input.integer, minval=-500, maxval=500,title="BB Offset",                                  group="Bonus Indicators")

floor_pivots_p_color            = input(color.new(color.yellow, 0),             type = input.color,     title="Central Floor Pivot",            group="Color Scheme")
floor_pivots_cpr_color          = input(color.new(color.blue, 50),              type = input.color,     title="CPR Band",                       group="Color Scheme")
floor_pivots_r_color            = input(color.new(color.red, 0),                type = input.color,     title="Floor Pivots Resistance Levels", group="Color Scheme")
floor_pivots_s_color            = input(color.new(color.lime, 0),               type = input.color,     title="Floor Pivots Support Levels",    group="Color Scheme")
ma_1_color                      = input(color.new(color.red, 0),                type = input.color,     title="Moving Average 1",               group="Color Scheme")
ma_2_color                      = input(color.new(color.yellow, 0),             type = input.color,     title="Moving Average 2",               group="Color Scheme")
ma_3_color                      = input(color.new(color.aqua, 0),               type = input.color,     title="Moving Average 3",               group="Color Scheme")
bb_basis_color                  = input(color.new(color.rgb(255,109,0), 0),     type = input.color,     title="Bollinger Band Basis",           group="Color Scheme")
bb_band_color                   = input(color.new(color.rgb(41,98,255), 0),     type = input.color,     title="Bollinger Upper/Lower Band",     group="Color Scheme")
bb_bg_color                     = input(color.new(color.rgb(33, 150, 243), 95), type = input.color,     title="Bollinger Background",           group="Color Scheme")


// Calculations
//==============================================================================
// Floor Pivots
// Central Pivot
pivot = (high + low + close) / 3.0
// Resistance Levels
r1 = (2 * pivot) - low
r2 = pivot + (high - low)
r3 = r1 + (high - low)
r4 = r3 + (r2 - r1)
// Support Levels
s1 = (2 * pivot) - high
s2 = pivot - (high - low)
s3 = s1 - (high - low)
s4 = s3 - (s1 - s2)
// Central Pivot Range
temp_bc = (high + low) / 2
temp_tc = (pivot - temp_bc) + pivot
tc = temp_tc > temp_bc ? temp_tc : temp_bc
bc = temp_bc < temp_tc ? temp_bc : temp_tc
// Dynamic Floor Pivots
dynamic_pivot_atr = atr(dynamic_pivot_atr_period) * dynamic_pivot_atr_threshold
dynamic_high = high + dynamic_pivot_atr
dynamic_low = low - dynamic_pivot_atr
// Average True Range for Pivot Level Dilation
atr_norm = atr(atr_period) * atr_multiplier
// Timeframe
floor_pivot_resolution = floor_pivot_timeframe
// Bonus Indicators
val_ma1 = if ma1 == "SMA"       // Moving Average 1
    sma(src1, len1)
else if ma1 == "EMA"
    ema(src1, len1)
else if ma1 == "WMA"
    wma(src1, len1)
else if ma1 == "VWMA"
    vwma(src1, len1)
val_ma2 = if ma2 == "SMA"       // Moving Average 2
    sma(src2, len2)
else if ma2 == "EMA"
    ema(src2, len2)
else if ma2 == "WMA"
    wma(src2, len2)
else if ma2 == "VWMA"
    vwma(src2, len2)
val_ma3 = if ma3 == "SMA"       // Moving Average 3
    sma(src3, len3)
else if ma3 == "EMA"
    ema(src3, len3)
else if ma3 == "WMA"
    wma(src3, len3)
else if ma3 == "VWMA"
    vwma(src3, len3)
basis = sma(srcbb, lenbb)       // Bollinger Band
dev = mult * stdev(srcbb, lenbb)
upper = basis + dev
lower = basis - dev


// Floor Pivots
//==============================================================================
// Dynamic Floor Pivot Variables
var bool show_daily_pivot   = na
var bool show_daily_r1      = na
var bool show_daily_r2      = na
var bool show_daily_r3      = na
var bool show_daily_r4      = na
var bool show_daily_s1      = na
var bool show_daily_s2      = na
var bool show_daily_s3      = na
var bool show_daily_s4      = na
// Daily Average True Range for ATR Dilation
daily_atr_dilation = security(syminfo.tickerid, 'D', atr_norm[1], barmerge.gaps_off, barmerge.lookahead_on)
// Daily Floor Pivots
daily_pivot = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? pivot : pivot[1],        barmerge.gaps_off, barmerge.lookahead_on)
daily_r1    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? r1 : r1[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_r2    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? r2 : r2[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_r3    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? r3 : r3[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_r4    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? r4 : r4[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_s1    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? s1 : s1[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_s2    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? s2 : s2[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_s3    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? s3 : s3[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_s4    = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? s4 : s4[1],              barmerge.gaps_off, barmerge.lookahead_on)
daily_tbc   = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? temp_bc : temp_bc[1],    barmerge.gaps_off, barmerge.lookahead_on)
daily_ttc   = security(syminfo.tickerid, floor_pivot_resolution, show_next_day_pivot ? temp_tc : temp_tc[1],    barmerge.gaps_off, barmerge.lookahead_on)
daily_tc    = daily_ttc > daily_tbc ? daily_ttc : daily_tbc
daily_bc    = daily_tbc < daily_ttc ? daily_tbc : daily_ttc
// Dynamic Daily Floor Pivot Logic (only for Intraday)
show_daily_pivot    := show_daily_pivot[1]  == false and dynamic_pivot_levels and timeframe.isintraday and ((daily_pivot  >= dynamic_low and daily_pivot  <= dynamic_high) or (daily_tc >= dynamic_low and daily_tc <= dynamic_high) or (daily_bc >= dynamic_low and daily_bc <= dynamic_high)) ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_pivot[1]  == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_r1       := show_daily_r1[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_r1       >= dynamic_low and daily_r1     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_r1[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_r2       := show_daily_r2[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_r2       >= dynamic_low and daily_r2     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_r2[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_r3       := show_daily_r3[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_r3       >= dynamic_low and daily_r3     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_r3[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_r4       := show_daily_r4[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_r4       >= dynamic_low and daily_r4     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_r4[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_s1       := show_daily_s1[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_s1       >= dynamic_low and daily_s1     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_s1[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_s2       := show_daily_s2[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_s2       >= dynamic_low and daily_s2     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_s2[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_s3       := show_daily_s3[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_s3       >= dynamic_low and daily_s3     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_s3[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0
show_daily_s4       := show_daily_s4[1]     == false and dynamic_pivot_levels and timeframe.isintraday and daily_s4       >= dynamic_low and daily_s4     <= dynamic_high ? 1 : dynamic_pivot_levels == false ? 1 : show_daily_s4[1]     == true and dayofmonth == dayofmonth[1] ? 1 : 0


// Plots  
//==============================================================================
// Neutral and ATR Dilated Positive plots
p1a = plot(show_floor_pivots and show_daily_pivot and not atr_dilation ? daily_pivot : show_floor_pivots and show_daily_pivot and atr_dilation and timeframe.isintraday ? daily_pivot+daily_atr_dilation : show_floor_pivots and show_daily_pivot and atr_dilation and not timeframe.isintraday ? daily_pivot : na, title = "Pivot",        color = color.new(floor_pivots_p_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r1a = plot(show_floor_pivots and show_daily_r1 and not atr_dilation ? daily_r1 : show_floor_pivots and show_daily_r1 and atr_dilation and timeframe.isintraday ? daily_r1+daily_atr_dilation : show_floor_pivots and show_daily_r1 and atr_dilation and not timeframe.isintraday ? daily_r1 : na,                   title = "R1",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r2a = plot(show_floor_pivots and show_daily_r2 and not atr_dilation ? daily_r2 : show_floor_pivots and show_daily_r2 and atr_dilation and timeframe.isintraday ? daily_r2+daily_atr_dilation : show_floor_pivots and show_daily_r2 and atr_dilation and not timeframe.isintraday ? daily_r2 : na,                   title = "R2",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r3a = plot(show_floor_pivots and show_daily_r3 and not atr_dilation ? daily_r3 : show_floor_pivots and show_daily_r3 and atr_dilation and timeframe.isintraday ? daily_r3+daily_atr_dilation : show_floor_pivots and show_daily_r3 and atr_dilation and not timeframe.isintraday ? daily_r3 : na,                   title = "R3",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r4a = plot(show_floor_pivots and show_daily_r4 and not atr_dilation ? daily_r4 : show_floor_pivots and show_daily_r4 and atr_dilation and timeframe.isintraday ? daily_r4+daily_atr_dilation : show_floor_pivots and show_daily_r4 and atr_dilation and not timeframe.isintraday ? daily_r4 : na,                   title = "R4",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s1a = plot(show_floor_pivots and show_daily_s1 and not atr_dilation ? daily_s1 : show_floor_pivots and show_daily_s1 and atr_dilation and timeframe.isintraday ? daily_s1+daily_atr_dilation : show_floor_pivots and show_daily_s1 and atr_dilation and not timeframe.isintraday ? daily_s1 : na,                   title = "S1",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s2a = plot(show_floor_pivots and show_daily_s2 and not atr_dilation ? daily_s2 : show_floor_pivots and show_daily_s2 and atr_dilation and timeframe.isintraday ? daily_s2+daily_atr_dilation : show_floor_pivots and show_daily_s2 and atr_dilation and not timeframe.isintraday ? daily_s2 : na,                   title = "S2",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s3a = plot(show_floor_pivots and show_daily_s3 and not atr_dilation ? daily_s3 : show_floor_pivots and show_daily_s3 and atr_dilation and timeframe.isintraday ? daily_s3+daily_atr_dilation : show_floor_pivots and show_daily_s3 and atr_dilation and not timeframe.isintraday ? daily_s3 : na,                   title = "S3",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s4a = plot(show_floor_pivots and show_daily_s4 and not atr_dilation ? daily_s4 : show_floor_pivots and show_daily_s4 and atr_dilation and timeframe.isintraday ? daily_s4+daily_atr_dilation : show_floor_pivots and show_daily_s4 and atr_dilation and not timeframe.isintraday ? daily_s4 : na,                   title = "S4",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
// ATR Dilated Negative Plots
p1b = plot(show_floor_pivots and show_daily_pivot and atr_dilation and timeframe.isintraday ? daily_pivot-daily_atr_dilation : na,         title = "DPivot",        color = color.new(floor_pivots_p_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r1b = plot(show_floor_pivots and show_daily_r1 and atr_dilation and timeframe.isintraday ? daily_r1-daily_atr_dilation : na,               title = "DR1",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r2b = plot(show_floor_pivots and show_daily_r2 and atr_dilation and timeframe.isintraday ? daily_r2-daily_atr_dilation : na,               title = "DR2",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r3b = plot(show_floor_pivots and show_daily_r3 and atr_dilation and timeframe.isintraday ? daily_r3-daily_atr_dilation : na,               title = "DR3",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
r4b = plot(show_floor_pivots and show_daily_r4 and atr_dilation and timeframe.isintraday ? daily_r4-daily_atr_dilation : na,               title = "DR4",           color = color.new(floor_pivots_r_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s1b = plot(show_floor_pivots and show_daily_s1 and atr_dilation and timeframe.isintraday ? daily_s1-daily_atr_dilation : na,               title = "DS1",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s2b = plot(show_floor_pivots and show_daily_s2 and atr_dilation and timeframe.isintraday ? daily_s2-daily_atr_dilation : na,               title = "DS2",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s3b = plot(show_floor_pivots and show_daily_s3 and atr_dilation and timeframe.isintraday ? daily_s3-daily_atr_dilation : na,               title = "DS3",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
s4b = plot(show_floor_pivots and show_daily_s4 and atr_dilation and timeframe.isintraday ? daily_s4-daily_atr_dilation : na,               title = "DS4",           color = color.new(floor_pivots_s_color, atr_dilation and timeframe.isintraday ? 100 : 0),   linewidth = 1, style = plot.style_circles)
// CPR Band
tcline = plot(show_cpr and show_daily_pivot and not atr_dilation ? daily_tc : show_cpr and show_daily_pivot and atr_dilation and timeframe.isintraday ? daily_tc+daily_atr_dilation : show_cpr and show_daily_pivot and atr_dilation and not timeframe.isintraday ? daily_tc : na,                                  title = "TC",           color = color.new(floor_pivots_cpr_color, atr_dilation and timeframe.isintraday ? 100 : 0), linewidth = 1, style = plot.style_circles)
bcline = plot(show_cpr and show_daily_pivot and not atr_dilation ? daily_bc : show_cpr and show_daily_pivot and atr_dilation and timeframe.isintraday ? daily_bc-daily_atr_dilation : show_cpr and show_daily_pivot and atr_dilation and not timeframe.isintraday ? daily_bc : na,                                  title = "BC",           color = color.new(floor_pivots_cpr_color, atr_dilation and timeframe.isintraday ? 100 : 0), linewidth = 1, style = plot.style_circles)
fill(tcline, bcline, color = color.new(floor_pivots_cpr_color, show_cpr and show_daily_pivot ? 75 : 100))
// Fill ATR Dilated bands
fill(p1a, p1b, color.new(floor_pivots_p_color, 75))
fill(r1a, r1b, color.new(floor_pivots_r_color, 75))
fill(r2a, r2b, color.new(floor_pivots_r_color, 75))
fill(r3a, r3b, color.new(floor_pivots_r_color, 75))
fill(r4a, r4b, color.new(floor_pivots_r_color, 75))
fill(s1a, s1b, color.new(floor_pivots_s_color, 75))
fill(s2a, s2b, color.new(floor_pivots_s_color, 75))
fill(s3a, s3b, color.new(floor_pivots_s_color, 75))
fill(s4a, s4b, color.new(floor_pivots_s_color, 75))
// Pivot Lables
if show_labels
    chper = time - time[1]
    chper := change(chper) > 0 ? chper[1] : chper

    var label plabel = na
    var label s1label = na, var label s2label = na, var label s3label = na, var label s4label = na
    var label r1label = na, var label r2label = na, var label r3label = na, var label r4label = na

    label.delete(plabel)
    label.delete(s1label), label.delete(s2label), label.delete(s3label), label.delete(s4label)
    label.delete(r1label), label.delete(r2label), label.delete(r3label), label.delete(r4label)
    if show_floor_pivots and show_daily_pivot
        plabel  := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_pivot+daily_atr_dilation    : daily_pivot,  text = "Pivot", color = floor_pivots_p_color, textcolor=color.black, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_r1
        r1label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_r1+daily_atr_dilation       : daily_r1,     text = "R1",    color = floor_pivots_r_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_r2
        r2label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_r2+daily_atr_dilation       : daily_r2,     text = "R2",    color = floor_pivots_r_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_r3
        r3label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_r3+daily_atr_dilation       : daily_r3,     text = "R3",    color = floor_pivots_r_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_r4
        r4label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_r4+daily_atr_dilation       : daily_r4,     text = "R4",    color = floor_pivots_r_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_s1
        s1label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_s1+daily_atr_dilation       : daily_s1,     text = "S1",    color = floor_pivots_s_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_s2
        s2label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_s2+daily_atr_dilation       : daily_s2,     text = "S2",    color = floor_pivots_s_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_s3
        s3label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_s3+daily_atr_dilation       : daily_s3,     text = "S3",    color = floor_pivots_s_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
    if show_floor_pivots and show_daily_s4
        s4label := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = atr_dilation and timeframe.isintraday ? daily_s4+daily_atr_dilation       : daily_s4,     text = "S4",    color = floor_pivots_s_color, textcolor=color.white, style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price)
// Bonus Indicators
// Moving Averages
plot(vis1 ? val_ma1 : na,                   title="Moving Average 1",       color=color.new(ma_1_color, 0), linewidth=1,    offset=off1)
plot(vis2 ? val_ma2 : na,                   title="Moving Average 2",       color=color.new(ma_2_color, 0), linewidth=1,    offset=off2)
plot(vis3 ? val_ma3 : na,                   title="Moving Average 3",       color=color.new(ma_3_color, 0), linewidth=1,    offset=off3)
// Bollinger Band
plot(visbb and visbb_basis? basis : na,     title="Bollinger Basis",        color=bb_basis_color,                           offset = offbb)
p1 = plot(visbb ? upper : na,               title="Bollinger Upper",        color=bb_band_color,                            offset = offbb)
p2 = plot(visbb ? lower : na,               title="Bollinger Lower",        color=bb_band_color,                            offset = offbb)
fill(p1, p2,                                title="Bollinger Background",   color=color.new(bb_bg_color, visbb ? 95 : 100))
A0b29lP.png


CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © pranjalchaubey
#//Structural Pivots
#study(title="[CP]Pivot Boss Floor Pivots with ATR Dilation and Dynamic Levels", shorttitle="[CP]Pivot Boss Floor Pivots",
# Converted by Sam4Cok@Samer800 - 01/2023
#// User Inputs
input floor_pivot_timeframe = AggregationPeriod.DAY;    # "Floor Pivot Timeframe"
input show_floor_pivots     = yes;    # "Show Floor Pivots"
input show_cpr              = yes;    # "Show CPR"
input show_labels           = no;    # "Show Pivot Lables"
input show_next_day_pivot   = no;     # "Show Next Time Period Pivots", 
input dynamic_pivot_levels  = yes;    #"Show Floor Pivot Levels Dynamically"
input dynamic_pivot_atr_period = 14;  # "Dynamic Pivot ATR Period",
input dynamic_pivot_atr_threshold  = 2.0;# "ATR Threshold for Dynamic Floor Pivots"
input atr_dilation   = yes;  # "Use ATR to Dilate Intraday Pivot Levels"
input atr_multiplier = 0.05; # "ATR Dilation Factor"
input atr_period     = 14;   # "ATR Period"

def na = Double.NaN;
def Agg = AggregationPeriod.DAY;
def current = GetAggregationPeriod();
def isintraday = Agg > current and !isNaN(close);
def today = GetDay();
def rollover = today == today[1];
def dayofmonth = rollover;

#// Calculations 
#// Floor Pivots
#// Central Pivot
def thi = high(Period  = floor_pivot_timeframe);
def tlo = low(Period   = floor_pivot_timeframe);
def tcl = close(Period = floor_pivot_timeframe);
def hi;
def lo;
def cl;
if show_next_day_pivot {
    hi = thi;
    lo = tlo;
    cl = tcl;
} else {
    hi = thi[1];
    lo = tlo[1];
    cl = tcl[1];
}
def pivot = (hi + lo + cl) / 3.0;
#// Resistance Levels
def r1 = (2 * pivot) - lo;
def r2 = pivot + (hi - lo);
def r3 = r1 + (hi - lo);
def r4 = r3 + (r2 - r1);
#// Support Levels
def s1 = (2 * pivot) - hi;
def s2 = pivot - (hi - lo);
def s3 = s1 - (hi - lo);
def s4 = s3 - (s1 - s2);
#// Central Pivot Range
def temp_bc = (hi + lo) / 2;
def temp_tc = (pivot - temp_bc) + pivot;
def tc = if temp_tc > temp_bc then temp_tc else temp_bc;
def bc = if temp_bc < temp_tc then temp_bc else temp_tc;
#// Dynamic Floor Pivots
def dynamic_pivot_atr = ATR(LENGTH = dynamic_pivot_atr_period) * dynamic_pivot_atr_threshold;
def dynamic_high = high + dynamic_pivot_atr;
def dynamic_low  = low - dynamic_pivot_atr;
#// Average True Range for Pivot Level Dilation
def trDilation = TrueRange(thi, tcl, tlo);
def atrdilation = WildersAverage(trDilation, atr_period);
def daily_atr_dilation = atrdilation * atr_multiplier;

def daily_pivot = pivot;
def daily_r1    = r1;
def daily_r2    = r2;
def daily_r3    = r3;
def daily_r4    = r4;
def daily_s1    = s1;
def daily_s2    = s2;
def daily_s3    = s3;
def daily_s4    = s4;
def daily_tbc   = temp_bc;
def daily_ttc   = temp_tc;

def daily_tc    = if daily_ttc > daily_tbc then daily_ttc else daily_tbc;
def daily_bc    = if daily_tbc < daily_ttc then daily_tbc else daily_ttc;
#// Dynamic Daily Floor Pivot Logic (only for Intraday)
def show_daily_pivot = if !dynamic_pivot_levels then 1 else
                       if !show_daily_pivot[1] and isintraday and ((daily_pivot>= dynamic_low and daily_pivot<= dynamic_high)
                       or (daily_tc >= dynamic_low and daily_tc <= dynamic_high)
                       or (daily_bc >= dynamic_low and daily_bc <= dynamic_high)) then 1 else
                       if show_daily_pivot[1] and dayofmonth then 1 else 0;
def show_daily_r1 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_r1[1] and isintraday and daily_r1 >= dynamic_low and daily_r1 <= dynamic_high then 1 else
                    if  show_daily_r1[1] and dayofmonth then 1 else 0;
def show_daily_r2 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_r2[1] and isintraday and daily_r2 >= dynamic_low and daily_r2 <= dynamic_high then 1 else
                    if show_daily_r2[1] and dayofmonth then 1 else 0;
def show_daily_r3 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_r3[1] and isintraday and daily_r3 >= dynamic_low and daily_r3 <= dynamic_high then 1 else
                    if show_daily_r3[1] and dayofmonth then 1 else 0;
def show_daily_r4 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_r4[1] and isintraday and daily_r4 >= dynamic_low and daily_r4  <= dynamic_high then 1 else
                    if show_daily_r4[1] and dayofmonth then 1 else 0;
def show_daily_s1 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_s1[1] and isintraday and daily_s1 >= dynamic_low and daily_s1 <= dynamic_high then 1 else
                    if show_daily_s1[1] and dayofmonth then 1 else 0;
def show_daily_s2 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_s2[1] and isintraday and daily_s2 >= dynamic_low and daily_s2 <= dynamic_high then 1 else
                    if show_daily_s2[1] and dayofmonth then 1 else 0;
def show_daily_s3 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_s3[1] and isintraday and daily_s3 >= dynamic_low and daily_s3 <= dynamic_high then 1 else
                    if show_daily_s3[1] and dayofmonth then 1 else 0;
def show_daily_s4 = if !dynamic_pivot_levels then 1 else
                    if !show_daily_s4[1] and isintraday and daily_s4 >= dynamic_low and daily_s4 <= dynamic_high then 1 else
                    if show_daily_s4[1] and dayofmonth then 1 else 0;

#// Plots   
#// Neutral and ATR Dilated Positive plots
plot p1a = if show_floor_pivots and show_daily_pivot then
          if !atr_dilation then daily_pivot else
          if isintraday then daily_pivot+daily_atr_dilation else daily_pivot else na;
plot r1a = if show_floor_pivots and show_daily_r1 then
          if !atr_dilation then daily_r1 else
          if isintraday then daily_r1+daily_atr_dilation else daily_r1 else na;
plot r2a = if show_floor_pivots and show_daily_r2 then
          if !atr_dilation then daily_r2 else
          if isintraday then daily_r2+daily_atr_dilation else daily_r2 else na;
plot r3a = if show_floor_pivots and show_daily_r3 then
          if !atr_dilation then daily_r3 else
          if isintraday then daily_r3+daily_atr_dilation else daily_r3 else na;
plot r4a = if show_floor_pivots and show_daily_r4 then
          if !atr_dilation then daily_r4 else
          if isintraday then daily_r4+daily_atr_dilation else daily_r4 else na;
plot s1a = if show_floor_pivots and show_daily_s1 then
          if !atr_dilation then daily_s1 else
          if isintraday then daily_s1+daily_atr_dilation else daily_s1 else na;
plot s2a = if show_floor_pivots and show_daily_s2 then
          if !atr_dilation then daily_s2 else
          if isintraday then daily_s2+daily_atr_dilation else daily_s2 else na;
plot s3a = if show_floor_pivots and show_daily_s3 then
          if !atr_dilation then daily_s3 else
          if isintraday then daily_s3+daily_atr_dilation else daily_s3 else na;
plot s4a = if show_floor_pivots and show_daily_s4 then
          if !atr_dilation then daily_s4 else
          if isintraday then daily_s4+daily_atr_dilation else daily_s4 else na;
p1a.SetHiding(atr_dilation);
r1a.SetHiding(atr_dilation);
r2a.SetHiding(atr_dilation);
r3a.SetHiding(atr_dilation);
r4a.SetHiding(atr_dilation);
s1a.SetHiding(atr_dilation);
s2a.SetHiding(atr_dilation);
s3a.SetHiding(atr_dilation);
s4a.SetHiding(atr_dilation);
p1a.SetDefaultColor(CreateColor(204,188,47));
r1a.SetDefaultColor(Color.RED);
r2a.SetDefaultColor(Color.RED);
r3a.SetDefaultColor(Color.RED);
r4a.SetDefaultColor(Color.RED);
s1a.SetDefaultColor(Color.GREEN);
s2a.SetDefaultColor(Color.GREEN);
s3a.SetDefaultColor(Color.GREEN);
s4a.SetDefaultColor(Color.GREEN);
#// ATR Dilated Negative Plots
plot p1b = if show_floor_pivots and show_daily_pivot and atr_dilation and isintraday then daily_pivot-daily_atr_dilation else na;
plot r1b = if show_floor_pivots and show_daily_r1 and atr_dilation and isintraday then daily_r1-daily_atr_dilation else na;
plot r2b = if show_floor_pivots and show_daily_r2 and atr_dilation and isintraday then daily_r2-daily_atr_dilation else na;
plot r3b = if show_floor_pivots and show_daily_r3 and atr_dilation and isintraday then daily_r3-daily_atr_dilation else na;
plot r4b = if show_floor_pivots and show_daily_r4 and atr_dilation and isintraday then daily_r4-daily_atr_dilation else na;
plot s1b = if show_floor_pivots and show_daily_s1 and atr_dilation and isintraday then daily_s1-daily_atr_dilation else na;
plot s2b = if show_floor_pivots and show_daily_s2 and atr_dilation and isintraday then daily_s2-daily_atr_dilation else na;
plot s3b = if show_floor_pivots and show_daily_s3 and atr_dilation and isintraday then daily_s3-daily_atr_dilation else na;
plot s4b = if show_floor_pivots and show_daily_s4 and atr_dilation and isintraday then daily_s4-daily_atr_dilation else na;
p1b.SetHiding(atr_dilation);
r1b.SetHiding(atr_dilation);
r2b.SetHiding(atr_dilation);
r3b.SetHiding(atr_dilation);
r4b.SetHiding(atr_dilation);
s1b.SetHiding(atr_dilation);
s2b.SetHiding(atr_dilation);
s3b.SetHiding(atr_dilation);
s4b.SetHiding(atr_dilation);
p1b.SetDefaultColor(CreateColor(204,188,47));
r1b.SetDefaultColor(Color.RED);
r2b.SetDefaultColor(Color.RED);
r3b.SetDefaultColor(Color.RED);
r4b.SetDefaultColor(Color.RED);
s1b.SetDefaultColor(Color.GREEN);
s2b.SetDefaultColor(Color.GREEN);
s3b.SetDefaultColor(Color.GREEN);
s4b.SetDefaultColor(Color.GREEN);
#// CPR Band
plot tcline = if isNaN(close) then na else
             if show_cpr and show_daily_pivot then
             if !atr_dilation then daily_tc else
             if  isintraday then daily_tc+daily_atr_dilation else daily_tc else na;
plot bcline =  if isNaN(close) then na else
             if show_cpr and show_daily_pivot then
             if !atr_dilation then daily_bc else
             if  isintraday then daily_bc-daily_atr_dilation else daily_bc else na;
tcline.SetHiding(atr_dilation);
bcline.SetHiding(atr_dilation);
tcline.SetDefaultColor(CreateColor(26,120,194));
bcline.SetDefaultColor(CreateColor(26,120,194));

AddCloud(tcline, bcline, CreateColor(26,120,194));

#// Fill ATR Dilated bands
AddCloud(p1a, p1b, CreateColor(204,188,47));
AddCloud(r1a, r1b, Color.DARK_RED);
AddCloud(r2a, r2b, Color.DARK_RED);
AddCloud(r3a, r3b, Color.DARK_RED);
AddCloud(r4a, r4b, Color.DARK_RED);
AddCloud(s1a, s1b, Color.DARK_GREEN);
AddCloud(s2a, s2b, Color.DARK_GREEN);
AddCloud(s3a, s3b, Color.DARK_GREEN);
AddCloud(s4a, s4b, Color.DARK_GREEN);

#--- Bubbles
def label = if show_labels then !isintraday[-1] else na;

AddChartBubble(label and p1a and isNaN(p1a[-1]), p1a, "Pivot", CreateColor(204,188,47), yes);
AddChartBubble(label and r1a and isNaN(r1a[-1]), r1a, "R1", Color.RED, yes);
AddChartBubble(label and r2a and isNaN(r2a[-1]), r2a, "R2", Color.RED, yes);
AddChartBubble(label and r3a and isNaN(r3a[-1]), r3a, "R3", Color.RED, yes);
AddChartBubble(label and r4a and isNaN(r4a[-1]), r4a, "R4", Color.RED, yes);

AddChartBubble(label and s1a and isNaN(s1a[-1]), s1a, "S1", Color.GREEN, yes);
AddChartBubble(label and s2a and isNaN(s2a[-1]), s2a, "S2", Color.GREEN, yes);
AddChartBubble(label and s3a and isNaN(s3a[-1]), s3a, "S3", Color.GREEN, yes);
AddChartBubble(label and s4a and isNaN(s4a[-1]), s4a, "S4", Color.GREEN, yes);

#--- END CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
507 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top