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.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.