A combination strategy that uses a EMA crossover to define trend direction and CCI as a filter on those signals. The idea: only act on crossovers that agree with momentum, to skip some of the false signals a crossover alone produces. Educational only — not predictive, and trading involves risk of loss.
Trend trigger — EMA crossover. A moving average (MA) takes the average price over a chosen number of bars and plots it as a single line that updates each bar. Two EMAs of different lengths (e.g. 9 and 21) are plotted; the fast one crossing above the slow one is read as upward momentum, and below as downward.
Filter — CCI. The Commodity Channel Index (CCI) is a momentum oscillator developed by Donald Lambert and introduced in 1980. Here it is used to require CCI to be positive for longs and negative for shorts.
Why combine them. A moving-average crossover defines direction but fires on every cross, including in choppy conditions; adding a CCI filter tries to skip crossovers that trigger into already-stretched momentum. Both components are lagging by construction, so this reduces some false signals at the cost of entering later — it does not remove risk or guarantee anything.
//@version=6
strategy("EMA Crossover + CCI Filter (Educational)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10, process_orders_on_close=true)
fastLen = input.int(9, "Fast EMA length", minval=1)
slowLen = input.int(21, "Slow EMA length", minval=1)
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
oscVal = ta.cci(close, 20)
longCond = ta.crossover(fast, slow) and oscVal > 0
shortCond = ta.crossunder(fast, slow) and oscVal < 0
if longCond
strategy.entry("Long", strategy.long)
if shortCond
strategy.entry("Short", strategy.short)
plot(fast, "Fast EMA", color.aqua)
plot(slow, "Slow EMA", color.orange)
// Educational only. Not financial advice. Validate for look-ahead bias &
// repainting before trusting any backtest. Past results do not predict future.It can reduce some false signals by skipping crossovers that fire into stretched momentum, but it also delays or removes some good entries, and it does not make the strategy predictive. Test it out-of-sample and account for costs. This is educational, not advice.
9/21 for the EMAs and standard CCI settings are common starting points, but there is no universally correct value — choose lengths that fit your timeframe and validate out-of-sample rather than tuning to past data.
Educational & software only — not financial advice, not a recommendation to trade. Backtests are illustrative; past performance does not predict future results. Trading involves substantial risk of loss.