Indicator · Pine Script v5 · On the chart

Pivot Boss Multi Timeframe CPR with MACD and EMA

by pranjalchaubey

This overlay indicator plots Central Pivot Range levels and bands across yearly, quarterly, monthly, weekly, daily, and six-hour periods.

View on GitHub

GitHub stars5on the repository
Pine versionv5runs as is
Lines of code288
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago8 Dec 2022

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

288 lines of Pine Script v5 from Pine Script/Pivot Boss Multitimeframe CPR with Momentum.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Pivot Boss Multitimeframe CPR with Momentum.pine
//@version=5
// 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
indicator(title='[CP]Pivot Boss Multi Timeframe CPR Inception with MACD Momentum and EMA Trend', shorttitle='[CP]Pivot Boss CPR + MACD + EMA', overlay=true, max_labels_count=500)


// Rangebound MACD and EMA Markings 
//==============================================================================
tooltip = "Pine Script limits the max number of lables that can be shown on a chart to 500. Therefore, if you go far back enough, you won't see any markings for the MACD or EMA setups. If you are looking to test the efficacy of this indicator in the past, change the start and end dates to your desired timeframe."
// Set the date range
startDate   = input.int(title="Start Date",     defval=1,       minval=1,       maxval=31,      group="Rangebound MACD and EMA Markings")
startMonth  = input.int(title="Start Month",    defval=1,       minval=1,       maxval=12,      group="Rangebound MACD and EMA Markings")
startYear   = input.int(title="Start Year",     defval=2010,    minval=1970,    maxval=2100,    group="Rangebound MACD and EMA Markings")

endDate     = input.int(title="End Date",       defval=31,      minval=1,       maxval=31,      group="Rangebound MACD and EMA Markings")
endMonth    = input.int(title="End Month",      defval=12,      minval=1,       maxval=12,      group="Rangebound MACD and EMA Markings")
endYear     = input.int(title="End Year",       defval=2012,    minval=1970,    maxval=2100,    group="Rangebound MACD and EMA Markings")
// Look if the current_close time of the current bar falls inside the date range
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
date_range  = input.bool(false,  title="Mark MACD and EMA Setups in Range?", tooltip = tooltip,      group="Rangebound MACD and EMA Markings")


// User Inputs 
//==============================================================================
show_yearly_cpr             = input.bool(true,                          title='Yearly Pivot      ', inline='yearly',    group='Multi Timeframe Central Pivot Range')
yearly_pivot_color          = input.color(color.new(color.yellow, 0),   title='',                   inline='yearly',    group='Multi Timeframe Central Pivot Range')
show_yearly_cpr_band        = input.bool(true,                          title='CPR Band',           inline='yearly',    group='Multi Timeframe Central Pivot Range')
yearly_cpr_color            = input.color(color.new(color.blue, 50),    title='',                   inline='yearly',    group='Multi Timeframe Central Pivot Range')

show_quarterly_cpr          = input.bool(true,                          title='Quarterly Pivot ',   inline='quarterly', group='Multi Timeframe Central Pivot Range')
quarterly_pivot_color       = input.color(color.new(color.fuchsia, 0),  title='',                   inline='quarterly', group='Multi Timeframe Central Pivot Range')
show_quarterly_cpr_band     = input.bool(true,                          title='CPR Band',           inline='quarterly', group='Multi Timeframe Central Pivot Range')
quarterly_cpr_color         = input.color(color.new(color.olive, 50),   title='',                   inline='quarterly', group='Multi Timeframe Central Pivot Range')

show_monthly_cpr            = input.bool(true,                          title='Monthly Pivot   ',   inline='monthly',   group='Multi Timeframe Central Pivot Range')
monthly_pivot_color         = input.color(color.new(color.teal, 0),     title='',                   inline='monthly',   group='Multi Timeframe Central Pivot Range')
show_monthly_cpr_band       = input.bool(true,                          title='CPR Band',           inline='monthly',   group='Multi Timeframe Central Pivot Range')
monthly_cpr_color           = input.color(color.new(color.navy, 50),    title='',                   inline='monthly',   group='Multi Timeframe Central Pivot Range')

