Indicator · Pine Script v5 · Own pane

MTF CCI & SAR

by g-moe· code credited to goodgains

This multi-timeframe indicator calculates the Commodity Channel Index and Parabolic SAR across four user-defined timeframes, defaulting to 1, 30, 60, and 240 minutes.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code82
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 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

82 lines of Pine Script v5 from Tradingview/mtf-cci-sar.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mtf-cci-sar.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("MTF CCI & SAR")

// @keywords: commodity-channel-index, parabolic-sar, multi-timeframe, four-timeframes, cci-entry, stepline-plots, long-entry, entry-background, cci-threshold, sar-filter, momentum-entry, oscillator-pane, mtf-confluence, cci-levels, entry-signal, exit-level, stepline-cci, sar-comparison, trend-entry, cci-sar

//INPUTS

//timeframes
tf1 = input.timeframe("1", title = 'Timeframe 1', group = 'Strategy Settings', inline = '1')
tf2 = input.timeframe("30", title = 'Timeframe 2', group = 'Strategy Settings', inline = '2')
tf3 = input.timeframe("60", title = 'Timeframe 3', group = 'Strategy Settings', inline = '3')
tf4 = input.timeframe("240", title = 'Timeframe 4', group = 'Strategy Settings', inline = '4')

//cci
cci_length = input.int(200, minval=1, title = 'CCI Length', group = 'Strategy Settings', inline = '5')
cci_src = input(hlc3, title="CCI Source", group = 'Strategy Settings', inline = '6')

cci_1 = request.security(syminfo.tickerid, tf1, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)
cci_2 = request.security(syminfo.tickerid, tf2, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)
cci_3 = request.security(syminfo.tickerid, tf3, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)
cci_4 = request.security(syminfo.tickerid, tf4, ta.cci(cci_src, cci_length)[1], lookahead = barmerge.lookahead_on)

// sar
sar_start = input(0.02, title = 'SAR Start', group = 'Strategy Settings', inline = '7')
sar_increment = input(0.02, title = 'SAR Increment', group = 'Strategy Settings', inline = '8')
sar_maximum = input(0.2, title = 'SAR Maximum', group = 'Strategy Settings', inline = '9')

sar_1 = request.security(syminfo.tickerid, tf1, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)
sar_2 = request.security(syminfo.tickerid, tf2, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)
sar_3 = request.security(syminfo.tickerid, tf3, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)
sar_4 = request.security(syminfo.tickerid, tf4, ta.sar(sar_start, sar_increment, sar_maximum)[1], lookahead = barmerge.lookahead_on)


//ENTRY
cci_entry_value = input.int(175,  title = 'CCI Entry Level', group = 'Strategy Settings', inline = '10')
cci_exit_value = input.int(-50, title = 'CCI Exit Level', group = 'Strategy Settings', inline = '11')

var long_cond = false
var long_entry = false
long_cond := (cci_1 > cci_entry_value) and (cci_2 > cci_entry_value) and (cci_3 > cci_entry_value) and (cci_4 > cci_entry_value) 
     and (close < sar_1) and (close < sar_2) and (close < sar_3) and (close < sar_4) ? true : false
long_entry := long_cond and not long_cond[1] ? true : false

var short_cond = false
var short_entry = false
short_cond := (cci_1 > cci_entry_value) and (cci_2 > cci_entry_value) and (cci_3 > cci_entry_value) and (cci_4 > cci_entry_value) 
     and (close < sar_1) and (close < sar_2) and (close < sar_3) and (close < sar_4) ? true : false
short_entry := short_cond and not short_cond[1] ? true : false

entry_color = input.color(color.new(color.yellow,0), title = 'Entry Color', group = 'Strategy Settings', inline = '12')
no_color = input.color(color.new(color.white,0), title = 'No Entry Color', group = 'Strategy Settings', inline = '12')


sar_color1 = close < sar_1 ? entry_color : no_color
sar_color2 = close < sar_2 ? entry_color : no_color
sar_color3 = close < sar_3 ? entry_color : no_color
sar_color4 = close < sar_4 ? entry_color : no_color

cci_color1 = cci_1 > cci_entry_value ? entry_color : no_color
cci_color2 = cci_2 > cci_entry_value ? entry_color : no_color
cci_color3 = cci_3 > cci_entry_value ? entry_color : no_color
cci_color4 = cci_4 > cci_entry_value ? entry_color : no_color

plot(cci_1, title = 'CCI 1', color = cci_color1, linewidth = 1, style = plot.style_stepline)
plot(cci_2, title = 'CCI 2', color = cci_color2, linewidth = 1, style = plot.style_stepline)
plot(cci_3, title = 'CCI 3', color = cci_color3, linewidth = 1, style = plot.style_stepline)
plot(cci_4, title = 'CCI 4', color = cci_color4, linewidth = 1, style = plot.style_stepline)

// plot(sar_1, color = sar_color1, linewidth = 1, style = plot.style_stepline)
// plot(sar_2, color = sar_color2, linewidth = 1, style = plot.style_stepline)
// plot(sar_3, color = sar_color3, linewidth = 1, style = plot.style_stepline)
// plot(sar_4, color = sar_color4, linewidth = 1, style = plot.style_stepline)

bgcolor(long_cond ? color.new(entry_color,80) : na)
// bgcolor(short_cond ? entry_color : no_color)

hline(cci_entry_value, title = 'CCI Entry', color = color.gray, linestyle = hline.style_dotted)
hline(cci_exit_value, title = 'CCI Exit', color = color.gray, linestyle = hline.style_dotted)

Overview

MTF CCI & SAR generates signals when CCI exceeds an entry threshold across all four periods while price sits below each respective Parabolic SAR level. Users can configure the timeframes, CCI length, source, SAR acceleration parameters, threshold levels, and visual colors. Displaying in a separate pane, the script currently defines identical criteria for both long and short conditions, while the configured exit level is not incorporated into active logic.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

Separate pane below the chart

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
Timeframe 1timeframe1tf1
Timeframe 2timeframe30tf2
Timeframe 3timeframe60tf3
Timeframe 4timeframe240tf4
CCI Lengthint200cci_length
CCI Sourcesourcehlc3cci_src
SAR Startfloat0.02sar_start
SAR Incrementfloat0.02sar_increment
SAR Maximumfloat0.2sar_maximum
CCI Entry Levelint175cci_entry_value
CCI Exit Levelint-50cci_exit_value
Entry Colorcolorcolor.new(color.yellow,0)entry_color
Show all 13 settings
SettingTypeDefaultVariable
No Entry Colorcolorcolor.new(color.white,0)no_color
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

Schaff Trend Cycle

by everget
947 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 12 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map
228 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

ADX Histogram

by harryguiacorn
220 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers