Indicator · Pine Script v4 · On the chart

[RS]MTF Candle Sticks

by ricardosantos79· code credited to RicardoSantos

This indicator overlays up to five higher-timeframe candlestick groups on the price chart.

View on GitHub

Repaints

GitHub stars261on the repository
Pine versionv4older, still runs
Lines of code133
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago13 Nov 2021

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

133 lines of Pine Script v4 from [RS]MTF Candlesticks.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

[RS]MTF Candlesticks.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=4
study(title="[RS]MTF Candle Sticks", overlay=true)

//  Required functions:
// —————————— PineCoders MTF Selection Framework functions
// ————— Converts current "timeframe.multiplier" plus the TF into minutes of type float.
f_resInMinutes() => 
    _resInMinutes = timeframe.multiplier * (
         timeframe.isseconds ? 1. / 60. :
         timeframe.isminutes ? 1.       :
         timeframe.isdaily   ? 1440.    :
         timeframe.isweekly  ? 10080.   :
         timeframe.ismonthly ? 43800.   : na)

// ————— Returns resolution of _resolution period in minutes.
f_tfResInMinutes(_resolution) =>
    // _resolution: resolution of any TF (in "timeframe.period" string format).
    security(syminfo.tickerid, _resolution, f_resInMinutes())

//  Returns a time formated text string of the elapsed time remaining until 
//      specified timeframe closes:
f_countdown_to_close_text(_tf)=>
    int _open_date = valuewhen(change(time(_tf)) != 0, time, 0)
    int _close_date = _open_date + round(f_tfResInMinutes(_tf)) * 60000
    int _time_difference = _close_date - timenow
    int _tina_minute = 60000, int _tina_hour = (60*_tina_minute), int _tina_day = (1440*_tina_minute), int _tina_week = (10080*_tina_minute), int _tina_month = (43800*_tina_minute)
    int _month = _time_difference / _tina_month
    int _weeks = (_time_difference % _tina_month) / _tina_week
    int _days = ((_time_difference % _tina_month) % _tina_week) / _tina_day
    int _hours = (((_time_difference % _tina_month) % _tina_week) % _tina_day) / _tina_hour
    int _minutes = ((((_time_difference % _tina_month) % _tina_week) % _tina_day) % _tina_hour) / _tina_minute
    string _countdown = (_month >= 1 ? tostring(_month, " #M ") : "") + (_weeks >= 1 ? tostring(_weeks, " #W ") : "") + (_days >= 1 ? tostring(_days, " #D ") : "") + (_hours >= 0 ? (_hours < 10 ? "0" : "") + tostring(_hours, "#") : "00") + (_minutes >= 0 ? (_minutes < 10 ? "0" : "") + tostring(_minutes, ":# ") : ":00")
    _countdown

//------------------------------------------------------------------------------
//  inputs:
int n_of_candlesticks = input(defval=5, minval=0, maxval=5)
int n_of_candlesticks_per_tf = input(defval=5, minval=0, maxval=5)
string tf1 = input(defval="60")
string tf2 = input(defval="240")
string tf3 = input(defval="D")
string tf4 = input(defval="W")
string tf5 = input(defval="M")

bool show_labels = input(false)
bool show_sr = input(false)

int spacing = input(4)
int tdispl = round(f_resInMinutes()) * 60000 * spacing

bool bm = barmerge.lookahead_on
bool gp = barmerge.gaps_off

f_security(_tf, _pos, _display)=>
    bool _bm = barmerge.lookahead_on
    bool _gp = barmerge.gaps_off
    float _open = not _display ? 0.0 : security(syminfo.tickerid, _tf, open[_pos], _gp, _bm)
    float _high = not _display ? 0.0 : security(syminfo.tickerid, _tf, high[_pos], _gp, _bm)
    float _low = not _display ? 0.0 : security(syminfo.tickerid, _tf, low[_pos], _gp, _bm)
    float _close = not _display ? 0.0 : security(syminfo.tickerid, _tf, close[_pos], _gp, _bm)
    [_open, _high, _low, _close]

[tf1_open, tf1_high, tf1_low, tf1_close] = f_security(tf1, 0, n_of_candlesticks >= 1)
[tf2_open, tf2_high, tf2_low, tf2_close] = f_security(tf2, 0, n_of_candlesticks >= 2)
[tf3_open, tf3_high, tf3_low, tf3_close] = f_security(tf3, 0, n_of_candlesticks >= 3)
[tf4_open, tf4_high, tf4_low, tf4_close] = f_security(tf4, 0, n_of_candlesticks >= 4)
[tf5_open, tf5_high, tf5_low, tf5_close] = f_security(tf5, 0, n_of_candlesticks >= 5)

labelpos = max(tf1_high, max(tf2_high, max(tf3_high, max(tf4_high, tf5_high))))