show_weekly_cpr             = input.bool(true,                          title='Weekly Pivot    ',   inline='weekly',    group='Multi Timeframe Central Pivot Range')
weekly_pivot_color          = input.color(color.new(color.orange, 0),   title='',                   inline='weekly',    group='Multi Timeframe Central Pivot Range')
show_weekly_cpr_band        = input.bool(true,                          title='CPR Band',           inline='weekly',    group='Multi Timeframe Central Pivot Range')
weekly_cpr_color            = input.color(color.new(color.purple, 50),  title='',                   inline='weekly',    group='Multi Timeframe Central Pivot Range')

show_daily_cpr              = input.bool(false,                         title='Daily Pivot       ', inline='daily',     group='Multi Timeframe Central Pivot Range')
daily_pivot_color           = input.color(color.new(color.red, 0),      title='',                   inline='daily',     group='Multi Timeframe Central Pivot Range')
show_daily_cpr_band         = input.bool(false,                         title='CPR Band',           inline='daily',     group='Multi Timeframe Central Pivot Range')
daily_cpr_color             = input.color(color.new(color.lime, 50),    title='',                   inline='daily',     group='Multi Timeframe Central Pivot Range')

show_hourly6_cpr            = input.bool(false,                         title='6 Hourly Pivot  ',   inline='hourly6',   group='Multi Timeframe Central Pivot Range')
hourly6_pivot_color         = input.color(color.new(color.green, 0),    title='',                   inline='hourly6',   group='Multi Timeframe Central Pivot Range')
show_hourly6_cpr_band       = input.bool(false,                         title='CPR Band',           inline='hourly6',   group='Multi Timeframe Central Pivot Range')
hourly6_cpr_color           = input.color(color.new(color.gray, 50),    title='',                   inline='hourly6',   group='Multi Timeframe Central Pivot Range')

show_hourly4_cpr            = input.bool(false,                         title='4 Hourly Pivot  ',   inline='hourly4',   group='Multi Timeframe Central Pivot Range')
hourly4_pivot_color         = input.color(color.new(color.green, 0),    title='',                   inline='hourly4',   group='Multi Timeframe Central Pivot Range')
show_hourly4_cpr_band       = input.bool(false,                         title='CPR Band',           inline='hourly4',   group='Multi Timeframe Central Pivot Range')
hourly4_cpr_color           = input.color(color.new(color.gray, 50),    title='',                   inline='hourly4',   group='Multi Timeframe Central Pivot Range')

show_hourly_cpr             = input.bool(false,                         title='Hourly Pivot    ',   inline='hourly',    group='Multi Timeframe Central Pivot Range')
hourly_pivot_color          = input.color(color.new(color.green, 0),    title='',                   inline='hourly',    group='Multi Timeframe Central Pivot Range')
show_hourly_cpr_band        = input.bool(false,                         title='CPR Band',           inline='hourly',    group='Multi Timeframe Central Pivot Range')
hourly_cpr_color            = input.color(color.new(color.gray, 50),    title='',                   inline='hourly',    group='Multi Timeframe Central Pivot Range')


show_labels                 = input.bool(true,                          title='Show CPR Lables',                        group='CPR Configuration')
show_next_day_pivot         = input.bool(false,                         title='Show Next Time Period Pivots',           group='CPR Configuration')


show_ema                    = input.bool(false,                         title="Show EMA on Chart",                      group="EMA Trend")
show_ema_crossovers         = input.bool(false,                         title="Mark EMA Crossovers on Chart",           group="EMA Trend")
ema_fast                    = input.int(12,                             title="Fast EMA Length  ",  inline="FEMA",      group="EMA Trend")
ema_fast_color              = input(color.orange,                       title="",                   inline="FEMA",      group="EMA Trend")
ema_slow                    = input.int(26,                             title="Slow EMA Length ",   inline="SEMA",      group="EMA Trend")
ema_slow_color              = input(color.green,                        title="",                   inline="SEMA",      group="EMA Trend")
ema_bullcross_color         = input(color.yellow,                       title="Bullish EMA Cross",                      group="EMA Trend")
ema_bearcross_color         = input(color.yellow,                       title="Bearish EMA Cross",                      group="EMA Trend")


