OPEN-SOURCE SCRIPT
MACD Crossover Strategy [Long/Short]

MACD Crossover Strategy [Long/Short]
A clean, fully configurable MACD-based strategy built on Pine Script v6.
Supports two entry modes, independent Long/Short toggles, and four alert conditions — ready for both backtesting and live trading.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 ENTRY CONDITIONS (selectable)
━━━━━━━━━━━━━━━━━━━━━━━
- MACDxSignal — Enter when the MACD line crosses the Signal line.
Fast, reactive. Suitable for trending markets.
- HistCross0 — Enter when the Histogram crosses zero.
Slightly smoother signal. Helps reduce noise in choppy conditions.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 FEATURES
━━━━━━━━━━━━━━━━━━━━━━━
- Independent Long / Short toggles
→ Disable either direction to run a one-sided strategy.
→ When one side is off, the opposite signal still closes the open position.
- Lot Size input
→ Set a fixed quantity per entry.
- Commission & Slippage
→ Defaults: 0.1% commission, 2 ticks slippage.
→ Edit directly in the script, or override via Strategy Properties tab.
- Visual entry markers
→ Green ▲ for Long entries, Red ▼ for Short entries, plotted on the MACD pane.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 ALERT CONDITIONS (4 total)
━━━━━━━━━━━━━━━━━━━━━━━
- 🟢 Long Entry — Long signal triggered
- 🔴 Short Entry — Short signal triggered
- 📈 Hist Rising — Histogram switched from falling to rising
- 📉 Hist Falling — Histogram switched from rising to falling
━━━━━━━━━━━━━━━━━━━━━━━
🔹 SETTINGS
━━━━━━━━━━━━━━━━━━━━━━━
- Fast Length: 12 (default)
- Slow Length: 26 (default)
- Signal Length: 9 (default)
- Oscillator / Signal MA Type: EMA or SMA
━━━━━━━━━━━━━━━━━━━━━━━
⚠️ DISCLAIMER
━━━━━━━━━━━━━━━━━━━━━━━
This script is for educational and backtesting purposes only.
Past performance does not guarantee future results.
Always apply proper risk management before using any strategy in live markets.
A clean, fully configurable MACD-based strategy built on Pine Script v6.
Supports two entry modes, independent Long/Short toggles, and four alert conditions — ready for both backtesting and live trading.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 ENTRY CONDITIONS (selectable)
━━━━━━━━━━━━━━━━━━━━━━━
- MACDxSignal — Enter when the MACD line crosses the Signal line.
Fast, reactive. Suitable for trending markets.
- HistCross0 — Enter when the Histogram crosses zero.
Slightly smoother signal. Helps reduce noise in choppy conditions.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 FEATURES
━━━━━━━━━━━━━━━━━━━━━━━
- Independent Long / Short toggles
→ Disable either direction to run a one-sided strategy.
→ When one side is off, the opposite signal still closes the open position.
- Lot Size input
→ Set a fixed quantity per entry.
- Commission & Slippage
→ Defaults: 0.1% commission, 2 ticks slippage.
→ Edit directly in the script, or override via Strategy Properties tab.
- Visual entry markers
→ Green ▲ for Long entries, Red ▼ for Short entries, plotted on the MACD pane.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 ALERT CONDITIONS (4 total)
━━━━━━━━━━━━━━━━━━━━━━━
- 🟢 Long Entry — Long signal triggered
- 🔴 Short Entry — Short signal triggered
- 📈 Hist Rising — Histogram switched from falling to rising
- 📉 Hist Falling — Histogram switched from rising to falling
━━━━━━━━━━━━━━━━━━━━━━━
🔹 SETTINGS
━━━━━━━━━━━━━━━━━━━━━━━
- Fast Length: 12 (default)
- Slow Length: 26 (default)
- Signal Length: 9 (default)
- Oscillator / Signal MA Type: EMA or SMA
━━━━━━━━━━━━━━━━━━━━━━━
⚠️ DISCLAIMER
━━━━━━━━━━━━━━━━━━━━━━━
This script is for educational and backtesting purposes only.
Past performance does not guarantee future results.
Always apply proper risk management before using any strategy in live markets.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.