OPEN-SOURCE SCRIPT

Smart MACD Crossover

460
█ OVERVIEW
Smart MACD Crossover is an indicator designed for traders who trade based on MACD line crossovers. It significantly reduces the number of false crossover signals by adding a breakout-box confirmation mechanism. Price must close outside the box created at the moment of the MACD crossover for a signal to trigger. The script also includes optional scaled MACD lines on the price chart, candle coloring, multi-layer “fog” visualization, fully customizable entry signals, automatic Take Profit / Stop Loss levels and a real-time table.

█ CONCEPTS
Standard MACD crossovers frequently produce noise, especially in ranging markets. Smart MACD Crossover attempts to solve this issue: a horizontal box is drawn at the exact bar where the crossover occurs, and a trade signal is generated only when price actually breaks out of that box. By default, the show_only_matching filter is enabled — signals are shown only when the breakout direction matches the original MACD crossover direction (bullish box → long only, bearish box → short only).

█ FEATURES
Fully configurable classic MACD (default 12/26/9)

Optional MACD & Signal lines scaled and plotted directly on the price chart (show_macd_overlay)

Trend-based candle coloring

One-Side Histogram Fog:
- 6 layers above and 6 layers below hl2
- layer height based on average candle size × offset_mult (default 0.7)
- increasing transparency (base 80 + increment 4) for depth effect
- fully customizable colors

Breakout Boxes:
- created on every MACD crossover
- default height = high-low of the signal candle
- optional extension using average candle size × box_multiplier
- semi-transparent fill (85) with colored borders, extended right until breakout

Signals:
- Triangles or “BUY” / “SELL” labels
- show_only_matching filter (enabled by default) — only direction-consistent breakouts generate signals
- when disabled, every box breakout generates a signal according to breakout direction
- Built-in alerts: BUY and SELL

Take Profit / Stop Loss:
- TP1, TP2, TP3 and SL levels drawn automatically after each confirmed signal
- two modes: Candle Multiplier (based on average candle size) or Percentage
- all multipliers/percentages fully adjustable in “Risk Management Settings”
- real-time table in the top-right corner showing current TP/SL prices

█ HOW TO USE
Add via Pine Editor → paste code → Add to Chart.

Settings overview:
- MACD Settings: lengths and source
- Risk Management Settings: TP/SL mode, multipliers/percentages, average candle period
- MACD Overlay Lines: toggle scaled MACD lines on price chart
- Fog: enable/disable, adjust height and transparency
- Visual Settings: candle coloring
- Boxes: optional size multiplier (use_box_multiplier)
- Signals: choose Triangles or Labels, enable/disable direction filter

Signal meaning:
- Triangle below bar / “BUY” label → upward breakout from a box created after bullish MACD crossover
- Triangle above bar / “SELL” label → downward breakout from a box created after bearish MACD crossover
- Open boxes = pending breakout zones
- Fog below price = bullish pressure, fog above price = bearish pressure

█ APPLICATIONS
The indicator reduces false signals coming from plain MACD crossovers. For additional trend confirmation, the scaled MACD lines can be enabled.
Entry into a position is triggered by the BUY/SELL signal generated after the breakout. The TP1–TP3 and SL levels are drawn automatically only for convenience and as a quick reference – they are fully optional and traders can (and usually should) use their own preferred exit strategies, trailing stops, partial closes, or other money-management methods.

█ NOTES
- Due to MACD line scaling onto the price chart, classic MACD divergences cannot be identified

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน