Indicator · Pine Script v6 · On the chart

Chintan Cheatcode

by onlyspx· code credited to Chintan

This indicator overlays a stack of reference lines on the price chart for index trading: session VWAP, optional two-day, weekly and monthly VWAP, an hourly 20-period average, daily 5, 20, 50 and 200 averages and a daily halfback midpoint.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code648
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago1 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

648 lines of Pine Script v6 from Chintan_Cheatcode.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Chintan_Cheatcode.pine
// This Pine Script(TM) code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Chintan

// @version=6
indicator("Chintan Cheatcode", shorttitle="Chintan Cheatcode", overlay=true, max_boxes_count=500, max_labels_count=64)


//--------------------------------------------------------------------
//#region                        Inputs
//--------------------------------------------------------------------

g_vwap         = "VWAP"
g_hourly       = "Hourly 20 SMA"
g_daily_5      = "Daily 5 SMA"
g_daily_20     = "Daily 20 SMA"
g_daily_50     = "Daily 50 SMA"
g_daily_200    = "Daily 200 SMA"
g_daily_halfback = "Daily Halfback"
g_atr          = "ATR Levels"
g_prior_day    = "Prior Day Levels"
g_preferences  = "Preferences"

tt_timeframe = "Higher-timeframe lines are automatically hidden when the chart timeframe is above their source timeframe."

