Indicator · Pine Script v4 · On the chart

Simple Supertrend CCI

by dearvn· code credited to LucaBono

This indicator modifies the classic Supertrend calculation by incorporating the Commodity Channel Index (CCI) to determine trend direction.

View on GitHub

GitHub stars4on the repository
Pine versionv4older, still runs
Lines of code94
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago25 Jul 2022

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

94 lines of Pine Script v4 from logic-buy-sell-rs-1h-2.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

logic-buy-sell-rs-1h-2.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LucaBono


//@version=4
study(title='Simple Supertrend CCI',  overlay=true, precision=6)


//////////////////////////
//* COLOR CONSTANTS *//
//////////////////////////

AQUA = #00FFFFFF
BLUE = #0000FFFF
RED  = #FF0000FF
LIME = #00FF00FF
GRAY = #808080FF
DARKRED   = #8B0000FF
DARKGREEN = #006400FF
GOLD = #FFD700
WHITE = color.white

// Plots
GREEN_LIGHT     = color.new(color.green, 40)
RED_LIGHT       = color.new(color.red, 40) 
BLUE_LIGHT      = color.new(color.aqua, 40)
PURPLE_LIGHT    = color.new(color.purple, 40) 

source = input(close)

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// CCI /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

cci_period = input(28, "CCI Period")
cci = cci(source, cci_period)
//UL = input(80, "Upper level")
//LL = input(20, "Lower Level")
ML = input(0, "CCI Mid Line pivot")

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////// SUPERTREND /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

Factor=input(3,title="[ST] Factor", minval=1,maxval = 100, type=input.float)
Pd=input(3, title="[ST] PD", minval=1,maxval = 100)

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/////////////////////// SUPERTREND DETECTION //////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

f_supertrend(Factor, Pd) =>

    Up=hl2-(Factor*atr(Pd))
    Dn=hl2+(Factor*atr(Pd))
    
    TrendUp = 0.0
    TrendUp := cci[1] > ML ? max(Up,TrendUp[1]) : Up
    TrendDown = 0.0
    TrendDown := cci[1]< ML ? min(Dn,TrendDown[1]) : Dn
    Trend = 0.0
    Trend := cci > ML ? 1: cci < ML ? -1: nz(Trend[1],1)
    Tsl = Trend==1? TrendUp: TrendDown

    Tsl

st_tsl = f_supertrend(Factor, Pd)

// Plot the ST
linecolor = close >= st_tsl ? color.green : color.red
plot(st_tsl, color = linecolor , linewidth = 4,title = "SuperTrend", transp=0)

buy= close >= st_tsl
sell= close < st_tsl
buy1= barssince(buy)
sell1 = barssince(sell)
color1 = buy1[1] > sell1[1] ? buy : na
alertcondition(color1, title='Buy Alert', message='Buy Signal')
plotshape(color1,title="Buy",text='BUY', color=color.green, style=shape.triangleup,location=location.bottom,size=size.tiny)
buy2= barssince(sell)
sell2 = barssince(buy)
color2 = buy2[1] > sell2[1] ? sell : na
alertcondition(color2, title='Sell Alert', message='Sell Signal')
plotshape(color2,title="Sell",text='SELL', color=color.red, style=shape.triangledown,location=location.top,size=size.tiny)
alertcondition(color1 or color2, title='Buy or Sell Alert', message='Buy or Sell Signal')
//hline(UL, title="Upper Line", linestyle=hline.style_solid, linewidth=1, color=color.red)
//hline(LL, title="Lower Line", linestyle=hline.style_solid, linewidth=1, color=color.lime)
//hline(ML, title="Mid Line", linestyle=hline.style_solid, linewidth=2, color=color.gray)

Overview

Simple Supertrend CCI calculates ATR bands around the median price and updates trailing stop levels based on whether CCI is above or below a chosen midline pivot. The resulting trailing stop line is plotted directly on the price chart in green or red. Buy and sell shapes appear on trend transitions, accompanied by alert conditions.

Details

Published by

dearvn on GitHub

Code credit

LucaBono, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price 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.

Topics

futurestrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
sourcesourceclosesource
CCI Periodint28cci_period
CCI Mid Line pivotint0ML
[ST] Factorfloat3Factor
[ST] PDint3Pd
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

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
257 stars

An overlay indicator that combines an ATR-based SuperTrend trailing stop with an integrated RSI-derived midline calculation on the price chart. The SuperTrend uses an ATR period and factor multiplier to plot dynamic green or red trend lines based on price dire

Indicator v5 TrendVolatility & bands
Updated 7 weeks ago · None stated GitHub repository of SuperTrend ATR + RSI
114 stars

ADX Strategy (original) is an overlay indicator that identifies trend-following trade signals using the Average Directional Index (ADX) combined with a Simple Moving Average filter. A long signal is generated when the ADX rises above a user-defined trend level

Indicator v4 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Strategy (original)

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Lunar Sniper
56 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision
55 stars

The VibeTrader Signal System is an overlay indicator that identifies trend direction and potential reversal conditions. It calculates a Supertrend line alongside Bollinger Bands and a 14-period RSI indicator. The script highlights bullish and bearish trends by

Indicator v6 TrendVolatility & bands
Updated 6 months ago · Apache-2.0 GitHub repository of VibeTrader Signal System

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