Strategy · Pine Script v5 · On the chart

CCI + EMA with RSI Cross Strategy

by hasnocool· code credited to rwestbrookjr

This intraday strategy enters positions based on an alignment of trend, momentum, and oscillator indicators.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code81
Settings11inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

81 lines of Pine Script v5 from CCI + EMA with RSI Cross Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

CCI + EMA with RSI Cross Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rwestbrookjr
//@version=5
strategy("CCI + EMA with RSI Cross Strategy", overlay=true, margin_long=100, margin_short=100, process_orders_on_close=true)
//EMA
fastLen = input(title='Fast EMA Length', defval=9, group='EMA Settings')
slowLen = input(title='Slow EMA Length', defval=20, group='EMA Settings')
fastEMA = ta.ema(close, fastLen)
slowEMA = ta.ema(close, slowLen)
fema = plot(fastEMA, title='FastEMA', color=color.new(color.green, 0), linewidth=1, style=plot.style_line)
sema = plot(slowEMA, title='SlowEMA', color=color.new(color.red, 0), linewidth=1, style=plot.style_line)
fill(fema, sema, color=fastEMA > slowEMA ? color.new(#417505, 50) : color.new(#890101, 50), title='Cloud')
// Bull and Bear Alerts
//Bull = ta.crossover(fastEMA, slowEMA)
Bull = fastEMA > slowEMA
//Bear = ta.crossunder(fastEMA, slowEMA)
Bear = fastEMA < slowEMA
//RSIs
rsiLength1Input = input.int(9, minval=1, title="Fast RSI Length", group="RSI Settings")
rsiSource1Input = input.source(close, "Fast RSI Source", group="RSI Settings")
rsiLength2Input = input.int(20, minval=1, title="Slow RSI Length", group="RSI Settings")
rsiSource2Input = input.source(close, "Slow RSI Source", group="RSI Settings")
up1 = ta.rma(math.max(ta.change(rsiSource1Input), 0), rsiLength1Input)
down1 = ta.rma(-math.min(ta.change(rsiSource1Input), 0), rsiLength1Input)
rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
up2 = ta.rma(math.max(ta.change(rsiSource2Input), 0), rsiLength2Input)
down2 = ta.rma(-math.min(ta.change(rsiSource2Input), 0), rsiLength2Input)
rsi2 = down2 == 0 ? 100 : up2 == 0 ? 0 : 100 - (100 / (1 + up2 / down2))
rsiBull = rsi > rsi2 and rsi > rsi[1]
rsiBear = rsi < rsi2 and rsi < rsi[1]
//CCI
cciLength = input.int(title='CCI Length', group='CCI Settings', defval=20, minval=1)
src = input(hlc3, title='CCI Source', group='CCI Settings')
ma = ta.sma(src, cciLength)
cci = (src - ma) / (0.015 * ta.dev(src, cciLength))
cciCut = input.int(title = 'CCI Cutoff', group='CCI Settings', defval = 50)
cciBull = cci > cciCut
cciBear = cci < cciCut * -1
//Trail Stop Setup
trstp = input.float(title="Trail Loss ($)", group='Stop Settings', minval = 0.0, step = 0.01, defval = 0.67)
longStop = 0.0, shortStop = 0.0
longStop := if Bull or strategy.position_size > 0
    stopValue = slowEMA - trstp
    math.max(stopValue, longStop[1])
else
    0.0
shortStop := if Bear or strategy.position_size < 0
    stopValue = slowEMA + trstp
    math.min(stopValue, shortStop[1])
else
    999999
    
plotshape(title='Short Stop', series=shortStop != 999999 and strategy.opentrades > 0 and strategy.position_size < 0 ? shortStop : na, style=shape.cross, color=color.yellow, location=location.absolute)
plotshape(title='Long Stop', series=longStop != 0.0 and strategy.opentrades > 0 and strategy.position_size > 0 ? longStop : na,style=shape.cross, color=color.yellow, location=location.absolute)
//Session Setup
open_session=input.session(title='Session',group='Session Settings', defval="0930-1545")
session = time("1", open_session)
validSession=(na(session) ? 0 : 1)
//Trade Signals
//longCondition = Bull and cci > cciCut and ta.crossover(rsi,rsi2) and validSession
longCondition = cciBull and ta.crossover(rsi,rsi2) and close > slowEMA and validSession
//longCondition = cciBull and ta.crossover(rsi,rsi2) and Bull and validSession
if (longCondition)
    strategy.entry("Long", strategy.long, 100)
    
//longExit = close > strategy.opentrades.entry_price(0) + 1.5 or close < strategy.opentrades.entry_price(0) - 0.75
longExit = close < longStop or not validSession
//longExit = ta.crossunder(low,longStop) or not validSession
if (longExit)
    strategy.close("Long")
//shortCondition = Bear and cci < (cciCut*-1) and ta.crossunder(rsi,rsi2) and validSession
shortCondition = cciBear and ta.crossunder(rsi,rsi2) and close < slowEMA and validSession
//shortCondition = cciBear and ta.crossunder(rsi,rsi2) and Bear and validSession
if (shortCondition)
    strategy.entry("Short", strategy.short, 100)
//shortExit = close < strategy.opentrades.entry_price(0) - 1.5 or close > strategy.opentrades.entry_price(0) + 0.75
shortExit = close > shortStop or not validSession
//shortExit = ta.crossover(high, shortStop) or not validSession
if (shortExit)
    strategy.close("Short")
Expand (98 lines)

Overview

CCI + EMA with RSI Cross Strategy triggers long entries when the Commodity Channel Index is above a positive threshold, a fast Relative Strength Index crosses above a slow RSI, price is above the slow Exponential Moving Average, and the current bar falls within a configured trading session. It plots the EMA ribbon and trailing stop levels directly on the price chart. Stop loss execution parameters are not fully configured by default.

Details

Published by

hasnocool on GitHub

Code credit

rwestbrookjr, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages, Sessions & time

Markets

Stocks, Indices

Timeframes

M1-M5, M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Fast EMA Lengthint9fastLen
Slow EMA Lengthint20slowLen
Fast RSI Lengthint9rsiLength1Input
Fast RSI SourcesourceclosersiSource1Input
Slow RSI Lengthint20rsiLength2Input
Slow RSI SourcesourceclosersiSource2Input
CCI Lengthint20cciLength
CCI Sourcesourcehlc3src
CCI Cutoffint50cciCut
Trail Loss ($)float0.67trstp
Sessionsession0930-1545open_session
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

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

Donald - Test Logic Futures is an overlay strategy designed for intraday futures trading. It combines kernel regression functions with exponential moving averages to evaluate price retracements and entry timing. Trades are filtered by session execution windows

Strategy v5 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald - Test Logic Futures
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers