Indicator · Pine Script v5 · Own pane

CCI + Stoch + HA

by g-moe· code credited to goodgains

This indicator combines three momentum and trend analysis tools into a separate pane: a multi-timeframe Commodity Channel Index (CCI), a multi-timeframe Stochastic Oscillator, and a dual-EMA smoothed Heikin-Ashi trend bias displayed as colored dots.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code108
Settings12inputs
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

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

cci-stoch-ha.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("CCI + Stoch + HA", overlay = false)

// @keywords: commodity-channel-index, cci-overbought-level, cci-oversold-level, cci-crossover-signal, cci-crossunder-signal, bars-since-cross, stochastic-oscillator, stochastic-percent-k, stochastic-percent-d, stoch-k-d-lines, heikin-ashi, heikin-ashi-trend, ema-smoothed-heikin-ashi, dual-ema-heikin-ashi, multi-timeframe, mtf-oscillator, momentum-oscillator, trend-bias-indicator, oscillator-confluence, threshold-cross-timing

ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

// CCI
cci_timeframe = input.timeframe('', title = 'Timeframe to Use', group = 'CCI Settings')
cci_length = input.int(20, minval=1, title = 'CCI Length', group = 'CCI Settings')
cci_source = input.source(hlc3, title = 'CCI Source', group = 'CCI Settings')
cci_long = input.int(60, title = 'CCI Long Cross Above', group = 'CCI Settings')
cci_short = input.int(-60, title = 'CCI Short Cross Below', group = 'CCI Settings')
bars_for_cross = input.int(10, title = 'Max Bars For Cross', group = 'CCI Settings')

cci  = request.security(syminfo.tickerid, cci_timeframe, ta.cci(cci_source, cci_length)[1], lookahead = barmerge.lookahead_on)

plot(cci, "CCI", color=color.yellow)
plot(cci_long, 'CCI Long', color = color.new(color.white,70))
plot(cci_short, 'CCI Short', color = color.new(color.white,70))

cci_long_cross = bar_index - ta.valuewhen(ta.crossover(cci, cci_long), bar_index, 0)
cci_short_cross = bar_index - ta.valuewhen(ta.crossunder(cci, cci_short), bar_index, 0)

// Stoch
stoch_timeframe = input.timeframe('', title = 'Timeframe to Use', group = 'Stoch Settings')
periodK = input.int(14, title="%K Length", minval=1, group = 'Stoch Settings')
smoothK = input.int(1, title="%K Smoothing", minval=1, group = 'Stoch Settings')
periodD = input.int(3, title="%D Smoothing", minval=1, group = 'Stoch Settings')

k = request.security(syminfo.tickerid, stoch_timeframe, ta.sma(ta.stoch(close, high, low, periodK), smoothK), lookahead = barmerge.lookahead_on)
d = request.security(syminfo.tickerid, stoch_timeframe, ta.sma(k, periodD), lookahead = barmerge.lookahead_on)

plot(k, title="%K", color=#2962FF)
plot(d, title="%D", color=#FF6D00)


// CHART Heikin-ashi
len=input.int(10, title = "Length 1", group = 'Chart HA Settings')
o=ta.ema(open,len)
c=ta.ema(close,len)
h=ta.ema(high,len)
l=ta.ema(low,len)

var float haopen = 0.00
haclose = (o+h+l+c)/4
haopen := na(haopen[1]) ? (o + c)/2 : (haopen[1] + haclose[1]) / 2
hahigh = math.max(h, math.max(haopen,haclose))
halow = math.min(l, math.min(haopen,haclose))

len2=input(10,  title = "Length 2", group = 'Chart HA Settings')
o2=ta.ema(haopen, len2)
c2=ta.ema(haclose, len2)
h2=ta.ema(hahigh, len2)
l2=ta.ema(halow, len2)

col= o2>c2 ? color.red : color.green
chartha_bull = c2 >= o2
chartha_bear = c2 < o2

plot(0, title = 'HA Trend', color = col, style = plot.style_circles, linewidth = 2)
// CHART Heikin-ashi

// --STRATEGY INPUTS-- //
// strategy_start = input.time(timestamp("01 January 2020 00:00:00 UTC-5"), "Strategy Start Date", group = "StrategySettings", inline = '1')
// use_trading_hours = input.bool(false, title = "Use Trading Hours", tooltip = "This is ignored if the chart timeframe is greater than or equal to the daily timeframe.", group = "StrategySettings", inline = '2')
// trading_time = input.session("0930-1600", title = " ", tooltip = "This uses Eastern Time Zone or U.S. NY Market Hours.", group = "StrategySettings", inline = '2')
// trading_hours_cond = not use_trading_hours or time("",trading_time, "America/New_York")

// long_trades = input.bool(true, title = "Long Trades", tooltip = "Do we want to take long trades?" , group = "StrategySettings", inline = '3')
// short_trades = input.bool(true, title = "Short Trades", tooltip = "Do we want to take short trades?" , group = "StrategySettings", inline = '4')

// long_entry = long_trades and trading_hours_cond and chartha_bull and k > d and cci_long_cross <= bars_for_cross
// long_exit = long_trades and chartha_bull[1] and not chartha_bull

// short_entry = short_trades and trading_hours_cond and chartha_bear and k < d and cci_short_cross <= bars_for_cross
// short_exit = short_trades and chartha_bear[1] and not chartha_bear

// past_strategy_start_date = time >= strategy_start ? true : false
// // --STRATEGY INPUTS-- //


// // --ORDERS-- //
// if past_strategy_start_date
//     if long_exit
//         strategy.close("LE", comment = 'LX')

//     if short_exit
//         strategy.close("SS_E", comment = 'SS_X')

//     if long_entry
//         strategy.entry("LE", strategy.long)

//     if short_entry
//         strategy.entry("SS_E", strategy.short)


// // --ORDERS-- //

Overview

Users can adjust timeframes, lengths, and crossover levels for each indicator module. Due to using multi-timeframe security calls with lookahead enabled, historical bar values may cause lookahead bias and repainting.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend, Candlestick patterns

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
Timeframe to Usetimeframecci_timeframe
CCI Lengthint20cci_length
CCI Sourcesourcehlc3cci_source
CCI Long Cross Aboveint60cci_long
CCI Short Cross Belowint-60cci_short
Max Bars For Crossint10bars_for_cross
Timeframe to Usetimeframestoch_timeframe
%K Lengthint14periodK
%K Smoothingint1smoothK
%D Smoothingint3periodD
Length 1int10len
Length 2int10len2
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

Heikin Ashi Delta Smoothed

by lunarticktrading
7 stars

This indicator calculates the difference between Heikin-Ashi close and open values to quantify directional candle spread. It smooths this delta value using a simple moving average and plots the resulting oscillator as a line in a separate pane. Traders can cus

Indicator v6 Oscillators & momentumCandlestick patterns
Updated 2 weeks ago · None stated GitHub repository of Heikin Ashi Delta Smoothed

DEPV2 A6 MTF HA GUCU

by YuceSezar89
1 stars

This indicator calculates Heikin Ashi scores for multiple multiplier timeframes relative to a signal timeframe. It computes HA power for 2x, 3x, 4x, and 6x the base timeframe (default 15 minutes) using custom HA candle logic and normalizes the close-open range

Indicator v6 TrendCandlestick patterns
Updated 11 days ago · None stated GitHub repository of DEPV2 A6 MTF HA GUCU
55 stars

This indicator overlays on the price chart and provides trend and momentum analysis. It calculates and plots three exponential moving averages with fixed periods of 20, 50, and 200 using yellow, orange, and blue colors respectively. The script also computes th

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · Apache-2.0 GitHub repository of Trend & Momentum Analysis

Advanced Scalping EMA & RSI Strategy is an overlay indicator that combines fast and smooth moving averages with RSI levels and candlestick patterns to generate scalping signals. Users can select calculation methods for moving averages, such as SMA, EMA, WMA, o

Indicator v5 TrendOscillators & momentum
Updated 2 years ago · MIT GitHub repository of Advanced Scalping EMA & RSI Strategy
2 stars

Multi-Indicator Trading System plots 50-period and 200-period exponential moving averages alongside buy and sell signals directly on the price chart. Signals trigger when a short-timeframe EMA crossover aligns with higher timeframe trend filters from 1-hour or

Indicator v5 TrendMoving averages Repaints
Updated 1 year ago · MIT GitHub repository of Multi-Indicator Trading System

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