OPEN-SOURCE SCRIPT

MACD Volume Strategy for XAUUSD (15m) [PineIndicators]

275
The MACD Volume Strategy is a momentum-based trading system designed for XAUUSD on the 15-minute timeframe. It integrates two key market indicators: the Moving Average Convergence Divergence (MACD) and a volume-based oscillator to identify strong trend shifts and confirm trade opportunities. This strategy uses dynamic position sizing, incorporates leverage customization, and applies structured entry and exit conditions to improve risk management.

⚙️ Core Strategy Components

1️⃣ Volume-Based Momentum Calculation
The strategy includes a custom volume oscillator to filter trade signals based on market activity. The oscillator is derived from the difference between short-term and long-term volume trends using Exponential Moving Averages (EMAs)

  • Short EMA (default = 5) represents recent volume activity.
  • Long EMA (default = 8) captures broader volume trends.
  • Positive values indicate rising volume, supporting momentum-based trades.
  • Negative values suggest weak market activity, reducing signal reliability.

By requiring positive oscillator values, the strategy ensures momentum confirmation before entering trades.

2️⃣ MACD Trend Confirmation
The strategy uses the MACD indicator as a trend filter. The MACD is calculated as:

  • Fast EMA (16-period) detects short-term price trends.
  • Slow EMA (26-period) smooths out price fluctuations to define the overall trend.
  • Signal Line (9-period EMA) helps identify crossovers, signaling potential trend shifts.
  • Histogram (MACD – Signal) visualizes trend strength.

The system generates trade signals based on MACD crossovers around the zero line, confirming bullish or bearish trend shifts.

📌 Trade Logic & Conditions

🔹 Long Entry Conditions
A buy signal is triggered when all the following conditions are met:
✅ MACD crosses above 0, signaling bullish momentum.
✅ Volume oscillator is positive, confirming increased trading activity.
✅ Current volume is at least 50% of the previous candle’s volume, ensuring market participation.

🔻 Short Entry Conditions
A sell signal is generated when:
✅ MACD crosses below 0, indicating bearish momentum.
✅ Volume oscillator is positive, ensuring market activity is sufficient.
✅ Current volume is less than 50% of the previous candle’s volume, showing decreasing participation.

This multi-factor approach filters out weak or false signals, ensuring that trades align with both momentum and volume dynamics.

📏 Position Sizing & Leverage

Dynamic Position Calculation:
Qty = strategy.equity × leverage / close price

  • Leverage: Customizable (default = 1x), allowing traders to adjust risk exposure.
  • Adaptive Sizing: The strategy scales position sizes based on account equity and market price.
  • Slippage & Commission: Built-in slippage (2 points) and commission (0.01%) settings provide realistic backtesting results.

This ensures efficient capital allocation, preventing overexposure in volatile conditions.

🎯 Trade Management & Exits
Take Profit & Stop Loss Mechanism
Each position includes predefined profit and loss targets:

  • Take Profit: +10% of risk amount.
  • Stop Loss: Fixed at 10,100 points.

The risk-reward ratio remains balanced, aiming for controlled drawdowns while maximizing trade potential.

Visual Trade Tracking
To improve trade analysis, the strategy includes:

📌 Trade Markers:
  • "Buy" label when a long position opens.
  • "Close" label when a position exits.


📌 Trade History Boxes:
  • Green for profitable trades.
  • Red for losing trades.


📌 Horizontal Trade Lines:
  • Shows entry and exit prices.
  • Helps identify trend movements over multiple trades.

This structured visualization allows traders to analyze past performance directly on the chart.

⚡ How to Use This Strategy

1️⃣ Apply the script to a XAUUSD (Gold) 15m chart in TradingView.
2️⃣ Adjust leverage settings as needed.
3️⃣ Enable backtesting to assess past performance.
4️⃣ Monitor volume and MACD conditions to understand trade triggers.
5️⃣ Use the visual trade markers to review historical performance.

The MACD Volume Strategy is designed for short-term trading, aiming to capture momentum-driven opportunities while filtering out weak signals using volume confirmation.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.