OPEN-SOURCE SCRIPT

N Bar Reversal Detector [LuxAlgo]

By LuxAlgo
Wizard
The N Bar Reversal Detector is designed to detect and highlight N-bar reversal patterns in user charts, where N represents the length of the candle sequence used to detect the patterns. The script incorporates various trend indicators to filter out detected signals and offers a range of customizable settings to fit different trading strategies.

🔶 USAGE

snapshot

The N-bar reversal pattern extends the popular 3-bar reversal pattern. While the 3-bar reversal pattern involves identifying a sequence of three bars signaling a potential trend reversal, the N-bar reversal pattern builds on this concept by incorporating additional bars based on user settings. This provides a more comprehensive indication of potential trend reversals. The script automates the identification of these patterns and generates clear, visually distinct signals to highlight potential trend changes.

snapshot

When a reversal chart pattern is confirmed and aligns with the price action, the pattern's boundaries are extended to create levels. The upper boundary serves as resistance, while the lower boundary acts as support.

snapshot

The script allows users to filter patterns based on the trend direction identified by various trend indicators. Users can choose to view patterns that align with the detected trend or those that are contrary to it.

snapshot

🔶 DETAILS

🔹 The N-bar Reversal Pattern

The N-bar reversal pattern is a technical analysis tool designed to signal potential trend reversals in the market. It consists of N consecutive bars, with the first N-1 bars used to identify the prevailing trend and the Nth bar confirming the reversal. Here’s a detailed look at the pattern:

  • Bullish Reversal: In a bullish reversal setup, the first bar is the highest among the first N-1 bars, indicating a prevailing downtrend. Most of the remaining bars in this sequence should be bearish (closing lower than where they opened), reinforcing the existing downward momentum. The Nth (most recent) bar confirms a bullish reversal if its high price is higher than the high of the first bar in the sequence (standard pattern). For a stronger signal, the closing price of the Nth bar should also be higher than the high of the first bar.

  • Bearish Reversal: In a bearish reversal setup, the first bar is the lowest among the first N-1 bars, indicating a prevailing uptrend. Most of the remaining bars in this sequence should be bullish (closing higher than where they opened), reinforcing the existing upward momentum. The Nth bar confirms a bearish reversal if its low price is lower than the low of the first bar in the sequence (standard pattern). For a stronger signal, the closing price of the Nth bar should also be lower than the low of the first bar.


🔹 Min Percentage of Required Candles

This parameter specifies the minimum percentage of candles that must be bullish (for a bearish reversal) or bearish (for a bullish reversal) among the first N-1 candles in a pattern. For higher values of N, it becomes more challenging for all of the first N-1 candles to be consistently bullish or bearish. By setting a percentage value, P, users can adjust the requirement so that only a minimum of P percent of the first N-1 candles need to meet the bullish or bearish condition. This allows for greater flexibility in pattern recognition, accommodating variations in market conditions.

🔶 SETTINGS

  • Pattern Type: Users can choose the type of the N-bar reversal patterns to detect: Normal, Enhanced, or All. "Normal" detects patterns that do not necessarily surpass the high/low of the first bar. "Enhanced" detects patterns where the last bar surpasses the high/low of the first bar. "All" detects both Normal and Enhanced patterns.
  • Reversal Pattern Sequence Length: Specifies the number of candles (N) in the sequence used to identify a reversal pattern.
  • Min Percentage of Required Candles: Sets the minimum percentage of the first N-1 candles that must be bullish (for a bearish reversal) or bearish (for a bullish reversal) to qualify as a valid reversal pattern.
  • Derived Support and Resistance: Toggles the visibility of the support and resistance levels/zones.


🔹 Trend Filtering

  • Filtering: Allows users to filter patterns based on the trend indicators: Moving Average Cloud, Supertrend, and Donchian Channels. The "Aligned" option only detects patterns that align with the trend and conversely, the "Opposite" option detects patterns that go against the trend.


🔹 Trend Indicator Settings

  • Moving Average Cloud: Allows traders to choose the type of moving averages (SMA, EMA, HMA, etc.) and set the lengths for fast and slow moving averages.
  • Supertrend: Options to set the ATR length and factor for Supertrend.
  • Donchian Channels: Option to set the length for the channel calculation.


🔶 RELATED SCRIPTS

3barpatternChart patternscloudluxalgoreversalreversalssupertrendTrend Analysis
LuxAlgo
Wizard
Get access to our exclusive tools: luxalgo.com

Join our 150k+ community: discord.gg/lux

All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer