OPEN-SOURCE SCRIPT

Commodity Channel Index CCI + EMA strategy

121
لقطة

================================================================================
COMMODITY CHANNEL INDEX CCI + EMA STRATEGY - STRATEGY GUIDE 📊
================================================================================

💡 COLLABORATION & SUPPORT
---------------------------

If you want to collaborate, have an idea for a strategy, or need help writing
or customizing code, send an email to burdytrader@gmail.com or send me a
message. Suggestions, ideas, and comments are always welcome! 🤝

I also develop automated trading codes for other trading platforms including:
- CTrader (C#)
- MetaTrader 4 (MQL4)
- MetaTrader 5 (MQL5)

If you need a strategy converted or developed for any of these platforms, feel
free to contact me!

================================================================================

⚠️ IMPORTANT: INSTRUMENT SELECTION 📈
-------------------------------------

This strategy performs BEST with currency pairs (forex). The CCI indicator
works particularly well in the forex market due to the nature of currency
movements and the effectiveness of the CCI in identifying overbought and
oversold conditions in trending markets.

Why Currency Pairs? 🎯
- CCI is highly effective in identifying reversals in forex markets
- Currency pairs show clear overbought/oversold patterns
- EMA filter (50/200) aligns well with major forex trends
- High liquidity ensures reliable signal execution

Performance Highlights:
In specific currency pairs, when properly configured, this strategy can achieve:
- Profit Factor: Over 2.0
- Win Rate: Up to 70%
- Particularly effective pairs: USDCAD, EURUSD, GBPJPY

While the strategy can work with other instruments (stocks, indices, commodities),
currency pairs provide the most consistent and reliable results. For optimal
performance, focus on major forex pairs with good liquidity and clear trending
characteristics.

================================================================================

WHAT DOES THIS STRATEGY DO? 🎯
---------------------------

This strategy combines the Commodity Channel Index (CCI) with Exponential
Moving Averages (EMA) to identify high-probability trading opportunities.
The strategy uses CCI crossovers with a smoothing moving average and filters
signals using EMA trend confirmation. The strategy automatically enters trades
when CCI crosses the smoothing MA in specific zones, indicating potential trend
reversals or continuations.

HOW IT WORKS? ⚙️
---------------

1. CCI CALCULATION 📈

The strategy calculates the Commodity Channel Index using:
- CCI = (Price - SMA(Price, length)) / (0.015 × Deviation(Price, length))
- Default length: 20 periods
- Source: HLC3 (typical price)

The CCI shows:
- Values above +100 = Overbought conditions
- Values below -100 = Oversold conditions
- Values around 0 = Neutral conditions

2. SMOOTHING MOVING AVERAGE 📊

A moving average is applied to the CCI to smooth out fluctuations:
- Types available: SMA, EMA, SMMA (RMA), WMA, VWMA
- Default: SMA with length 14
- Can be disabled (set to "None")

This smoothed line acts as a reference for crossover signals.

3. EMA TREND FILTER 🎯

Two EMAs are calculated on the CCI:
- EMA 50 (fast EMA)
- EMA 200 (slow EMA)

When the EMA filter is enabled:
- LONG signals only occur when EMA50 > EMA200 (uptrend confirmation)
- SHORT signals only occur when EMA50 < EMA200 (downtrend confirmation)

This filter can be enabled/disabled via the "Use EMA Filter" option.

4. ENTRY CONDITIONS 🎲

LONG ENTRY (Buy Signal):
- CCI crosses ABOVE the Smoothing MA (crossover)
- CCI is between Lower Level (-100) and Middle Level (0)
- EMA Filter: EMA50 > EMA200 (if filter enabled)
- No existing positions (or close opposite positions first)

SHORT ENTRY (Sell Signal):
- CCI crosses BELOW the Smoothing MA (crossunder)
- CCI is between Middle Level (0) and Upper Level (+100)
- EMA Filter: EMA50 < EMA200 (if filter enabled)
- No existing positions (or close opposite positions first)

5. POSITION MANAGEMENT 💰

The strategy uses a simple position management approach:
- Only ONE position at a time (no pyramiding)
- If a signal occurs in the opposite direction, closes existing position first
- Then opens new position in the new direction
- This prevents overexposure and simplifies risk management

6. TAKE PROFIT & STOP LOSS SETTINGS 🎯

The strategy uses percentage-based TP/SL:
- Take Profit: 1.0% (default, configurable)
- Stop Loss: 0.5% (default, configurable)
- Risk/Reward Ratio: 2:1 (TP is double the SL)

TP/SL are calculated once when the position opens and remain fixed.

AVAILABLE PARAMETERS ⚙️
-----------------------

CCI SETTINGS:
1. CCI Length (Default: 20)
- Period for CCI calculation
- Lower values = More sensitive to recent price action
- Higher values = More smoothed, less sensitive

2. CCI Source (Default: HLC3)
- Price source for CCI calculation
- Options: close, open, high, low, hlc3, hlcc4, ohlc4

3. CCI Lower Level (Default: -100)
- Lower boundary for LONG entry zone
- Typically -100 for oversold conditions

4. CCI Middle Level (Default: 0)
- Neutral level separating LONG and SHORT zones

5. CCI Upper Level (Default: +100)
- Upper boundary for SHORT entry zone
- Typically +100 for overbought conditions

SMOOTHING MA:
6. Type (Default: SMA)
- Moving average type: None, SMA, EMA, SMMA (RMA), WMA, VWMA
- Set to "None" to disable smoothing

7. Length (Default: 14)
- Period for smoothing MA
- Range: 7-28, step 7

EMA FILTER:
8. EMA 1 Length (Default: 50)
- Fast EMA period applied to CCI

9. EMA 2 Length (Default: 200)
- Slow EMA period applied to CCI

10. Use EMA Filter (Default: true)
- Enable/disable EMA trend filter
- When enabled: LONG only if EMA50 > EMA200, SHORT only if EMA50 < EMA200

RISK MANAGEMENT:
11. Take Profit (%) (Default: 1.0%)
- Profit target as percentage of entry price
- For LONG: Entry × (1 + TP%)
- For SHORT: Entry × (1 - TP%)

12. Stop Loss (%) (Default: 0.5%)
- Stop loss as percentage of entry price
- For LONG: Entry × (1 - SL%)
- For SHORT: Entry × (1 + SL%)

VISUALIZATION 📊
---------------

The strategy displays in a separate panel below the price chart:

1. CCI LINE
- Blue line showing the CCI value
- Oscillates around zero

2. SMOOTHING MA LINE
- Yellow line showing the smoothed CCI
- Reference line for crossover signals

3. CCI LEVEL LINES
- Red dashed line: Upper Level (+100)
- Green dashed line: Lower Level (-100)
- Yellow dashed line: Middle Level (0)

4. ENTRY SIGNALS
- Green cross: LONG entry signal (when CCI crosses above MA)
- Red cross: SHORT entry signal (when CCI crosses below MA)

RECOMMENDED SETTINGS 🎯
-----------------------

To get started, you can use these settings:

CCI SETTINGS:
- CCI Length: 20 (default)
- CCI Source: HLC3 (default)
- CCI Lower Level: -100 (default)
- CCI Middle Level: 0 (default)
- CCI Upper Level: +100 (default)

SMOOTHING MA:
- Type: SMA (default) or EMA for faster response
- Length: 14 (default)

EMA FILTER:
- EMA 1 Length: 50 (default)
- EMA 2 Length: 200 (default)
- Use EMA Filter: true (recommended for better signal quality)

RISK MANAGEMENT:
- Take Profit (%): 1.0% (adjust based on your risk/reward preference)
- Stop Loss (%): 0.5% (adjust based on your risk tolerance)

For more aggressive trading:
- Reduce CCI Length to 14-16
- Reduce Smoothing MA Length to 7
- Disable EMA Filter

For more conservative trading:
- Increase CCI Length to 24-30
- Increase Smoothing MA Length to 21-28
- Keep EMA Filter enabled

RECOMMENDED CURRENCY PAIRS 💱
------------------------------

This strategy is optimized for currency pairs and performs exceptionally well
on the following pairs when properly configured:

TOP PERFORMING PAIRS:
- USDCAD: Can achieve Profit Factor > 2.0 and Win Rate up to 70%
- EURUSD: Excellent performance with consistent signals
- GBPJPY: Strong results with proper EMA filter configuration

These pairs have shown the best historical performance due to:
- Clear trending characteristics
- Good response to CCI overbought/oversold levels
- Strong alignment with EMA 50/200 trend filter
- High liquidity ensuring reliable execution

When trading these pairs, use the default settings or slightly adjusted
parameters based on the pair's volatility. Always backtest on historical
data before using real money to find the optimal configuration for each
specific pair.

PRACTICAL EXAMPLE 📝
--------------------

Scenario: LONG Entry on EUR/USD

1. Market conditions:
- Price: 1.1000
- CCI: -80 (in oversold zone)
- Smoothing MA: -90
- CCI crosses above Smoothing MA (crossover occurs)
- EMA50: -50, EMA200: -70 (EMA50 > EMA200, uptrend confirmed)

2. Strategy checks conditions:
✓ Smoothing MA enabled: Yes
✓ Crossover: Yes (CCI crosses above MA)
✓ CCI in range: Yes (-100 <= -80 <= 0)
✓ EMA Filter: Yes (EMA50 > EMA200)
✓ No existing position: Yes

3. Strategy opens position:
- Direction: LONG (Buy)
- Entry: 1.1000 (current close)
- Take Profit: 1.1110 (1.0% above entry)
- Stop Loss: 1.0945 (0.5% below entry)
- Risk/Reward: 2:1

4. Outcome scenarios:
- If price rises to 1.1110 → Take Profit hit (profit)
- If price falls to 1.0945 → Stop Loss hit (loss limited)

IMPORTANT NOTE ⚠️
-----------------

This strategy is a technical analysis tool based on CCI and EMA indicators.
Like all trading strategies, it does NOT guarantee profits. Trading involves
significant risks and you can lose money, including your entire investment.
Past performance does not guarantee future results.

Always:
- Use appropriate risk management
- Never risk more than you can afford to lose
- Test the strategy on historical data (backtesting) before using real money
- Start with small position sizes or paper trading
- Understand that no strategy works 100% of the time
- Consider market conditions, news events, and other factors
- Keep a trading journal to learn and improve

The author and contributors are NOT responsible for any losses incurred from
using this strategy. Trading decisions are your own responsibility. Profits
are NOT guaranteed, and losses are possible.

LICENSE 📄
----------

This code is open source and available for modification. You are free to use,
modify, and distribute this strategy. If you republish or share a modified
version, please kindly mention the original author.

================================================================================

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.