show_macd_crossovers        = input.bool(true,                          title="Mark MACD Crossovers on Chart",          group="MACD Momentum")
show_macd_histogram         = input.bool(false,                         title="Show MACD Histogram on Chart",           group="MACD Momentum")
show_macd_momentum          = input.bool(true,                          title="Mark MACD Histogram Peaks on Chart",     group="MACD Momentum")
fast_length                 = input.int(12,                             title="Fast Length",                            group="MACD Momentum")
slow_length                 = input.int(26,                             title="Slow Length",                            group="MACD Momentum")
src                         = input.source(close,                       title="Source",                                 group="MACD Momentum")
signal_length               = input.int(9, minval=1, maxval=50,         title="Signal Smoothing",                       group="MACD Momentum")
sma_source                  = input.string("EMA", options=["SMA","EMA"],title="Oscillator MA Type",                     group="MACD Momentum")
sma_signal                  = input.string("EMA", options=["SMA","EMA"],title="Signal Line MA Type",                    group="MACD Momentum")
macd_bullcross_color        = input(color.white,                        title="Bullish MACD Cross",                     group="MACD Momentum")
macd_bearcross_color        = input(color.white,                        title="Bearish MACD Cross",                     group="MACD Momentum")
macd_grow_above_color       = input(#26A69A,                            title="Above   Grow",       inline="Above",     group="MACD Momentum")
macd_fall_above_color       = input(#B2DFDB,                            title="Fall",               inline="Above",     group="MACD Momentum")
macd_grow_below_color       = input(#FFCDD2,                            title="Below Grow",         inline="Below",     group="MACD Momentum")
macd_fall_below_color       = input(#FF5252,                            title="Fall",               inline="Below",     group="MACD Momentum")


// Calculations  
//==============================================================================
// Floor Pivots 
// Central Pivot 
pivot = (high + low + close) / 3.0
// 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
// EMA 
fast_ema_value = ta.ema(close, ema_fast)
slow_ema_value = ta.ema(close, ema_slow)
ema_bullcross = ta.crossover(fast_ema_value, slow_ema_value)
ema_bearcross = ta.crossover(slow_ema_value, fast_ema_value)
// MACD
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
macd_bullcross = ta.crossover(macd, signal)
macd_bearcross = ta.crossover(signal, macd)


// Multi Timeframe CPR 
//==============================================================================
yearly_pivot        = request.security(syminfo.tickerid, '12M', show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
yearly_tbc          = request.security(syminfo.tickerid, '12M', show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
yearly_ttc          = request.security(syminfo.tickerid, '12M', show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
yearly_tc           = yearly_ttc > yearly_tbc ? yearly_ttc : yearly_tbc
yearly_bc           = yearly_tbc < yearly_ttc ? yearly_tbc : yearly_ttc
quarterly_pivot     = request.security(syminfo.tickerid, '3M',  show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
quarterly_tbc       = request.security(syminfo.tickerid, '3M',  show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
quarterly_ttc       = request.security(syminfo.tickerid, '3M',  show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
quarterly_tc        = quarterly_ttc > quarterly_tbc ? quarterly_ttc : quarterly_tbc
quarterly_bc        = quarterly_tbc < quarterly_ttc ? quarterly_tbc : quarterly_ttc
monthly_pivot       = request.security(syminfo.tickerid, 'M',   show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
monthly_tbc         = request.security(syminfo.tickerid, 'M',   show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
monthly_ttc         = request.security(syminfo.tickerid, 'M',   show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
monthly_tc          = monthly_ttc > monthly_tbc ? monthly_ttc : monthly_tbc
monthly_bc          = monthly_tbc < monthly_ttc ? monthly_tbc : monthly_ttc
weekly_pivot        = request.security(syminfo.tickerid, 'W',   show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
weekly_tbc          = request.security(syminfo.tickerid, 'W',   show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
weekly_ttc          = request.security(syminfo.tickerid, 'W',   show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
weekly_tc           = weekly_ttc > weekly_tbc ? weekly_ttc : weekly_tbc
weekly_bc           = weekly_tbc < weekly_ttc ? weekly_tbc : weekly_ttc
daily_pivot         = request.security(syminfo.tickerid, 'D',   show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
daily_tbc           = request.security(syminfo.tickerid, 'D',   show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
daily_ttc           = request.security(syminfo.tickerid, 'D',   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
hourly6_pivot       = request.security(syminfo.tickerid, '360', show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
hourly6_tbc         = request.security(syminfo.tickerid, '360', show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
hourly6_ttc         = request.security(syminfo.tickerid, '360', show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
hourly6_tc          = hourly6_ttc > hourly6_tbc ? hourly6_ttc : hourly6_tbc
hourly6_bc          = hourly6_tbc < hourly6_ttc ? hourly6_tbc : hourly6_ttc
hourly4_pivot       = request.security(syminfo.tickerid, '240', show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
hourly4_tbc         = request.security(syminfo.tickerid, '240', show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
hourly4_ttc         = request.security(syminfo.tickerid, '240', show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
hourly4_tc          = hourly4_ttc > hourly4_tbc ? hourly4_ttc : hourly4_tbc
hourly4_bc          = hourly4_tbc < hourly4_ttc ? hourly4_tbc : hourly4_ttc
hourly_pivot        = request.security(syminfo.tickerid, '60',  show_next_day_pivot ? pivot     : pivot[1],     barmerge.gaps_off, barmerge.lookahead_on)
hourly_tbc          = request.security(syminfo.tickerid, '60',  show_next_day_pivot ? temp_bc   : temp_bc[1],   barmerge.gaps_off, barmerge.lookahead_on)
hourly_ttc          = request.security(syminfo.tickerid, '60',  show_next_day_pivot ? temp_tc   : temp_tc[1],   barmerge.gaps_off, barmerge.lookahead_on)
hourly_tc           = hourly_ttc > hourly_tbc ? hourly_ttc : hourly_tbc
hourly_bc           = hourly_tbc < hourly_ttc ? hourly_tbc : hourly_ttc


// Plots   
//==============================================================================
// Yearly CPR   
yearly_pivot_plot       = plot(show_yearly_cpr          ? yearly_pivot      : na, title='Yearly Pivot',     color=color.new(yearly_pivot_color, 0),     linewidth=1, style=plot.style_circles)
yearly_tcline           = plot(show_yearly_cpr_band     ? yearly_tc         : na, title='Yearly TC',        color=color.new(yearly_cpr_color, 0),       linewidth=0, style=plot.style_circles)
yearly_bcline           = plot(show_yearly_cpr_band     ? yearly_bc         : na, title='Yearly BC',        color=color.new(yearly_cpr_color, 0),       linewidth=0, style=plot.style_circles)
fill(yearly_tcline, yearly_bcline, color=color.new(yearly_cpr_color, show_yearly_cpr_band ? 95 : 100))
// Quarterly CPR   
quarterly_pivot_plot    = plot(show_quarterly_cpr       ? quarterly_pivot   : na, title='Quarterly Pivot',  color=color.new(quarterly_pivot_color, 0),  linewidth=1, style=plot.style_circles)
quarterly_tcline        = plot(show_quarterly_cpr_band  ? quarterly_tc      : na, title='Quarterly TC',     color=color.new(quarterly_cpr_color, 0),    linewidth=0, style=plot.style_circles)
quarterly_bcline        = plot(show_quarterly_cpr_band  ? quarterly_bc      : na, title='Quarterly BC',     color=color.new(quarterly_cpr_color, 0),    linewidth=0, style=plot.style_circles)
fill(quarterly_tcline, quarterly_bcline, color=color.new(quarterly_cpr_color, show_quarterly_cpr_band ? 95 : 100))
// Monthly CPR   
monthly_pivot_plot      = plot(show_monthly_cpr         ? monthly_pivot     : na, title='Monthly Pivot',    color=color.new(monthly_pivot_color, 0),    linewidth=1, style=plot.style_circles)
monthly_tcline          = plot(show_monthly_cpr_band    ? monthly_tc        : na, title='Monthly TC',       color=color.new(monthly_cpr_color, 0),      linewidth=0, style=plot.style_circles)
monthly_bcline          = plot(show_monthly_cpr_band    ? monthly_bc        : na, title='Monthly BC',       color=color.new(monthly_cpr_color, 0),      linewidth=0, style=plot.style_circles)
fill(monthly_tcline, monthly_bcline, color=color.new(monthly_cpr_color, show_monthly_cpr_band ? 95 : 100))
// Weekly CPR   
weekly_pivot_plot       = plot(show_weekly_cpr          ? weekly_pivot      : na, title='Weekly Pivot',     color=color.new(weekly_pivot_color, 0),     linewidth=1, style=plot.style_circles)
weekly_tcline           = plot(show_weekly_cpr_band     ? weekly_tc         : na, title='Weekly TC',        color=color.new(weekly_cpr_color, 0),       linewidth=0, style=plot.style_circles)
weekly_bcline           = plot(show_weekly_cpr_band     ? weekly_bc         : na, title='Weekly BC',        color=color.new(weekly_cpr_color, 0),       linewidth=0, style=plot.style_circles)
fill(weekly_tcline, weekly_bcline, color=color.new(weekly_cpr_color, show_weekly_cpr_band ? 95 : 100))
// Daily CPR   
daily_pivot_plot        = plot(show_daily_cpr           ? daily_pivot       : na, title='Daily Pivot',      color=color.new(daily_pivot_color, 0),      linewidth=1, style=plot.style_circles)
daily_tcline            = plot(show_daily_cpr_band      ? daily_tc          : na, title='Daily TC',         color=color.new(daily_cpr_color, 0),        linewidth=0, style=plot.style_circles)
daily_bcline            = plot(show_daily_cpr_band      ? daily_bc          : na, title='Daily BC',         color=color.new(daily_cpr_color, 0),        linewidth=0, style=plot.style_circles)
fill(daily_tcline, daily_bcline, color=color.new(daily_cpr_color, show_daily_cpr_band ? 95 : 100))
// 6 Hourly CPR   
hourly6_pivot_plot      = plot(show_hourly6_cpr         ? hourly6_pivot     : na, title='6H Pivot',         color=color.new(hourly6_pivot_color, 0),    linewidth=1, style=plot.style_circles)
hourly6_tcline          = plot(show_hourly6_cpr_band    ? hourly6_tc        : na, title='6H TC',            color=color.new(hourly6_cpr_color, 0),      linewidth=0, style=plot.style_circles)
hourly6_bcline          = plot(show_hourly6_cpr_band    ? hourly6_bc        : na, title='6H BC',            color=color.new(hourly6_cpr_color, 0),      linewidth=0, style=plot.style_circles)
fill(hourly6_tcline, hourly6_bcline, color=color.new(hourly6_cpr_color, show_hourly6_cpr_band ? 95 : 100))
// 4 Hourly CPR   
hourly4_pivot_plot      = plot(show_hourly4_cpr         ? hourly4_pivot     : na, title='4H Pivot',         color=color.new(hourly4_pivot_color, 0),    linewidth=1, style=plot.style_circles)
hourly4_tcline          = plot(show_hourly4_cpr_band    ? hourly4_tc        : na, title='4H TC',            color=color.new(hourly4_cpr_color, 0),      linewidth=0, style=plot.style_circles)
hourly4_bcline          = plot(show_hourly4_cpr_band    ? hourly4_bc        : na, title='4H BC',            color=color.new(hourly4_cpr_color, 0),      linewidth=0, style=plot.style_circles)
fill(hourly4_tcline, hourly4_bcline, color=color.new(hourly4_cpr_color, show_hourly4_cpr_band ? 95 : 100))
// Hourly CPR   
hourly_pivot_plot       = plot(show_hourly_cpr          ? hourly_pivot      : na, title='Hourly Pivot',     color=color.new(hourly_pivot_color, 0),     linewidth=1, style=plot.style_circles)
hourly_tcline           = plot(show_hourly_cpr_band     ? hourly_tc         : na, title='Hourly TC',        color=color.new(hourly_cpr_color, 0),       linewidth=0, style=plot.style_circles)
hourly_bcline           = plot(show_hourly_cpr_band     ? hourly_bc         : na, title='Hourly BC',        color=color.new(hourly_cpr_color, 0),       linewidth=0, style=plot.style_circles)
fill(hourly_tcline, hourly_bcline, color=color.new(hourly_cpr_color, show_hourly_cpr_band ? 95 : 100))


// CPR Labels  
if show_labels
    chper = time - time[1]
    chper := ta.change(chper) > 0 ? chper[1] : chper

    var label yearly_pivot_label        = na   
    var label quarterly_pivot_label     = na   
    var label monthly_pivot_label       = na   
    var label weekly_pivot_label        = na   
    var label daily_pivot_label         = na   
    var label hourly6_pivot_label       = na   
    var label hourly4_pivot_label       = na   
    var label hourly_pivot_label        = na   

    label.delete(yearly_pivot_label)
    label.delete(quarterly_pivot_label)
    label.delete(monthly_pivot_label)
    label.delete(weekly_pivot_label)
    label.delete(daily_pivot_label)
    label.delete(hourly6_pivot_label)
    label.delete(hourly4_pivot_label)
    label.delete(hourly_pivot_label)
    if show_yearly_cpr
        yearly_pivot_label      := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = yearly_pivot,     text = "Yearly Pivot",      color = yearly_pivot_color,     textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_quarterly_cpr
        quarterly_pivot_label   := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = quarterly_pivot,  text = "Quarterly Pivot",   color = quarterly_pivot_color,  textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_monthly_cpr
        monthly_pivot_label     := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = monthly_pivot,    text = "Monthly Pivot",     color = monthly_pivot_color,    textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_weekly_cpr
        weekly_pivot_label      := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = weekly_pivot,     text = "Weekly Pivot",      color = weekly_pivot_color,     textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_daily_cpr
        daily_pivot_label       := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = daily_pivot,      text = "Daily Pivot",       color = daily_pivot_color,      textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_hourly6_cpr
        hourly6_pivot_label     := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = hourly6_pivot,    text = "6 Hourly Pivot",    color = hourly6_pivot_color,    textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_hourly4_cpr
        hourly4_pivot_label     := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = hourly4_pivot,    text = "4 Hourly Pivot",    color = hourly4_pivot_color,    textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 
    if show_hourly_cpr
        hourly_pivot_label      := label.new(x = timeframe.isintraday ? time + chper * 5 :  time + chper, y = hourly_pivot,     text = "Hourly Pivot",      color = hourly_pivot_color,     textcolor=color.black, style=label.style_label_down, xloc = xloc.bar_time, yloc=yloc.price) 


// EMA
plot(show_ema ? fast_ema_value : na, title='Fast EMA', color=ema_fast_color, linewidth=1)
plot(show_ema ? slow_ema_value : na, title='Slow EMA', color=ema_slow_color, linewidth=1)


if not(date_range == true and inDateRange == false)  
    // EMA Crossovers 
    if show_ema_crossovers
        if ema_bullcross
            label.new(x=bar_index, y=low,  yloc=yloc.belowbar, color=ema_bullcross_color, style=label.style_diamond, size=size.tiny, tooltip="EMA Bullcross")
        if ema_bearcross
            label.new(x=bar_index, y=high, yloc=yloc.abovebar, color=ema_bearcross_color, style=label.style_diamond, size=size.tiny, tooltip="EMA Bearcross")


    // MACD Crossovers 
    if show_macd_crossovers
        if macd_bullcross
            label.new(x=bar_index, y=low,  yloc=yloc.belowbar, color=macd_bullcross_color, style=label.style_triangleup,   size=size.tiny, tooltip="MACD Bullcross")
        if macd_bearcross
            label.new(x=bar_index, y=high, yloc=yloc.abovebar, color=macd_bearcross_color, style=label.style_triangledown, size=size.tiny, tooltip="MACD Bearcross")
    // MACD Histogram 
    if show_macd_histogram
        label.new(x=bar_index, y=hist>=0 ? high : low, yloc=hist>=0 ? yloc.abovebar : yloc.belowbar, color=(hist>=0 ? (hist[1] < hist ? macd_grow_above_color : macd_fall_above_color) : (hist[1] < hist ? macd_grow_below_color : macd_fall_below_color)), style=label.style_circle, size=size.auto, tooltip="MACD Momentum")
    // MACD Momentum 
    if show_macd_momentum
        if ((hist >= 0) and (hist[2] < hist[1]) and (hist[1] > hist) )      // Peak Detection in MACD Histogram 
            label.new(x=bar_index, y=high, yloc=yloc.abovebar, color=macd_grow_above_color, style=label.style_triangledown, size=size.auto, tooltip="MACD Momentum")
        if ((hist < 0) and (hist[2] > hist[1]) and (hist[1] < hist) )      // Peak Detection in MACD Histogram 
            label.new(x=bar_index, y=low,  yloc=yloc.belowbar, color=macd_grow_below_color, style=label.style_triangleup,   size=size.auto, tooltip="MACD Momentum")


// Alerts   
//==============================================================================
alertcondition(ema_bullcross,   title="EMA Bullcross",  message="Time to go long!")
alertcondition(ema_bearcross,   title="EMA Bearcross",  message="Time to go short!")
alertcondition(macd_bullcross,  title="MACD Bullcross", message="Time to go long!")
alertcondition(macd_bearcross,  title="MACD Bearcross", message="Time to go short!")

Overview

Each timeframe can be shown or hidden, and pivot and band colors are set separately. It also marks MACD momentum and EMA trend setups on the price chart. An optional start and end date limits those markings because TradingView caps labels at 500. It does not place trades or define stops.

Details

Published by

pranjalchaubey on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Oscillators & momentum, Moving averages, Trend

Markets

Any symbol

Timeframes

Any timeframe

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
Start Dateint1startDate
Start Monthint1startMonth
Start Yearint2010startYear
End Dateint31endDate
End Monthint12endMonth
End Yearint2012endYear
Mark MACD and EMA Setups in Range?boolfalsedate_range
Yearly Pivot      booltrueshow_yearly_cpr
yearly_pivot_colorcolorcolor.new(color.yellow, 0)yearly_pivot_color
CPR Bandbooltrueshow_yearly_cpr_band
yearly_cpr_colorcolorcolor.new(color.blue, 50)yearly_cpr_color
Quarterly Pivot booltrueshow_quarterly_cpr
Show all 40 settings
SettingTypeDefaultVariable
quarterly_pivot_colorcolorcolor.new(color.fuchsia, 0)quarterly_pivot_color
CPR Bandbooltrueshow_quarterly_cpr_band
quarterly_cpr_colorcolorcolor.new(color.olive, 50)quarterly_cpr_color
Monthly Pivot   booltrueshow_monthly_cpr
monthly_pivot_colorcolorcolor.new(color.teal, 0)monthly_pivot_color
CPR Bandbooltrueshow_monthly_cpr_band
monthly_cpr_colorcolorcolor.new(color.navy, 50)monthly_cpr_color
Weekly Pivot    booltrueshow_weekly_cpr
weekly_pivot_colorcolorcolor.new(color.orange, 0)weekly_pivot_color
CPR Bandbooltrueshow_weekly_cpr_band
weekly_cpr_colorcolorcolor.new(color.purple, 50)weekly_cpr_color
Daily Pivot       boolfalseshow_daily_cpr
daily_pivot_colorcolorcolor.new(color.red, 0)daily_pivot_color
CPR Bandboolfalseshow_daily_cpr_band
daily_cpr_colorcolorcolor.new(color.lime, 50)daily_cpr_color
6 Hourly Pivot  boolfalseshow_hourly6_cpr
hourly6_pivot_colorcolorcolor.new(color.green, 0)hourly6_pivot_color
CPR Bandboolfalseshow_hourly6_cpr_band
hourly6_cpr_colorcolorcolor.new(color.gray, 50)hourly6_cpr_color
4 Hourly Pivot  boolfalseshow_hourly4_cpr
hourly4_pivot_colorcolorcolor.new(color.green, 0)hourly4_pivot_color
CPR Bandboolfalseshow_hourly4_cpr_band
hourly4_cpr_colorcolorcolor.new(color.gray, 50)hourly4_cpr_color
Hourly Pivot    boolfalseshow_hourly_cpr
hourly_pivot_colorcolorcolor.new(color.green, 0)hourly_pivot_color
CPR Bandboolfalseshow_hourly_cpr_band
hourly_cpr_colorcolorcolor.new(color.gray, 50)hourly_cpr_color
Show CPR Lablesbooltrueshow_labels
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

BTE Acc AO SMIO

by f-cksociety
11 stars

This script provides an indicator-based backtesting engine framework that simulates trade entries, exits, and filtering directly on the price chart. It evaluates selected entry rules and multi-layered filters, including moving average trends, volume increases,

Indicator v5 TrendOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of BTE Acc AO SMIO
5 stars

This indicator combines pivot-based support and resistance levels with multi-timeframe MACD crossovers and a higher-timeframe exponential moving average trend filter. It identifies support and resistance touches using pivot highs and lows within a user-defined

Indicator v4 Oscillators & momentumSupport & resistance Repaints
Updated 3 years ago · Apache-2.0 GitHub repository of MACD + Support / Resistance
948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average

PivotHighLow

by Alorse
330 stars

This indicator calculates pivot high and pivot low points on the price chart based on configurable left and right bar counts. Confirmed pivot highs and lows are plotted with negative bar offsets directly on the price chart using line and cross styles. Addition

Indicator v4 Support & resistanceOscillators & momentum Repaints
Updated 2 months ago · None stated GitHub repository of PivotHighLow

Ichimoku Cloud

by harryguiacorn
219 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud

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