Strategy · Pine Script v5 · On the chart

CCI & EMA strategy by Tradeswithashish

by hasnocool

This strategy generates trend-following entries using double-smoothed exponential moving averages, two Commodity Channel Index (CCI) periods, VWAP, and volume filters.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code73
Settings3inputs
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

73 lines of Pine Script v5 from CCI & EMA strategy by Tradeswithashish.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

CCI & EMA strategy by Tradeswithashish.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//This strategy is excellent in timeperiod above 15min. So use it carefully
//@version=5
//This strategy can be used for daily entry for positional trading
strategy('CCI & EMA strategy by Tradeswithashish', shorttitle='CC-EMA by tradeswithashish', overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=1000000)
emalen = input.int(title='Smooth EMA length', defval=100, minval=50, maxval=200, step=10)
Return = input.float(title='Return (%)', defval=5, minval=5, maxval=100, step=5)
Risk = input.float(title='Risk (%)', defval=3, minval=1, maxval=10, step=1)
ema = ta.ema(close, emalen)
emasmooth = ta.ema(ema, emalen)
ema2 = ta.ema(close, 50)
emasmooth2 = ta.ema(ema2, 50)
volMA = ta.sma(volume, 20)
volcheck = volume > volMA
//fidning CCI-100 and CCI-20 values value
ma1 = ta.sma(hlc3, 100)
cci100 = (hlc3 - ma1) / (0.015 * ta.dev(hlc3, 100))
ma2 = ta.sma(hlc3, 20)
cci20 = (hlc3 - ma2) / (0.015 * ta.dev(hlc3, 20))
//conditions for short and long entries
BuyCond = close > emasmooth and close > open and volcheck and cci100 > 0 and cci20 > 100 and close > ta.vwap and barstate.isconfirmed and (close - low) / (high - low) > 0.6 and volume > volume[1]
SellCond = close < emasmooth and close < open and volcheck and cci100 < 0 and cci20 < -100 and close < ta.vwap and barstate.isconfirmed and (close - low) / (high - low) < 0.4 and volume > volume[1]
//Buy and Sell Signals
Buysignal = BuyCond and strategy.position_size == 0 and barstate.isconfirmed
Sellsignal = SellCond and strategy.position_size == 0 and barstate.isconfirmed
//settingup stoploss
sllong = math.max(ema2, emasmooth)
slshort = math.min(ema2, emasmooth)
//Setting up Targets
longtarget = ohlc4 * (1 + Return / 100)
shorttarget = ohlc4 * (1 - Return / 100)
//Save SLs and Target prices
var StopPrice = 0.0
var TargetPrice = 0.0
var EntryPrice = 0.0
//Detect Valid long setup and trigger alerts
if Buysignal
    StopPrice := sllong
    EntryPrice := ohlc4
    TargetPrice := longtarget
    TargetPrice
if Sellsignal
    StopPrice := slshort
    TargetPrice := shorttarget
    EntryPrice := ohlc4
    EntryPrice
//Trailing Stoplosses
if strategy.position_size > 0
    StopPrice := math.max(StopPrice, ema2, emasmooth)
    StopPrice
if strategy.position_size < 0
    StopPrice := math.min(StopPrice, ema2, emasmooth)
    StopPrice
//enter trades whenever there is signal
strategy.entry(id='BUY', direction=strategy.long, when=Buysignal, alert_message='Buy signal given')
strategy.entry(id='SELL', direction=strategy.short, when=Sellsignal, alert_message='Sell signal given')
//Exit entries
if cci100 < 0 or close < emasmooth or close < ema2
    strategy.exit(id='Exit', from_entry='BUY', limit=TargetPrice, stop=StopPrice, when=strategy.position_size > 0, alert_message='Long entry closed')
if cci100 > 0 or close > emasmooth or close > ema2
    strategy.exit(id='Exit', from_entry='SELL', limit=TargetPrice, stop=StopPrice, when=strategy.position_size < 0, alert_message='Short entry closed')
//Draw trade data
stoplong = plot(strategy.position_size > 0 or Buysignal or Sellsignal ? StopPrice : na, title='Trailing stoploss long', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=1)
stopshort = plot(strategy.position_size < 0 or Sellsignal ? StopPrice : na, title='Trailing stoploss short', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=1)
candlenearest = plot(strategy.position_size < 0 ? high : strategy.position_size > 0 ? low : na, title='Candle nearest point', color=color.new(color.green, 80), style=plot.style_linebr, linewidth=1)
fill(stoplong, candlenearest, color=color.new(color.green, 80))
fill(stopshort, candlenearest, color=color.new(color.red, 80))
//Draw Price action arrow
plotshape(Buysignal ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), title='Bullish setup', size=size.small)
plotshape(Sellsignal ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), title='Bearish setup', size=size.small)
//Plot emasmooth and vwap
plot(ta.vwap, title='VWAP', color=color.new(color.black, 0), linewidth=2, show_last=75)
Expand (93 lines)

Overview

Long entries require price to trade above smoothed EMAs and VWAP alongside high volume and bullish candle closes, while short entries require the inverse. Positions exit using a percentage take-profit limit, EMA-based trailing stops, or opposing CCI and moving average crosses. Stop loss lines are plotted directly on the main chart.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages, Volume

Markets

Any symbol

Timeframes

M15-H1, H4 and above

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

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Smooth EMA lengthint100emalen
Return (%)float5Return
Risk (%)float3Risk
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

12 stars

This strategy enters long when a fast EMA crosses above a slow EMA and RSI, ADX, and volume all clear their thresholds. It sizes the order from a percentage of equity and an ATR stop distance, then sets a partial profit target at a multiple of that risk. After

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of BTC 4H Institutional Trend

Combined Strategy

by Dropio12
7 stars

This strategy plots buy and sell markers on the price chart by combining a fast and slow ALMA crossover with a simple close-to-close momentum check. A long marker appears when the fast ALMA crosses above the slow ALMA and momentum is positive. A short marker a

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Combined Strategy
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

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy enters long when a faster moving average crosses above a slower one and short when it crosses below, unless long-only mode is on. An optional volume filter requires volume above a 20-bar average times a multiplier. Exits use a percentage stop los

Strategy v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of MA Cross Strategy Template

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