This strategy generates trend-following entries using double-smoothed exponential moving averages, two Commodity Channel Index (CCI) periods, VWAP, and volume filters.
// 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.
Double-smoothed exponential moving average trend filter
Dual-period CCI confirmation (20 and 100 periods)
Volume and candle close ratio validation
Dynamic EMA-based trailing stop loss and percentage target
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Smooth EMA length
int
100
emalen
Return (%)
float
5
Return
Risk (%)
float
3
Risk
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.
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
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
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
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
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
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