PulseHub
OPEN-SOURCE SCRIPT
Updated

Buy Sell Badge with ADX by Bybllo

2 949
OVERVIEW

This indicator generates Buy/Sell badges from a Fast/Slow EMA crossover (the "BSB" signal), then automatically manages an ATR-based stop loss and a risk:reward-based take profit for each signal, showing the resulting entry/stop/target levels directly on the chart along with a live status table. On top of the EMA-based signal, an optional ADX strength filter can be enabled: when turned on, a badge is only shown if ADX (Welles Wilder's Average Directional Index, a well-established public trend-strength measure) is either at/above an upper threshold or at/below a lower threshold at the time of the signal.

This ADX filter is fundamentally different in what it measures compared to a DMI-crossover style filter (as used in this author's companion script "Buy Sell Badge with DMI"): a DMI crossover filter asks "did the directional balance between buyers and sellers just flip?", while this ADX-threshold filter asks a completely separate question - "is the market currently trending strongly, or is it currently flat/range-bound?" - without caring about any recent direction change at all. A market can be in the middle of a strong, established uptrend (high ADX, no fresh DI crossover) or can just be exiting a range with an unclear trend (low ADX, but possibly a fresh DI crossover). Because these two filters answer genuinely different questions about market state, they are published and maintained as two separate, focused tools rather than merged into a single script with an ever-growing list of unrelated filter options - each remains simple enough to reason about and tune on its own. Position management (entry, stop loss, take profit, invalidation) always runs on the underlying EMA "BSB" signal regardless of the ADX filter; the ADX filter only controls whether a badge and the accompanying risk-management lines are displayed for that signal.

CALCULATION METHOD

The BSB signal itself comes from a Fast EMA and Slow EMA crossing (with an optional requirement that the current candle also closes beyond its open in the signal direction, for extra confirmation).
ADX is calculated using Wilder's classic Directional Movement System: True Range, +DM and -DM are computed from real market high/low/close values, smoothed using Wilder's running-smoothing method (SmoothedX = PreviousSmoothedX - PreviousSmoothedX/Length + CurrentValue), then DI+ and DI- are derived from the smoothed values, DX from the normalized difference between DI+ and DI-, and ADX as a moving average of DX - representing overall trend strength regardless of direction.
Stop loss is placed at ATR * multiplier beyond the signal bar's high/low; take profit is derived from the resulting risk multiplied by your chosen Risk:Reward ratio, with intermediate take-profit levels plotted when Risk:Reward is greater than 1.

KEY FEATURES

Fast/Slow EMA crossover generates the base Buy/Sell signal, with an optional candle-confirmation requirement (close beyond open in the signal direction).
Automatic ATR-based stop loss and configurable Risk:Reward take profit are calculated for every new signal, with intermediate take-profit levels plotted when Risk:Reward is greater than 1.
Optional "BSB + ADX" filter: a badge is only shown when ADX is at or above an upper threshold, OR at or below a lower threshold, at the time of the EMA signal. This lets you badge-filter for either strong-trend conditions (ADX high) or quiet/ranging conditions (ADX low), while suppressing badges in the ambiguous middle zone.
On-chart entry / stop-loss / take-profit lines and an SL distance (in points) label, both toggleable and only shown while a badge has actually been displayed for the active position.
Take-profit, stop-loss, and "invalidated" (opposite signal fired before target/stop was hit) markers are plotted separately so you can see exactly how each trade idea played out.
A live status table (top-right) shows the current position, entry, stop loss, take profit, and realized Risk:Reward.
Real-price calculation: prices and ATR are pulled via request.security() against the plain ticker, so signals stay consistent whether your chart is displaying candlesticks, Heikin Ashi, Renko, or any other non-standard chart type.
A full set of alertcondition() calls for Buy/Sell signals, take-profit hits, stop-loss hits, and invalidated entries.

HOW TO USE

Leave "BSB + ADX" unchecked to use the EMA crossover badges on their own, with no ADX-based filtering.
Check "BSB + ADX" and set the upper/lower thresholds to only badge signals that occur when ADX confirms your preferred market regime - for example, set a high upper threshold to badge only strongly trending breakouts, or a low lower threshold to badge only signals from quiet, low-ADX conditions.
Watch the on-chart entry/SL/TP lines and the status table to track an open idea's risk and progress in real time.
Set up alerts on the "Buy/Sell Signal", "Entry Signal", "Take Profit Hit", "Stop Loss Hit", or "Entry Invalidated" conditions depending on which events you want to be notified about.

NOTES

Unlike a DMI golden-cross / dead-cross confirmation filter (see "Buy Sell Badge with DMI by Bybllo"), this version filters purely on the ADX strength value itself (above an upper threshold or below a lower threshold), without checking DI+/DI- direction at all - the two are independent, differently-purposed filters kept as separate scripts rather than combined into one.
Stop-loss and alert-sensitivity offsets are point-based and will need adjusting per instrument (see the tooltips on those inputs).
This indicator does not place real orders; it is a visual / alerting tool for tracking a rules-based EMA (optionally ADX-filtered) trade idea.
Release Notes
Update: Improved documentation and cleaner publish chart

- Expanded the description with a full breakdown of the underlying
Wilder ADX/DMI calculation method (True Range, +DM/-DM, Wilder's
running smoothing, DI+/DI-, DX, ADX).
- Clarified how this indicator's ADX-threshold filter differs from a
DMI-crossover filter (trend strength vs. directional flip), and why
the two are kept as separate, focused tools rather than merged into
one script.
- Re-published the chart snapshot with EMA lines, entry/SL/TP lines,
and the SL distance label hidden, so the chart clearly shows only
the Buy/Sell badges this script produces.
- No changes to signal logic, position management, or calculations -
documentation and chart presentation only.
Release Notes
Update — Added a disclaimer to the description.

No changes to the calculation logic, default settings, or plot behavior — this update only adds an educational-purposes/not-financial-advice disclaimer to the description, matching the other indicators in this series.
Release Notes
Update — Added independent "ADX Rising" confirmation for the upper and lower zones, plus dedicated BSB+ADX alerts.

Two new toggles have been added under the ADX settings, both checked by default:

ADX Rising (at/above upper): when checked, the upper-zone condition also requires ADX to be higher than on the previous bar — not just past the threshold, but still building.
ADX Rising (at/below lower): when checked, the lower-zone condition also requires ADX to be higher than on the previous bar — catching the early pickup out of a quiet, low-ADX regime rather than a fading one.

These two toggles are fully independent of each other. With both unchecked, the ADX condition behaves exactly as before (upper-or-lower threshold only).

Also added dedicated "BSB+ADX Buy" and "BSB+ADX Sell" alertconditions at the top of the alert list, alongside the existing Buy/Sell Signal, Entry Signal, Take Profit Hit, Stop Loss Hit, and Entry Invalidated alerts. As before, alerts only fire once the entry-to-stop distance also meets "Alert Sensitivity (points)."

No changes to core position management, stop-loss/take-profit calculation, or badge visuals.
Release Notes
Update — Fixed a same-bar edge case where risk lines could fail to appear on an immediate re-entry.

If a position closed via Take Profit or Stop Loss on the exact same bar that a fresh, opposite BSB signal opened a brand-new position, the badge for the new position would display correctly, but the entry/SL/TP lines and the SL distance label would sometimes fail to appear for it. This was caused by an internal "was a badge shown for this position" flag being reset for the just-closed position after it had already been correctly set for the new one — silently overwriting it back to false.

The reset now runs immediately after a position closes and before any new-entry logic is evaluated, so a same-bar close-and-reopen no longer clears the new position's badge/line state.

No changes to entry, stop-loss, take-profit, ADX filtering, or badge logic — only the reliability of the on-chart lines and SL label that accompany a badge.
Release Notes
UPDATED — Badge Colors Changed
Buy badge color changed to green, Sell badge color changed to red. Applies to both standalone BSB signals and BSB+ADX-filtered signals. No changes to signal logic, entry/exit rules, or alerts — visual-only update.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.