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 aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.