Indicator · Pine Script v5 · On the chart

Multi-Time Period Charts

by TWODS-CAPITAL

This overlay indicator draws a box for each completed higher-timeframe period on the price chart.

View on GitHub

GitHub stars37on the repository
Pine versionv5runs as is
Lines of code97
Settings5inputs
LicenceMIT
Last update3 years ago10 Feb 2023

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

97 lines of Pine Script v5 from Technical-Indicators/Technical Indicators are Here🤩/Multi-Time-Period-Charts.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Multi-Time-Period-Charts.pine
//@version=5
indicator("Multi-Time Period Charts", overlay=true, max_boxes_count=500)

AUTO_TIMEFRAME_TOOLTIP = "When the Auto option is selected, the timeframe of the indicator is chosen automatically based on the chart timeframe. The Timeframe dropdown is ignored. The automated timeframes are: \n

 '1 day' for any chart timeframes below '1 day' \n

 '1 week' for any timeframes starting from '1 day' up to '1 week' \n

 '1 month' for any timeframes starting from '1 week' up to '1 month' \n

 '3 months' for any timeframes starting from '1 month' up to '3 months' \n

 '12 months' for any timeframes above '3 months'"

HLR = "High/Low Range"
TR = "True Range"
HAR = "Heikin Ashi Range"

DEFAULT_RESOLUTION = "1M"
DEFAULT_COLOR_GROWTH = color.rgb(0, 150, 136, 80)
DEFAULT_COLOR_FALL = color.rgb(244, 67, 54, 80)
DEFAULT_CALCULATION_METHOD = HLR
DEFAULT_AUTO_RESOLUTION = true

var prevBarIndex = bar_index

drawBox(left, right, top, bottom, diff, growthColorInput, fallColorInput, borderGrowth, borderFall) =>
    drawnBox = box.new(left, top, right, bottom)
    if diff < 0
        box.set_border_color(drawnBox, borderFall)
        box.set_bgcolor(drawnBox, fallColorInput)
    else
        box.set_border_color(drawnBox, borderGrowth)
        box.set_bgcolor(drawnBox, growthColorInput)
    drawnBox

selectAutoTimeframe() =>
     timeframe.isseconds ? '120':
     timeframe.isminutes ? '1440':
     timeframe.isdaily ? 'W':
     timeframe.isweekly ? 'M':
     timeframe.ismonthly and timeframe.multiplier < 3 ? '3M': '12M'

autoTimeframeInput = input(DEFAULT_AUTO_RESOLUTION, title="AutoTimeframe", tooltip=AUTO_TIMEFRAME_TOOLTIP)
timeframeInput = input.timeframe(DEFAULT_RESOLUTION, title="Timeframe")
timeframe = autoTimeframeInput ? selectAutoTimeframe() : timeframeInput

calculationMethodInput = input.string(DEFAULT_CALCULATION_METHOD, "Calculation", options = [HLR, TR, HAR])

growthColorInput = input(DEFAULT_COLOR_GROWTH, title="",inline="Body")
fallColorInput = input(DEFAULT_COLOR_FALL, title="Body", inline="Body")

growthBorderColor = color.new(growthColorInput, 0)
fallBorderColor = color.new(fallColorInput, 0)

[previousHigh, previousLow, previousClose, previousOpen, prePreviousClose] = request.security(syminfo.tickerid, timeframe, [high[1], low[1], close[1], open[1], close[2]], lookahead=barmerge.lookahead_on)
[currentHigh, currentLow, currentClose, currentOpen, prevClose] = request.security(syminfo.tickerid, timeframe, [high, low, close, open, close[1]])

isNewPeriod = ta.change(time(timeframe))

drawCurrent = barstate.islast and not isNewPeriod
secHigh = drawCurrent ? currentHigh : previousHigh
secPrevClose = drawCurrent ? prevClose : prePreviousClose
secLow = drawCurrent ? currentLow : previousLow


diff = drawCurrent ? currentClose - currentOpen : previousClose - previousOpen
left = prevBarIndex
right = drawCurrent ? bar_index : bar_index[1]

[ashiHigh, ashiLow] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe, [high, low])
float top = na
float bottom = na

if calculationMethodInput == HLR
    top := secHigh
    bottom := secLow
else if calculationMethodInput == TR
    top := math.max(secHigh, secPrevClose)
    bottom := math.min(secLow, secPrevClose)
else if calculationMethodInput == HAR
    top := ashiHigh
    bottom := ashiLow

if isNewPeriod
    prevBarIndex := bar_index
    drawBox(left, right, top, bottom, diff, growthColorInput, fallColorInput, growthBorderColor, fallBorderColor)

var box prevBox = na

if barstate.islast
    if isNewPeriod
        prevBox := na
    else
        box.delete(prevBox)
        prevBox := drawBox(left, right, top, bottom, diff, growthColorInput, fallColorInput, growthBorderColor, fallBorderColor)

Overview

Box height follows High/Low Range, True Range, or Heikin Ashi Range, and the fill is growth or fall color according to that period’s open-to-close change. Auto timeframe maps the chart timeframe to a higher one, or the user picks a timeframe manually. Colors and the calculation method are the main settings. The excerpt ends before the live-bar box is finished, and it does not generate trade signals.

Details

Published by

TWODS-CAPITAL on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Volatility & bands

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
AutoTimeframeinputDEFAULT_AUTO_RESOLUTIONautoTimeframeInput
TimeframetimeframeDEFAULT_RESOLUTIONtimeframeInput
CalculationstringDEFAULT_CALCULATION_METHODcalculationMethodInput
growthColorInputinputDEFAULT_COLOR_GROWTHgrowthColorInput
BodyinputDEFAULT_COLOR_FALLfallColorInput
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

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

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