f_draw_candle(_o, _h, _l, _c, _x, _label, _label_pos)=>
    color _col_body_buy = color.new(color.green, 0)
    color _col_body_sel = color.new(color.maroon, 0)
    color _col_shadow_buy = color.new(color.green, 20)
    color _col_shadow_sel = color.new(color.maroon, 20)
    //-
    color _shadowcol = _c > _o ? _col_shadow_buy : _col_shadow_sel
    color _bodycol = _c > _o ? _col_body_buy : _col_body_sel
    var line _shadow = na
    var line _body = na
    line.delete(_shadow)
    line.delete(_body)
    _shadow := line.new(
             x1=_x, y1=_l,
             x2=_x, y2=_h,
             xloc= xloc.bar_time, extend=extend.none, color=_shadowcol, style=line.style_solid, width=2 
             )
    _body := line.new(
             x1=_x, y1=_o,
             x2=_x, y2=_c,
             xloc= xloc.bar_time, extend=extend.none, color=_bodycol, style=line.style_solid, width=8 
             )
    //
    string _countdown = f_countdown_to_close_text(_label)
    if show_labels
        var label _la = na
        label.delete(_la)
        _la := label.new(
                 x=_x, y=labelpos,
                 text=_label + "\n" + _countdown,
                 xloc=xloc.bar_time, yloc=yloc.price,
                 color=color.white, style=label.style_labeldown, textcolor=color.black, size=size.small
                 )
    //
    if show_sr
        var line _lh = na
        var line _ll = na
        line.delete(_lh)
        line.delete(_ll)
        _lh := line.new(
                 x1=time, y1=_h,
                 x2=_x, y2=_h,
                 xloc= xloc.bar_time, extend=extend.left, color=color.new(color.blue, 50), style=line.style_solid, width=1 
                 )
        _ll := line.new(
                 x1=time, y1=_l,
                 x2=_x, y2=_l,
                 xloc= xloc.bar_time, extend=extend.left, color=color.new(color.blue, 50), style=line.style_solid, width=1 
                 )

if n_of_candlesticks >= 1
    f_draw_candle(tf1_open, tf1_high, tf1_low, tf1_close, time + tdispl * 1, tf1, labelpos)
if n_of_candlesticks >= 2
    f_draw_candle(tf2_open, tf2_high, tf2_low, tf2_close, time + tdispl * 2, tf2, labelpos)
if n_of_candlesticks >= 3
    f_draw_candle(tf3_open, tf3_high, tf3_low, tf3_close, time + tdispl * 3, tf3, labelpos)
if n_of_candlesticks >= 4
    f_draw_candle(tf4_open, tf4_high, tf4_low, tf4_close, time + tdispl * 4, tf4, labelpos)
if n_of_candlesticks >= 5
    f_draw_candle(tf5_open, tf5_high, tf5_low, tf5_close, time + tdispl * 5, tf5, labelpos)

Overview

For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the five resolutions, label visibility, and a support-and-resistance toggle. A helper builds a countdown until a chosen timeframe closes. It does not generate trades. Because the requests use lookahead on the current higher-timeframe bar, those candles can change before that bar closes.

Details

Published by

ricardosantos79 on GitHub

Code credit

RicardoSantos, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Candlestick patterns, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
n_of_candlesticksint5n_of_candlesticks
n_of_candlesticks_per_tfint5n_of_candlesticks_per_tf
tf1string60tf1
tf2string240tf2
tf3stringDtf3
tf4stringWtf4
tf5stringMtf5
show_labelsboolfalseshow_labels
show_srboolfalseshow_sr
spacingint4spacing
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

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

Strat Assistant

by rickyzcarroll
90 stars

The Strat Assistant indicator identifies candlestick patterns from the STRAT methodology on the price chart. It detects inside bars, 2-candle directional bars, 3-candle outside bars, and sequences like 212 and 222 for continuations and reversals. Shapes such a

Indicator v4 Candlestick patternsSupport & resistance
Updated 5 years ago · None stated GitHub repository of Strat Assistant
56 stars

This overlay indicator highlights candles with a body smaller than 50% of their total range by coloring them white on the price chart. Simultaneously, it calculates and plots horizontal lines for open prices across multiple higher timeframes, such as daily, we

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 2 months ago · None stated GitHub repository of Daily Weekly Monthly Yearly Opens

This Pine Script indicator identifies liquidity sweeps and confirms signals using a close-back candle pattern directly on the price chart. It tracks recent swing highs and lows over a customizable lookback period. A bullish signal forms when a prior bar sweeps

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MPL-2.0 GitHub repository of Liquidity Sweep + Close-Back Confirmation

8020 System Indicator

by TamaraKGreen
46 stars

This overlay indicator draws 80/20 price levels and optional 40-point zone bands on the price chart. It marks repairs, cross sections, and forks with optional letter labels, and can highlight confluence when those marks sit near a level. Separate options shade

Indicator v6 Support & resistanceCandlestick patterns
Updated 7 weeks ago · None stated GitHub repository of 8020 System Indicator

Zen Gaps v5.0

by Zen-Tim
29 stars

This indicator draws colored boxes on the price chart to highlight gaps between bars. It detects bullish gaps when the current low exceeds the prior bar's high and bearish gaps when the current high falls below the prior bar's low. Strong gaps receive extra em

Indicator v5 Support & resistanceCandlestick patterns
Updated 2 weeks ago · MIT GitHub repository of Zen Gaps v5.0

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