i_showVwap        = input.bool(true, "Show", group=g_vwap, display=display.none)
i_colorVwap       = input.color(color.new(#FF69B4, 0), "Color", group=g_vwap, display=display.none)

g_vwap2d          = "2-Day VWAP"
i_showVwap2d      = input.bool(false, "Show Line", group=g_vwap2d, display=display.none)
i_colorVwap2d     = input.color(color.new(#FF9800, 0), "Color", group=g_vwap2d, display=display.none)

g_vwapWtd         = "WTD VWAP"
i_showVwapWtd     = input.bool(false, "Show Line", group=g_vwapWtd, display=display.none)
i_colorVwapWtd    = input.color(color.new(#66BB6A, 0), "Color", group=g_vwapWtd, display=display.none)

g_vwapMtd         = "MTD VWAP"
i_showVwapMtd     = input.bool(false, "Show Line", group=g_vwapMtd, display=display.none)
i_colorVwapMtd    = input.color(color.new(#CE93D8, 0), "Color", group=g_vwapMtd, display=display.none)

i_showHourly20    = input.bool(true, "Show", group=g_hourly, tooltip=tt_timeframe, display=display.none)
i_colorHourly20   = input.color(color.new(#FFFF00, 0), "Color", group=g_hourly, display=display.none)

i_showDaily5      = input.bool(false, "Show Line", group=g_daily_5, tooltip=tt_timeframe, display=display.none)
i_colorDaily5     = input.color(color.new(#d9e7ff, 0), "Color", group=g_daily_5, display=display.none)

i_showDaily20     = input.bool(false, "Show Line", group=g_daily_20, tooltip=tt_timeframe, display=display.none)
i_colorDaily20    = input.color(color.new(#a4c2f4, 0), "Color", group=g_daily_20, display=display.none)

i_showDaily50     = input.bool(false, "Show Line", group=g_daily_50, tooltip=tt_timeframe, display=display.none)
i_colorDaily50    = input.color(color.new(#6d9eeb, 0), "Color", group=g_daily_50, display=display.none)

i_showDaily200    = input.bool(false, "Show Line", group=g_daily_200, tooltip=tt_timeframe, display=display.none)
i_colorDaily200   = input.color(color.new(#1c4587, 0), "Color", group=g_daily_200, display=display.none)

i_showDailyHalfback  = input.bool(true, "Show Line", group=g_daily_halfback, tooltip=tt_timeframe, display=display.none)
i_colorDailyHalfback = input.color(color.new(#9E9D24, 0), "Color", group=g_daily_halfback, display=display.none)
i_halfbackPlotStyle  = input.string("Stepline", "Plot style", options=["Stepline", "Line"], group=g_daily_halfback, tooltip="Stepline: flat until session high/low changes. Line: connects per-bar midpoint.", display=display.none)
i_showHalfbackLabel  = input.bool(true, "Label on last bar", group=g_daily_halfback, display=display.none)

i_showAtrLevels   = input.bool(false, "Show Lines", group=g_atr, tooltip=tt_timeframe, display=display.none)
i_atrLength       = input.int(14, "ATR Length", minval=1, group=g_atr, display=display.none)
i_colorAtrUp      = input.color(color.new(#00E5FF, 0), "+1 ATR Color", group=g_atr, display=display.none)
i_colorAtrDown    = input.color(color.new(#FFD54F, 0), "-1 ATR Color", group=g_atr, display=display.none)
i_showAtrTable    = input.bool(true, "Show ATR Table", group=g_atr, display=display.none)
i_showMaTable     = input.bool(true, "Show MA Table", group=g_atr, display=display.none)
i_rvolPeriod      = input.int(5, "RVOL Lookback Days", minval=1, maxval=10, group=g_atr, display=display.none)

i_showPriorDay         = input.bool(true, "Show", group=g_prior_day, tooltip=tt_timeframe, display=display.none)
i_colorPriorHigh       = input.color(color.new(#66BB6A, 0), "Prior Day High Color", group=g_prior_day, display=display.none)
i_colorPriorLow        = input.color(color.new(#EF5350, 0), "Prior Day Low Color", group=g_prior_day, display=display.none)
i_showPriorLevelLabels = input.bool(true, "Labels on last bar (PDH/PDL/PWH/PWL/PW mid)", group=g_prior_day, display=display.none)

g_prior_week      = "Prior Week"
i_showPriorWeek     = input.bool(true, "Show", group=g_prior_week, display=display.none)
i_colorPriorWeekH   = input.color(color.new(#66BB6A, 0), "Prior Week High Color", group=g_prior_week, display=display.none)
i_colorPriorWeekL   = input.color(color.new(#EF5350, 0), "Prior Week Low Color",  group=g_prior_week, display=display.none)
i_showPriorWeekMid  = input.bool(true, "Show prior week midpoint", group=g_prior_week, display=display.none)
i_colorPriorWeekMid = input.color(color.new(#78909C, 0), "Prior Week Mid Color", group=g_prior_week, display=display.none)

g_orb               = "30-Min ORB"
tt_orb              = "30-min opening range shown on intraday charts up to 60 minutes."
i_showOrbBox        = input.bool(true, "Show Box", group=g_orb, tooltip=tt_orb, display=display.none)
i_colorOrbBox       = input.color(color.new(#FF8F00, 0), "Box Color", group=g_orb, display=display.none)
i_showOrbText       = input.bool(true, "Show ORB Range Text", group=g_orb, tooltip=tt_orb, display=display.none)

g_first_hour        = "First Hour Range"
tt_firstHour        = "First-hour range is shown on intraday charts up to 60 minutes."
i_showFirstHourBox  = input.bool(true, "Show Box", group=g_first_hour, tooltip=tt_firstHour, display=display.none)
i_colorFirstHourBox = input.color(color.new(#546E7A, 0), "Box Color", group=g_first_hour, display=display.none)
i_showFirstHourText = input.bool(true, "Show 1HR Range Text", group=g_first_hour, tooltip=tt_firstHour, display=display.none)


i_waitForCloses   = input.bool(true, "Wait for timeframe closes", group=g_preferences, display=display.none)
i_showKeyTimes    = input.bool(true, "Show Key Time Markers", group=g_preferences, display=display.none)

g_gaps               = "Gaps"
i_showGaps           = input.bool(true, "Show", group=g_gaps, display=display.none)
i_closeGapsPartially = input.bool(false, "Close Gaps Partially", group=g_gaps, display=display.none)
i_gapBoxLimit        = input.int(15, "Max Number of Gaps", minval=1, maxval=500, group=g_gaps, display=display.none)
i_gapMinDevPct       = input.float(30.0, "Minimal Deviation (%)", minval=1, maxval=100, group=g_gaps, tooltip="Specifies the minimal size of detected gaps, as a percentage of the average high-low range for the last 14 bars.", display=display.none)
i_limitGapLength     = input.bool(false, "Limit Max Gap Trail Length (bars)", inline="GapLen", group=g_gaps, display=display.none)
i_gapMaxBars         = input.int(300, "", inline="GapLen", minval=1, group=g_gaps, display=display.none, active=i_limitGapLength)
i_colorGapUpBorder   = input.color(color.green, "Up Gaps", inline="GapUp", group=g_gaps, display=display.none)
i_colorGapUpBg       = input.color(color.new(color.green, 85), "", inline="GapUp", group=g_gaps, display=display.none)
i_colorGapDownBorder = input.color(color.red, "Down Gaps", inline="GapDn", group=g_gaps, display=display.none)
i_colorGapDownBg     = input.color(color.new(color.red, 85), "", inline="GapDn", group=g_gaps, display=display.none)
i_gapMinPoints       = input.float(10.0, "Min gap size (points)", minval=0, step=0.25, group=g_gaps, tooltip="Minimum absolute gap size for gap boxes.", display=display.none)

//#endregion


//--------------------------------------------------------------------
//#region                       Functions
//--------------------------------------------------------------------

f_canDisplay(string _tf) =>
    timeframe.in_seconds(_tf) >= timeframe.in_seconds()

f_getHtfSma(string _tf, int _length) =>
    i_waitForCloses ?
         request.security(syminfo.tickerid, _tf, ta.sma(close, _length)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) :
         request.security(syminfo.tickerid, _tf, ta.sma(close, _length), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)


type Gap
    bool isActive
    bool isBull
    array<box> boxes

method delete(Gap this) =>
    for _box in this.boxes
        _box.delete()

method partialClose(Gap this) =>
    activeBox = this.boxes.last()
    activeBox.set_extend(extend.none)
    top    = this.isBull ? activeBox.get_top() : low
    bottom = this.isBull ? high : activeBox.get_bottom()
    this.boxes.push(box.new(bar_index, top, bar_index, bottom,
      this.isBull ? i_colorGapDownBorder : i_colorGapUpBorder,
      bgcolor = this.isBull ? i_colorGapDownBg : i_colorGapUpBg))

method fullClose(Gap this) =>
    activeBox = this.boxes.last()
    activeBox.set_extend(extend.none)
    this.isActive := false
    if i_closeGapsPartially
        activeBox.delete()

method checkForClose(Gap this) =>
    if this.isActive
        activeBox = this.boxes.last()
        top    = activeBox.get_top()
        bot    = activeBox.get_bottom()
        isBull = this.isBull
        activeBox.set_right(bar_index)
        if (high > bot and isBull) or (low < top and not isBull)
            if i_closeGapsPartially
                this.partialClose()
            else
                this.fullClose()
        bool forceClose = i_limitGapLength and bar_index - activeBox.get_left() >= i_gapMaxBars
        if ((high > top and isBull) or (low < bot and not isBull)) or forceClose
            this.fullClose()

//#endregion


//--------------------------------------------------------------------
//#region                         Logic
//--------------------------------------------------------------------

vwap = ta.vwap(close)

typicalPrice = hlc3

var float sumPV_2day = 0.0
var float sumV_2day  = 0.0
var float sumPV_wtd  = 0.0
var float sumV_wtd   = 0.0
var float sumPV_mtd  = 0.0
var float sumV_mtd   = 0.0

new2Day  = ta.change(time("2D")) != 0
newWeek  = ta.change(time("W"))  != 0
newMonth = ta.change(time("M"))  != 0

if new2Day
    sumPV_2day := 0.0
    sumV_2day  := 0.0
if newWeek
    sumPV_wtd := 0.0
    sumV_wtd  := 0.0
if newMonth
    sumPV_mtd := 0.0
    sumV_mtd  := 0.0

sumPV_2day += typicalPrice * volume
sumV_2day  += volume
sumPV_wtd  += typicalPrice * volume
sumV_wtd   += volume
sumPV_mtd  += typicalPrice * volume
sumV_mtd   += volume

vwap_2day = sumV_2day != 0 ? sumPV_2day / sumV_2day : na
vwap_wtd  = sumV_wtd  != 0 ? sumPV_wtd  / sumV_wtd  : na
vwap_mtd  = sumV_mtd  != 0 ? sumPV_mtd  / sumV_mtd  : na

hourly20 = f_getHtfSma("60", 20)

daily5 = f_getHtfSma("D", 5)
daily20 = f_getHtfSma("D", 20)
daily50 = f_getHtfSma("D", 50)
daily200 = f_getHtfSma("D", 200)

var float dayHigh = na
var float dayLow  = na

if ta.change(time("D")) != 0 or na(dayHigh)
    dayHigh := high
    dayLow  := low
else
    dayHigh := math.max(dayHigh, high)
    dayLow  := math.min(dayLow, low)

dailyHalfback = dayLow + (dayHigh - dayLow) / 2.0

atrTicker = ticker.new(syminfo.prefix, syminfo.ticker, session=session.extended)
atrBase = i_waitForCloses ?
     request.security(atrTicker, "D", close[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) :
     request.security(atrTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
atrValue = i_waitForCloses ?
     request.security(atrTicker, "D", ta.atr(i_atrLength)[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) :
     request.security(atrTicker, "D", ta.atr(i_atrLength), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)

atrPlus1 = atrBase + atrValue
atrMinus1 = atrBase - atrValue

priorDayHigh  = request.security(syminfo.tickerid, "D", high[1],  gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
priorDayLow   = request.security(syminfo.tickerid, "D", low[1],   gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
priorWeekHigh = request.security(syminfo.tickerid, "W", high[1],  gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
priorWeekLow  = request.security(syminfo.tickerid, "W", low[1],   gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
priorWeekMid  = not na(priorWeekHigh) and not na(priorWeekLow) ? (priorWeekHigh + priorWeekLow) * 0.5 : na

hrHigh = request.security(syminfo.tickerid, "60", high, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
hrLow  = request.security(syminfo.tickerid, "60", low,  gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
hrRange = hrHigh - hrLow

orbSession             = "0930-1000:23456"
orbTimeZone            = "America/New_York"
canTrackOrb            = timeframe.isintraday and timeframe.in_seconds() <= timeframe.in_seconds("60")
orbFeatureEnabled      = canTrackOrb and (i_showOrbBox or i_showOrbText)
inOrb                  = orbFeatureEnabled and not na(time(timeframe.period, orbSession, orbTimeZone))
orbStart               = inOrb and not inOrb[1]

var float orbHigh = na
var float orbLow  = na

firstHourSession       = "0930-1030:23456"
firstHourTimeZone      = "America/New_York"
canTrackFirstHour      = timeframe.isintraday and timeframe.in_seconds() <= timeframe.in_seconds("60")
firstHourFeatureEnabled = canTrackFirstHour and (i_showFirstHourBox or i_showFirstHourText)
inFirstHour            = firstHourFeatureEnabled and not na(time(timeframe.period, firstHourSession, firstHourTimeZone))
firstHourStart         = inFirstHour and not inFirstHour[1]
newUsDay               = canTrackFirstHour and nz(ta.change(time("D", "0000-2359:23456", firstHourTimeZone)), 0) != 0

var float firstHourHigh = na
var float firstHourLow  = na

showDailyLevels = f_canDisplay("D")
newDay = ta.change(time("D")) != 0
barsSinceDayStart = nz(ta.barssince(newDay), 0)
dayStartIndex = bar_index - barsSinceDayStart

rvolSessLen  = 390  // 9:30–4:00 ET = 390 min, no midnight crossing for SPX
var float[] rvolVols = array.new_float(rvolSessLen * 11, 0.0)  // max 10 days + current = 4,290 elements

// Relative volume — session-relative slots (fast: 390 slots/day vs 2880, 4290 elements vs 60480)
// Uses ET hour/minute to compute session-relative slot (0=9:30, 389=15:59)
inRvolSess = not na(time(timeframe.period, "0930-1600:23456", "America/New_York"))
rvolEtHour = hour(time, "America/New_York")
rvolEtMin  = minute(time, "America/New_York")
rvolSlot   = math.max(0, math.min(rvolEtHour * 60 + rvolEtMin - 570, rvolSessLen - 1))  // 570 = 9*60+30

if newDay
    for _i = 1 to rvolSessLen
        array.shift(rvolVols)
        array.push(rvolVols, 0.0)

if inRvolSess
    rvolIdx = i_rvolPeriod * rvolSessLen + rvolSlot
    array.set(rvolVols, rvolIdx, newDay ? volume : array.get(rvolVols, i_rvolPeriod * rvolSessLen + rvolSlot[1]) + volume)

rvolCalc() =>
    hvol      = 0.0
    validDays = 0
    for x = 0 to i_rvolPeriod - 1
        svol = array.get(rvolVols, x * rvolSessLen + rvolSlot)
        if svol > 0.0
            hvol      += svol
            validDays += 1
    cvol = array.get(rvolVols, i_rvolPeriod * rvolSessLen + rvolSlot)
    validDays > 0 ? cvol / (hvol / validDays) : na

rvol = timeframe.isintraday ? rvolCalc() : na

// Gaps (min deviation % and absolute min points)
gapMinDev = nz(i_gapMinDevPct / 100 * ta.sma(high - low, 14))
gapSzUp   = not na(high[1]) ? low - high[1] : na
gapSzDn   = not na(low[1]) ? low[1] - high : na
strucGapUp   = not na(gapSzUp) and low > high[1] and gapSzUp >= gapMinDev and gapSzUp >= i_gapMinPoints
strucGapDown = not na(gapSzDn) and high < low[1] and gapSzDn >= gapMinDev and gapSzDn >= i_gapMinPoints
isGapUp   = i_showGaps and strucGapUp
isGapDown = i_showGaps and strucGapDown
isGap     = isGapDown or isGapUp

var array<Gap> allGaps = array.new<Gap>()

gapRegisterNew(bool _isGapDown) =>
    newBox = box.new(
      bar_index - 1,
      _isGapDown ? low[1] : low,
      bar_index,
      _isGapDown ? high : high[1],
      border_color = _isGapDown ? i_colorGapDownBorder : i_colorGapUpBorder,
      bgcolor      = _isGapDown ? i_colorGapDownBg     : i_colorGapUpBg,
      extend       = extend.right)
    allGaps.push(Gap.new(true, _isGapDown, array.from(newBox)))
    if allGaps.size() > i_gapBoxLimit
        allGaps.shift().delete()

if i_showGaps
    for gap in allGaps
        gap.checkForClose()
    if isGap
        gapRegisterNew(isGapDown)

var line atrPlus1Line = na
var line atrMinus1Line = na
var label halfbackLastLabel = na
var label pdhLastLabel = na
var label pdlLastLabel = na
var label pwhLastLabel = na
var label pwlLastLabel = na
var label pwmLastLabel = na
var box  orbBox       = na
var box  firstHourBox = na
var table atrTable = table.new(position.top_right,    3, 2)
var table maTable  = table.new(position.bottom_right, 2, 5)

//#endregion


//--------------------------------------------------------------------
//#region                   Plotting & styling
//--------------------------------------------------------------------

plot(i_showVwap    ? vwap      : na, "VWAP",        i_colorVwap,   1, style=plot.style_circles, display=display.all - display.status_line)
plot(i_showVwap2d  ? vwap_2day : na, "2-Day VWAP",  i_colorVwap2d, 1, display=display.all - display.status_line)
plot(i_showVwapWtd ? vwap_wtd  : na, "WTD VWAP",    i_colorVwapWtd, 1, display=display.all - display.status_line)
plot(i_showVwapMtd ? vwap_mtd  : na, "MTD VWAP",    i_colorVwapMtd, 1, display=display.all - display.status_line)

plot(i_showHourly20 and f_canDisplay("60") ? hourly20 : na, "Hourly 20 SMA", i_colorHourly20, 1, display=display.all - display.status_line)

if newUsDay or not orbFeatureEnabled
    orbHigh := na
    orbLow  := na

if (newUsDay or not canTrackOrb or not i_showOrbBox) and not na(orbBox)
    box.delete(orbBox)
    orbBox := na

if orbFeatureEnabled
    if orbStart
        orbHigh := high
        orbLow  := low
        if i_showOrbBox
            if not na(orbBox)
                box.delete(orbBox)
            orbBox := box.new(left=bar_index, top=orbHigh, right=bar_index + 1, bottom=orbLow, xloc=xloc.bar_index, border_width=1, border_color=color.new(i_colorOrbBox, 20), bgcolor=color.new(i_colorOrbBox, 80))
    else if inOrb and not na(orbHigh)
        orbHigh := math.max(orbHigh, high)
        orbLow  := math.min(orbLow, low)
        if i_showOrbBox
            if na(orbBox)
                orbBox := box.new(left=bar_index, top=orbHigh, right=bar_index + 1, bottom=orbLow, xloc=xloc.bar_index, border_width=1, border_color=color.new(i_colorOrbBox, 20), bgcolor=color.new(i_colorOrbBox, 80))
            else
                box.set_top(orbBox, orbHigh)
                box.set_rightbottom(orbBox, right=bar_index + 1, bottom=orbLow)
                box.set_bgcolor(orbBox, color.new(i_colorOrbBox, 80))
                box.set_border_color(orbBox, color.new(i_colorOrbBox, 20))

if i_showOrbBox and canTrackOrb and not inOrb and not na(orbBox) and not na(orbHigh) and not na(orbLow)
    box.set_top(orbBox, orbHigh)
    box.set_rightbottom(orbBox, right=bar_index + 1, bottom=orbLow)
    box.set_bgcolor(orbBox, color.new(i_colorOrbBox, 80))
    box.set_border_color(orbBox, color.new(i_colorOrbBox, 20))

if newUsDay or not firstHourFeatureEnabled
    firstHourHigh := na
    firstHourLow  := na

if (newUsDay or not canTrackFirstHour or not i_showFirstHourBox) and not na(firstHourBox)
    box.delete(firstHourBox)
    firstHourBox := na

if firstHourFeatureEnabled
    if firstHourStart
        firstHourHigh := high
        firstHourLow  := low
        if i_showFirstHourBox
            if not na(firstHourBox)
                box.delete(firstHourBox)
            firstHourBox := box.new(left=bar_index, top=firstHourHigh, right=bar_index + 1, bottom=firstHourLow, xloc=xloc.bar_index, border_width=1, border_color=color.new(i_colorFirstHourBox, 35), bgcolor=color.new(i_colorFirstHourBox, 85))
    else if inFirstHour and not na(firstHourHigh)
        firstHourHigh := math.max(firstHourHigh, high)
        firstHourLow  := math.min(firstHourLow, low)
        if i_showFirstHourBox
            if na(firstHourBox)
                firstHourBox := box.new(left=bar_index, top=firstHourHigh, right=bar_index + 1, bottom=firstHourLow, xloc=xloc.bar_index, border_width=1, border_color=color.new(i_colorFirstHourBox, 35), bgcolor=color.new(i_colorFirstHourBox, 85))
            else
                box.set_top(firstHourBox, firstHourHigh)
                box.set_rightbottom(firstHourBox, right=bar_index + 1, bottom=firstHourLow)
                box.set_bgcolor(firstHourBox, color.new(i_colorFirstHourBox, 85))
                box.set_border_color(firstHourBox, color.new(i_colorFirstHourBox, 35))

if i_showFirstHourBox and canTrackFirstHour and not inFirstHour and not na(firstHourBox) and not na(firstHourHigh) and not na(firstHourLow)
    box.set_top(firstHourBox, firstHourHigh)
    box.set_rightbottom(firstHourBox, right=bar_index + 1, bottom=firstHourLow)
    box.set_bgcolor(firstHourBox, color.new(i_colorFirstHourBox, 85))
    box.set_border_color(firstHourBox, color.new(i_colorFirstHourBox, 35))

plot(i_showDaily5 and f_canDisplay("D") ? daily5 : na, "Daily 5 SMA", i_colorDaily5, 1, display=display.all - display.status_line)
plot(i_showDaily20 and f_canDisplay("D") ? daily20 : na, "Daily 20 SMA", i_colorDaily20, 1, display=display.all - display.status_line)
plot(i_showDaily50 and f_canDisplay("D") ? daily50 : na, "Daily 50 SMA", i_colorDaily50, 1, display=display.all - display.status_line)
plot(i_showDaily200 and f_canDisplay("D") ? daily200 : na, "Daily 200 SMA", i_colorDaily200, 1, display=display.all - display.status_line)

halfbackPlotStyle = i_halfbackPlotStyle == "Stepline" ? plot.style_stepline : plot.style_line
plot(i_showDailyHalfback and timeframe.isintraday and showDailyLevels and not na(dailyHalfback) ? dailyHalfback : na, "Daily Halfback", i_colorDailyHalfback, 1, style=halfbackPlotStyle, display=display.all - display.status_line)
plot(i_showPriorDay and showDailyLevels and not na(priorDayHigh) ? priorDayHigh : na, "Prior Day High", i_colorPriorHigh, 1, style=plot.style_stepline, display=display.all - display.status_line)
plot(i_showPriorDay and showDailyLevels and not na(priorDayLow) ? priorDayLow : na, "Prior Day Low", i_colorPriorLow, 1, style=plot.style_stepline, display=display.all - display.status_line)
plot(i_showPriorWeek and showDailyLevels and not na(priorWeekHigh) ? priorWeekHigh : na, "Prior Week High", i_colorPriorWeekH, 1, style=plot.style_stepline, display=display.all - display.status_line)
plot(i_showPriorWeek and showDailyLevels and not na(priorWeekLow) ? priorWeekLow : na, "Prior Week Low", i_colorPriorWeekL, 1, style=plot.style_stepline, display=display.all - display.status_line)
plot(i_showPriorWeekMid and i_showPriorWeek and showDailyLevels and not na(priorWeekMid) ? priorWeekMid : na, "Prior Week Mid", i_colorPriorWeekMid, 1, style=plot.style_stepline, display=display.all - display.status_line)

if i_showDailyHalfback and timeframe.isintraday and showDailyLevels and i_showHalfbackLabel and not na(dailyHalfback)
    if barstate.islast
        if na(halfbackLastLabel)
            halfbackLastLabel := label.new(bar_index, dailyHalfback, "Halfback", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=color.white, color=i_colorDailyHalfback, size=size.tiny)
        else
            label.set_xy(halfbackLastLabel, bar_index, dailyHalfback)
            label.set_text(halfbackLastLabel, "Halfback")
            label.set_textcolor(halfbackLastLabel, color.white)
            label.set_color(halfbackLastLabel, i_colorDailyHalfback)
            label.set_style(halfbackLastLabel, label.style_label_left)
            label.set_size(halfbackLastLabel, size.tiny)
else
    if not na(halfbackLastLabel)
        label.delete(halfbackLastLabel)
        halfbackLastLabel := na

// Last-bar labels for prior day/week levels (same pattern as halfback)
if i_showPriorLevelLabels and showDailyLevels
    if barstate.islast
        if i_showPriorDay and not na(priorDayHigh)
            if na(pdhLastLabel)
                pdhLastLabel := label.new(bar_index, priorDayHigh, "PDH", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=color.white, color=i_colorPriorHigh, size=size.tiny)
            else
                label.set_xy(pdhLastLabel, bar_index, priorDayHigh)
                label.set_text(pdhLastLabel, "PDH")
                label.set_color(pdhLastLabel, i_colorPriorHigh)
        else if not na(pdhLastLabel)
            label.delete(pdhLastLabel)
            pdhLastLabel := na
        if i_showPriorDay and not na(priorDayLow)
            if na(pdlLastLabel)
                pdlLastLabel := label.new(bar_index, priorDayLow, "PDL", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=color.white, color=i_colorPriorLow, size=size.tiny)
            else
                label.set_xy(pdlLastLabel, bar_index, priorDayLow)
                label.set_text(pdlLastLabel, "PDL")
                label.set_color(pdlLastLabel, i_colorPriorLow)
        else if not na(pdlLastLabel)
            label.delete(pdlLastLabel)
            pdlLastLabel := na
        if i_showPriorWeek and not na(priorWeekHigh)
            if na(pwhLastLabel)
                pwhLastLabel := label.new(bar_index, priorWeekHigh, "PWH", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=color.white, color=i_colorPriorWeekH, size=size.tiny)
            else
                label.set_xy(pwhLastLabel, bar_index, priorWeekHigh)
                label.set_text(pwhLastLabel, "PWH")
                label.set_color(pwhLastLabel, i_colorPriorWeekH)
        else if not na(pwhLastLabel)
            label.delete(pwhLastLabel)
            pwhLastLabel := na
        if i_showPriorWeek and not na(priorWeekLow)
            if na(pwlLastLabel)
                pwlLastLabel := label.new(bar_index, priorWeekLow, "PWL", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=color.white, color=i_colorPriorWeekL, size=size.tiny)
            else
                label.set_xy(pwlLastLabel, bar_index, priorWeekLow)
                label.set_text(pwlLastLabel, "PWL")
                label.set_color(pwlLastLabel, i_colorPriorWeekL)
        else if not na(pwlLastLabel)
            label.delete(pwlLastLabel)
            pwlLastLabel := na
        if i_showPriorWeekMid and i_showPriorWeek and not na(priorWeekMid)
            if na(pwmLastLabel)
                pwmLastLabel := label.new(bar_index, priorWeekMid, "PW Mid", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=color.white, color=i_colorPriorWeekMid, size=size.tiny)
            else
                label.set_xy(pwmLastLabel, bar_index, priorWeekMid)
                label.set_text(pwmLastLabel, "PW Mid")
                label.set_color(pwmLastLabel, i_colorPriorWeekMid)
        else if not na(pwmLastLabel)
            label.delete(pwmLastLabel)
            pwmLastLabel := na
else
    if not na(pdhLastLabel)
        label.delete(pdhLastLabel)
        pdhLastLabel := na
    if not na(pdlLastLabel)
        label.delete(pdlLastLabel)
        pdlLastLabel := na
    if not na(pwhLastLabel)
        label.delete(pwhLastLabel)
        pwhLastLabel := na
    if not na(pwlLastLabel)
        label.delete(pwlLastLabel)
        pwlLastLabel := na
    if not na(pwmLastLabel)
        label.delete(pwmLastLabel)
        pwmLastLabel := na

if i_showAtrLevels and showDailyLevels and not na(atrPlus1)
    if na(atrPlus1Line)
        atrPlus1Line := line.new(dayStartIndex, atrPlus1, bar_index + 1, atrPlus1, xloc=xloc.bar_index, extend=extend.right, color=i_colorAtrUp, style=line.style_dashed, width=2)
    else
        line.set_xy1(atrPlus1Line, dayStartIndex, atrPlus1)
        line.set_xy2(atrPlus1Line, bar_index + 1, atrPlus1)
        line.set_color(atrPlus1Line, i_colorAtrUp)
        line.set_style(atrPlus1Line, line.style_dashed)
        line.set_width(atrPlus1Line, 2)
        line.set_extend(atrPlus1Line, extend.right)
else if not na(atrPlus1Line)
    line.delete(atrPlus1Line)
    atrPlus1Line := na

if i_showAtrLevels and showDailyLevels and not na(atrMinus1)
    if na(atrMinus1Line)
        atrMinus1Line := line.new(dayStartIndex, atrMinus1, bar_index + 1, atrMinus1, xloc=xloc.bar_index, extend=extend.right, color=i_colorAtrDown, style=line.style_dashed, width=2)
    else
        line.set_xy1(atrMinus1Line, dayStartIndex, atrMinus1)
        line.set_xy2(atrMinus1Line, bar_index + 1, atrMinus1)
        line.set_color(atrMinus1Line, i_colorAtrDown)
        line.set_style(atrMinus1Line, line.style_dashed)
        line.set_width(atrMinus1Line, 2)
        line.set_extend(atrMinus1Line, extend.right)
else if not na(atrMinus1Line)
    line.delete(atrMinus1Line)
    atrMinus1Line := na

if barstate.islast
    // Top-right table: 3 cols x 2 rows
    if i_showAtrTable and not na(priorDayHigh) and not na(priorDayLow) and not na(atrValue)
        firstHourRange = not na(firstHourHigh) and not na(firstHourLow) ? firstHourHigh - firstHourLow : na
        // Row 0: ATR | +1 | -1
        table.cell(atrTable, 0, 0, "ATR = " + str.tostring(atrValue, "#.##"), bgcolor=color.new(color.gray, 50), text_color=color.white)
        table.cell(atrTable, 1, 0, "+1: " + str.tostring(atrPlus1, format.mintick), bgcolor=color.new(i_colorAtrUp, 15), text_color=color.black)
        table.cell(atrTable, 2, 0, "-1: " + str.tostring(atrMinus1, format.mintick), bgcolor=color.new(i_colorAtrDown, 15), text_color=color.black)
        // Row 1: 1HR Range | PDH/PDL | RVOL
        hrRangeStr = not na(firstHourRange) ? "1HR = " + str.tostring(firstHourRange, format.mintick) : "1HR = N/A"
        table.cell(atrTable, 0, 1, hrRangeStr, bgcolor=color.new(color.gray, 60), text_color=color.white)
        pdhPdlLabel = close > priorDayHigh ? "Above PDH" : close < priorDayLow ? "Below PDL" : "In Prior Day Range"
        pdhPdlColor = close > priorDayHigh ? color.new(color.green, 15) : close < priorDayLow ? color.new(color.red, 15) : color.new(#B8860B, 15)
        table.cell(atrTable, 1, 1, pdhPdlLabel, bgcolor=pdhPdlColor, text_color=color.black)
        rvolStr = not na(rvol) ? "RVOL: " + str.tostring(rvol, "#.##") + "x" : "RVOL: N/A"
        rvolBg  = not na(rvol) ? (rvol >= 2.0 ? color.new(#00E5FF, 15) : rvol >= 1.2 ? color.new(#388E3C, 15) : rvol >= 0.8 ? color.new(#F9A825, 30) : color.new(color.gray, 50)) : color.new(color.gray, 60)
        rvolTxt = not na(rvol) ? (rvol >= 2.0 ? color.black : rvol >= 1.2 ? color.white : color.black) : color.white
        table.cell(atrTable, 2, 1, rvolStr, bgcolor=rvolBg, text_color=rvolTxt)
    else
        for r = 0 to 1
            for c = 0 to 2
                table.cell(atrTable, c, r, "", bgcolor=color.new(color.black, 100), text_color=color.new(color.black, 100))

    // Bottom-right table: 2 cols x 5 rows (col 0 = VWAPs, col 1 = SMAs — independent)
    if i_showMaTable
        hasVwap = not na(vwap) and not na(vwap_2day) and not na(vwap_wtd) and not na(vwap_mtd)
        hasSma  = not na(daily5) and not na(daily20) and not na(daily50) and not na(daily200)
        // Header row
        table.cell(maTable, 0, 0, hasVwap ? "VWAP" : "", bgcolor=color.new(#222222, hasVwap ? 15 : 100), text_color=color.new(#888888, 0))
        table.cell(maTable, 1, 0, hasSma  ? "SMA"  : "", bgcolor=color.new(#222222, hasSma  ? 15 : 100), text_color=color.new(#888888, 0))
        // VWAP col
        if hasVwap
            table.cell(maTable, 0, 1, "1D  " + str.tostring(vwap,      format.mintick), bgcolor=color.new(close > vwap      ? color.green : color.red, 25), text_color=color.black)
            table.cell(maTable, 0, 2, "2D  " + str.tostring(vwap_2day, format.mintick), bgcolor=color.new(close > vwap_2day  ? color.green : color.red, 25), text_color=color.black)
            table.cell(maTable, 0, 3, "WTD " + str.tostring(vwap_wtd,  format.mintick), bgcolor=color.new(close > vwap_wtd   ? color.green : color.red, 25), text_color=color.black)
            table.cell(maTable, 0, 4, "MTD " + str.tostring(vwap_mtd,  format.mintick), bgcolor=color.new(close > vwap_mtd   ? color.green : color.red, 25), text_color=color.black)
        else
            for r = 1 to 4
                table.cell(maTable, 0, r, "", bgcolor=color.new(color.black, 100), text_color=color.new(color.black, 100))
        // SMA col
        if hasSma
            table.cell(maTable, 1, 1, "5D  " + str.tostring(daily5,   format.mintick), bgcolor=color.new(close > daily5   ? color.green : color.red, 25), text_color=color.black)
            table.cell(maTable, 1, 2, "20D " + str.tostring(daily20,  format.mintick), bgcolor=color.new(close > daily20  ? color.green : color.red, 25), text_color=color.black)
            table.cell(maTable, 1, 3, "50D " + str.tostring(daily50,  format.mintick), bgcolor=color.new(close > daily50  ? color.green : color.red, 25), text_color=color.black)
            table.cell(maTable, 1, 4, "200D" + str.tostring(daily200, format.mintick), bgcolor=color.new(close > daily200 ? color.green : color.red, 25), text_color=color.black)
        else
            for r = 1 to 4
                table.cell(maTable, 1, r, "", bgcolor=color.new(color.black, 100), text_color=color.new(color.black, 100))
    else
        for r = 0 to 4
            for c = 0 to 1
                table.cell(maTable, c, r, "", bgcolor=color.new(color.black, 100), text_color=color.new(color.black, 100))


// Key intraday time markers
keyTZ     = "America/New_York"
in1030 = timeframe.isintraday and not na(time(timeframe.period, "1030-1031:23456", keyTZ))
in1130 = timeframe.isintraday and not na(time(timeframe.period, "1130-1131:23456", keyTZ))
in1200 = timeframe.isintraday and not na(time(timeframe.period, "1200-1201:23456", keyTZ))
in1400 = timeframe.isintraday and not na(time(timeframe.period, "1400-1401:23456", keyTZ))
in1500 = timeframe.isintraday and not na(time(timeframe.period, "1500-1501:23456", keyTZ))
in1550 = timeframe.isintraday and not na(time(timeframe.period, "1550-1551:23456", keyTZ))

at1030 = i_showKeyTimes and in1030 and not in1030[1]
at1130 = i_showKeyTimes and in1130 and not in1130[1]
at1200 = i_showKeyTimes and in1200 and not in1200[1]
at1400 = i_showKeyTimes and in1400 and not in1400[1]
at1500 = i_showKeyTimes and in1500 and not in1500[1]
at1550 = i_showKeyTimes and in1550 and not in1550[1]

isKeyTime = at1030 or at1130 or at1200 or at1400 or at1500 or at1550
bgcolor(isKeyTime ? color.new(color.gray, 80) : na, title="Key Time Marker")

keyLabelColor = color.new(color.gray, 40)
keyLabelStyle = label.style_none
if at1030
    label.new(bar_index, high, "End 1H",     color=color.new(color.black, 100), textcolor=keyLabelColor, style=keyLabelStyle, size=size.tiny, yloc=yloc.abovebar)
if at1130
    label.new(bar_index, high, "Euro Close", color=color.new(color.black, 100), textcolor=keyLabelColor, style=keyLabelStyle, size=size.tiny, yloc=yloc.abovebar)
if at1200
    label.new(bar_index, high, "Lunch",      color=color.new(color.black, 100), textcolor=keyLabelColor, style=keyLabelStyle, size=size.tiny, yloc=yloc.abovebar)
if at1400
    label.new(bar_index, high, "Bond Close", color=color.new(color.black, 100), textcolor=keyLabelColor, style=keyLabelStyle, size=size.tiny, yloc=yloc.abovebar)
if at1500
    label.new(bar_index, high, "Last Hour",  color=color.new(color.black, 100), textcolor=keyLabelColor, style=keyLabelStyle, size=size.tiny, yloc=yloc.abovebar)
if at1550
    label.new(bar_index, high, "MOC",        color=color.new(color.black, 100), textcolor=keyLabelColor, style=keyLabelStyle, size=size.tiny, yloc=yloc.abovebar)

//#endregion

Overview

Chintan Cheatcode can also show ATR-based levels, prior-day levels, and tables for ATR, moving averages and relative volume. Each element has its own show toggle and colour. Higher-timeframe lines hide automatically when the chart timeframe is above their source timeframe.

Details

Published by

onlyspx on GitHub

Code credit

Chintan, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Moving averages, Support & resistance, Screeners & dashboards

Markets

Indices

Timeframes

M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Showbooltruei_showVwap
Colorcolorcolor.new(#FF69B4, 0)i_colorVwap
Show Lineboolfalsei_showVwap2d
Colorcolorcolor.new(#FF9800, 0)i_colorVwap2d
Show Lineboolfalsei_showVwapWtd
Colorcolorcolor.new(#66BB6A, 0)i_colorVwapWtd
Show Lineboolfalsei_showVwapMtd
Colorcolorcolor.new(#CE93D8, 0)i_colorVwapMtd
Showbooltruei_showHourly20
Colorcolorcolor.new(#FFFF00, 0)i_colorHourly20
Show Lineboolfalsei_showDaily5
Colorcolorcolor.new(#d9e7ff, 0)i_colorDaily5
Show all 40 settings
SettingTypeDefaultVariable
Show Lineboolfalsei_showDaily20
Colorcolorcolor.new(#a4c2f4, 0)i_colorDaily20
Show Lineboolfalsei_showDaily50
Colorcolorcolor.new(#6d9eeb, 0)i_colorDaily50
Show Lineboolfalsei_showDaily200
Colorcolorcolor.new(#1c4587, 0)i_colorDaily200
Show Linebooltruei_showDailyHalfback
Colorcolorcolor.new(#9E9D24, 0)i_colorDailyHalfback
Plot stylestringSteplinei_halfbackPlotStyle
Label on last barbooltruei_showHalfbackLabel
Show Linesboolfalsei_showAtrLevels
ATR Lengthint14i_atrLength
+1 ATR Colorcolorcolor.new(#00E5FF, 0)i_colorAtrUp
-1 ATR Colorcolorcolor.new(#FFD54F, 0)i_colorAtrDown
Show ATR Tablebooltruei_showAtrTable
Show MA Tablebooltruei_showMaTable
RVOL Lookback Daysint5i_rvolPeriod
Showbooltruei_showPriorDay
Prior Day High Colorcolorcolor.new(#66BB6A, 0)i_colorPriorHigh
Prior Day Low Colorcolorcolor.new(#EF5350, 0)i_colorPriorLow
Labels on last bar (PDH/PDL/PWH/PWL/PW mid)booltruei_showPriorLevelLabels
Showbooltruei_showPriorWeek
Prior Week High Colorcolorcolor.new(#66BB6A, 0)i_colorPriorWeekH
Prior Week Low Colorcolorcolor.new(#EF5350, 0)i_colorPriorWeekL
Show prior week midpointbooltruei_showPriorWeekMid
Prior Week Mid Colorcolorcolor.new(#78909C, 0)i_colorPriorWeekMid
Show Boxbooltruei_showOrbBox
Box Colorcolorcolor.new(#FF8F00, 0)i_colorOrbBox
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

20 stars

This indicator calculates a base moving average (EMA, SMA, WMA, or HMA) and projects multiple symmetrical envelope bands around it directly on the price chart. Users can adjust the length, source, moving average type, and initial envelope multiplier. Additiona

Indicator v5 Moving averagesVolatility & bands
Updated 1 year ago · None stated GitHub repository of Multiple Moving Average Envelope

Bottom Level Finder

by chris-c-thomas
14 stars

Bottom Level Finder is a support identification indicator designed to locate correction and re-entry zones directly on the price chart. It calculates horizon-adaptive Fibonacci retracements, drawdown percentage levels, moving averages, and integrated VIX volat

Indicator v6 Support & resistanceMoving averages
Updated 6 months ago · MIT GitHub repository of Bottom Level Finder

5 EMAs

by hirawatt
11 stars

5 EMAs calculates and plots five Exponential Moving Averages derived from five configurable timeframes directly onto the main price chart. It also plots the high and low lines fetched from an additional custom timeframe, accompanied by a small on-screen table

Indicator v4 Moving averagesTrend Repaints
Updated 2 years ago · MIT GitHub repository of 5 EMAs
9 stars

Calculates volume-weighted average price anchored to automatically detected swing pivots, period starts, or a custom manual timestamp. It plots volume-weighted standard deviation bands with configurable multiples and measures price distance from VWAP in standa

Indicator v6 Moving averagesVolatility & bands Repaints
Updated 2 days ago · MIT GitHub repository of Anchored VWAP [WavesUnchained]
7 stars

This indicator plots standard Bollinger Bands alongside scaled Average True Range (ATR) bands directly on the price chart. It is designed to assist traders in identifying price consolidation zones, potential breakout levels, dynamic stops, and take-profit targ

Indicator v5 Moving averagesVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Bollinger and ATR Bands

ATR Based Stoploss

by rubystar0512
5 stars

ATR Based Stoploss is an overlay indicator that calculates dynamic stop loss and take profit bands around a central simple moving average. It uses standard Average True Range or an ATR Surge Average derived from volatility spikes to offset profit and loss boun

Indicator v5 Volatility & bandsMoving averages
Updated 2 years ago · None stated GitHub repository of ATR Based Stoploss

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers