Indicator · Pine Script v6 · Own pane

Kestrel Export - CCI

by casoon

Kestrel Export - CCI is a reference data generator designed to export Commodity Channel Index values and divergence metrics for parity testing against external systems.

View on GitHub

GitHub stars9on the repository
Pine versionv6current
Lines of code139
Settings11inputs
LicenceMIT
Last updateyesterday27 Oct 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

139 lines of Pine Script v6 from kestrel/cci_export.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

cci_export.pine
//@version=6
// ============================================================================
// Kestrel Export · CCI [Kestrel]
// ============================================================================
// Not an indicator to trade off — a bar-by-bar reference generator for
// Kestrel's CCI port (kestrel/crates/core/src/indicators/cci.rs), used two
// ways:
//
//   Track A — "..." menu → Export chart data → CSV. One column per Kestrel
//             output field, dropped into
//             kestrel/crates/core/tests/fixtures/tradingview/ as a real
//             parity fixture (replaces the brute-force reference test).
//   Track B — Pine Logs panel (bottom toolbar). One log.info() line per
//             confirmed bar close, for a quick live spot-check against
//             Kestrel's own `indicator_values` table while it's running.
//             Caveat: Kestrel's bars come from Capital.com's bid quote, not
//             this chart's feed (see kestrel/todo.md §9) — expect
//             ballpark/timing agreement here, not exact numeric parity.
//             Exact parity is Track A's job.
//
// Restricted to exactly what Kestrel ported — not the full
// pine-scripts/indicators/momentum/cci_advanced/cci_advanced.pine feature
// set: EMA-only smoothing (the other 7 pluggable modes aren't ported),
// hlc3 source only (no input.source), no scale mode (raw/"Classic" CCI
// only). The "9 · Trend Context" divergence engine (slow CCI + fast/slow
// slope divergence) *is* ported, unconditionally (no useCtx/showDiv
// toggle — Kestrel always computes it).
//
// Defaults below = config.toml's `[[instrument.indicator]] name = "cci"`
// block for NATURALGAS, with registry.rs fallbacks for the params
// config.toml leaves unset (require_extreme_zone, ctx_length, div_length,
// div_min — see crates/core/src/indicators/registry.rs). Same defaults
// apply to every other CCI-driven instrument in config.toml, so this
// script generalizes — just point the chart at a different symbol and
// update the epic label input.
//
// Kestrel's `Bar.ts` is the bar's CLOSE time, epoch ms, UTC (see
// crates/core/src/capital/model.rs) — matched here via Pine's `time_close`,
// not `time` (which is bar OPEN).
// ============================================================================

indicator("Kestrel Export - CCI", "KST-CCI", overlay = false)

// ─────────────────────────────────────────────────────────────────────────
// Inputs
// ─────────────────────────────────────────────────────────────────────────

g_id = "Instrument"
epicLabel = input.string("NATURALGAS", "Epic (log line only)", group = g_id)

g_cci = "Kestrel CCI Params (= config.toml)"
cciLen          = input.int(20, "CCI Length", group = g_cci)
avgLen          = input.int(3, "Average Length", group = g_cci)
sigLen          = input.int(3, "Signal Length", group = g_cci)
lookbackExtreme = input.int(5, "OB/OS Lookback (bars)", group = g_cci)
os1             = input.float(-100.0, "Oversold", group = g_cci)
ob1             = input.float(100.0, "Overbought", group = g_cci)
useExtremeOnly  = input.bool(true, "Extreme signals require OB/OS zone", group = g_cci)

g_ctx = "Trend Context (= registry.rs defaults)"
ctxLen = input.int(100, "Trend CCI Length", group = g_ctx)
divLen = input.int(4, "Divergence Slope Lookback", group = g_ctx)
divMin = input.float(25.0, "Min Fast Slope", group = g_ctx)

// ─────────────────────────────────────────────────────────────────────────
// CCI core — identical formulas to Cci::on_bar (cci.rs)
// ─────────────────────────────────────────────────────────────────────────

src = hlc3

cciRaw  = ta.cci(src, cciLen)
cciLine = ta.ema(cciRaw, avgLen)
signal  = ta.ema(cciLine, sigLen)

ctxRaw  = ta.cci(src, ctxLen)
ctxLine = ta.ema(ctxRaw, avgLen)

// ─────────────────────────────────────────────────────────────────────────
// Signals — identical logic to Cci::on_bar's alert block
// ─────────────────────────────────────────────────────────────────────────

lowestWin  = ta.lowest(cciLine, lookbackExtreme)
highestWin = ta.highest(cciLine, lookbackExtreme)
wasOversold   = lowestWin <= os1
wasOverbought = highestWin >= ob1

bullCross = ta.crossover(cciLine, signal)
bearCross = ta.crossunder(cciLine, signal)
bullExtreme = bullCross and (not useExtremeOnly or wasOversold)
bearExtreme = bearCross and (not useExtremeOnly or wasOverbought)
bullZeroCross = ta.crossover(cciLine, 0.0)
bearZeroCross = ta.crossunder(cciLine, 0.0)

extremeStrength = bullExtreme ? math.max(math.min((os1 - lowestWin) / math.abs(os1), 1.0), 0.0)
     : bearExtreme ? math.max(math.min((highestWin - ob1) / math.abs(ob1), 1.0), 0.0)
     : 0.0

fastDir = cciLine - cciLine[divLen]
slowDir = ctxLine - ctxLine[divLen]
bullDivergence = fastDir < -divMin and slowDir > 0.0
bearDivergence = fastDir > divMin and slowDir < 0.0
divergenceStrength = (bullDivergence or bearDivergence) ? math.max(math.min((math.abs(fastDir) - divMin) / divMin, 1.0), 0.0) : 0.0

// ─────────────────────────────────────────────────────────────────────────
// Track A — data-window plots, one per Kestrel output field.
// "..." → Export chart data pulls these into the CSV alongside OHLC + time.
// ─────────────────────────────────────────────────────────────────────────

plot(cciLine, "cci_line", display = display.data_window)
plot(signal, "signal", display = display.data_window)
plot(ctxLine, "ctx", display = display.data_window)
plot(bullExtreme ? 1 : 0, "bull_extreme", display = display.data_window)
plot(bearExtreme ? 1 : 0, "bear_extreme", display = display.data_window)
plot(bullZeroCross ? 1 : 0, "bull_zero_cross", display = display.data_window)
plot(bearZeroCross ? 1 : 0, "bear_zero_cross", display = display.data_window)
plot(bullDivergence ? 1 : 0, "bull_divergence", display = display.data_window)
plot(bearDivergence ? 1 : 0, "bear_divergence", display = display.data_window)
plot(extremeStrength, "extreme_strength", display = display.data_window)
plot(divergenceStrength, "divergence_strength", display = display.data_window)

// ─────────────────────────────────────────────────────────────────────────
// Track B — one Pine Logs line per confirmed bar close.
// ─────────────────────────────────────────────────────────────────────────

if barstate.isconfirmed
    line = "KESTREL cci epic=" + epicLabel + " tf=" + timeframe.period +
         " t_close=" + str.tostring(time_close) +
         " cci_line=" + str.tostring(cciLine, "#.######") +
         " signal=" + str.tostring(signal, "#.######") +
         " ctx=" + str.tostring(ctxLine, "#.######") +
         " bull_extreme=" + str.tostring(bullExtreme) +
         " bear_extreme=" + str.tostring(bearExtreme) +
         " bull_zero=" + str.tostring(bullZeroCross) +
         " bear_zero=" + str.tostring(bearZeroCross) +
         " bull_div=" + str.tostring(bullDivergence) +
         " bear_div=" + str.tostring(bearDivergence) +
         " extreme_strength=" + str.tostring(extremeStrength, "#.###") +
         " div_strength=" + str.tostring(divergenceStrength, "#.###")
    log.info(line)

Overview

Kestrel Export - CCI calculates standard CCI, EMA smoothing, signal lines, overbought or oversold extreme zones, and trend context divergence. Rendered in a separate pane, the indicator writes output values to chart data exports and Pine Logs on confirmed bar closes. User settings allow customization of CCI lengths, smoothing periods, extreme zones, and slope lookbacks.

Details

Published by

casoon on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum

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.

Topics

pine-scriptpinescripttechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Epic (log line only)stringNATURALGASepicLabel
CCI Lengthint20cciLen
Average Lengthint3avgLen
Signal Lengthint3sigLen
OB/OS Lookback (bars)int5lookbackExtreme
Oversoldfloat-100.0os1
Overboughtfloat100.0ob1
Extreme signals require OB/OS zonebooltrueuseExtremeOnly
Trend CCI Lengthint100ctxLen
Divergence Slope Lookbackint4divLen
Min Fast Slopefloat25.0divMin
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

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

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
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

KD指標

by TaichiS
219 stars

This script calculates and plots a Stochastic Oscillator (KD indicator) in a separate chart pane. It determines the fast stochastic value over a 9-period lookback, then applies a 3-period Simple Moving Average (SMA) to create the %K line, and a second 3-period

Indicator v4 Oscillators & momentum
Updated 5 years ago · None stated GitHub repository of KD指標

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