OPEN-SOURCE SCRIPT

Pivot Order Blocks - Lines

2 126
The indicator identifies pivot highs and pivot lows in the price chart to detect potential order blocks. It then draws horizontal lines representing the top and bottom of these blocks, which can be extended until the price interacts with them or left as fixed-length lines. The indicator allows customization of pivot detection, line appearance, and behavior, making it adaptable to various trading strategies and timeframes.
Key features include:
Pivot-based order block detection: Uses pivot highs and lows to define bearish and bullish order blocks.

Customizable inputs: Options for source data (wicks or body), pivot lengths, line colors, and line behavior.

Dynamic line extension: Lines can extend until price breaks the order block or remain fixed in length.

Broken level visualization: Option to display old or broken order blocks with distinct colors.

The indicator is overlaid on the price chart, with a maximum lookback of 500 bars and a limit of 500 lines to ensure performance efficiency.
Inputs and Configuration
The indicator provides a range of customizable inputs, grouped into Pivots and Plots sections, allowing traders to tailor its behavior to their preferences.
Pivots Group
Source (input.string):
Options: 'Wicks' or 'Body'.

Determines whether the pivot calculations use the high/low wicks or the open/close prices (body) of candles.

Default: 'Body'.

Example: Selecting 'Wicks' uses the high/low prices, while 'Body' uses the candle's open/close to define order block boundaries.

Pivot High Parameters:
Left Length (leftLenH): Number of bars to the left of a pivot high (default: 25, minimum: 1).

Right Length (rightLenH): Number of bars to the right of a pivot high (default: 25, minimum: 1).

These parameters define the lookback and confirmation periods for detecting pivot highs.

Pivot Low Parameters:
Left Length (leftLenL): Number of bars to the left of a pivot low (default: 25, minimum: 1).

Right Length (rightLenL): Number of bars to the right of a pivot low (default: 25, minimum: 1).

These define the lookback and confirmation periods for detecting pivot lows.

Plots Group
Bullish Color (bullLineColor):
Color for bullish order block lines (default: semi-transparent gray).

Used to highlight zones where buying activity is inferred.

Bearish Color (bearLineColor):
Color for bearish order block lines (default: semi-transparent gray).

Used to highlight zones where selling activity is inferred.

Old/Broken Levels Color (oldLevelColor):
Color for order blocks that have been broken or are no longer active (default: semi-transparent gray).

Applied when the Show Old/Broken Levels option is enabled.

Closed Color (closedLineColor):
Color for broken order blocks when Show Old/Broken Levels is disabled (default: fully transparent gray).

Effectively hides broken levels by making them invisible.

Extend Lines (extendLines):
Boolean option (default: true).

When enabled, lines extend until the price breaks the order block (e.g., price crosses above a bullish block or below a bearish block).

When disabled, lines are drawn with a fixed length.

Line Size (lineLength):
Integer value (default: 30).

Specifies the length of lines (in bars) when Extend Lines is disabled.

Tooltip: Clarifies that this applies only when lines are not extended.

Show Old/Broken Levels (showOldLevels):
Boolean option (default: false).

When enabled, broken order blocks are displayed with the oldLevelColor. Otherwise, they are shown with the closedLineColor (typically transparent).

Core Calculations
The indicator operates by detecting pivot points and using them to define order blocks, which are then visualized as horizontal lines. Below is a breakdown of the calculations:
1. Pivot Detection
Pivot High: Calculated using ta.pivothigh(pivotHighOption, leftLenH, rightLenH).
Identifies a pivot high when the price at a given bar is higher than the prices in the specified leftLenH bars before and rightLenH bars after.

pivotHighOption is either high (if source = 'Wicks') or close (if source = 'Body').

Pivot Low: Calculated using ta.pivotlow(pivotLowOption, leftLenL, rightLenL).
Identifies a pivot low when the price at a given bar is lower than the prices in the specified leftLenL bars before and rightLenL bars after.

pivotLowOption is either low (if source = 'Wicks') or close (if source = 'Body').

2. Order Block Definition
Bullish Order Block (triggered by a pivot low):
Represents a zone where buying pressure likely occurred.

Left Boundary (leftBull): Set to bar_index - leftLenL, aligning with the pivot low's left lookback.

Right Boundary (rightBull): Set to bar_index - (leftLenL - lineLength), defining the initial line length.

Top Price (topBull):
If source = 'Body': Uses the higher of open or close at the pivot low bar.

If source = 'Wicks': Uses the lower of open or close to capture the candle body’s top.

Bottom Price (bottomBull):
If source = 'Body': Uses the lower of open or close.

If source = 'Wicks': Uses the low price to include the wick.

Bearish Order Block (triggered by a pivot high):
Represents a zone where selling pressure likely occurred.

Left Boundary (leftBear): Set to bar_index - leftLenH.

Right Boundary (rightBear): Set to bar_index - (leftLenH - lineLength).

Top Price (topBear):
If source = 'Body': Uses the higher of open or close.

If source = 'Wicks': Uses the high price to include the wick.

Bottom Price (bottomBear):
If source = 'Body': Uses the lower of open or close.

If source = 'Wicks': Uses the lower of open or close.

3. Line Plotting
For each pivot low:
Two lines are drawn: one at topBull and one at bottomBull, using bullLineColor.

Lines are stored in arrays (bullTopLines, bullBottomLines) for tracking.

A boolean array (bullBroken) tracks whether the block is broken (initially false).

For each pivot high:
Two lines are drawn: one at topBear and one at bottomBear, using bearLineColor.

Lines are stored in arrays (bearTopLines, bearBottomLines).

A boolean array (bearBroken) tracks whether the block is broken (initially false).

4. Line Extension Logic
If extendLines = true, the extend_lines function dynamically adjusts line lengths:
For bullish order blocks:
Lines extend (move right) if the current low price remains above topBull.

If low falls below topBull, the block is marked as broken (bullBroken = true), and the lines:
Change to oldLevelColor (if showOldLevels = true) or closedLineColor (typically transparent).

Stop extending and are fixed at the current bar.

For bearish order blocks:
Lines extend if the current high price remains below bottomBear.

If high exceeds bottomBear, the block is marked as broken (bearBroken = true), and the lines:
Change to oldLevelColor or closedLineColor.

Stop extending.

If extendLines = false, lines are drawn with a fixed length defined by lineLength.

Visualization
The indicator overlays horizontal lines on the price chart:
Bullish Order Blocks: Two lines (top and bottom) in bullLineColor, representing a buying zone.

Bearish Order Blocks: Two lines (top and bottom) in bearLineColor, representing a selling zone.

Broken Levels: Optionally displayed in oldLevelColor or made transparent with closedLineColor.

Lines either extend dynamically or remain fixed, depending on the extendLines setting.

Practical Applications
The Pivot Order Blocks - Lines indicator is valuable for traders employing supply and demand, price action, or institutional trading strategies. Potential use cases include:
Support and Resistance Identification:
Bullish order blocks often act as support zones, where price may bounce.

Bearish order blocks act as resistance zones, where price may reverse.

Trade Entry and Exit:
Traders can enter long positions when price approaches a bullish order block, expecting a bounce.

Short positions can be considered at bearish order blocks, anticipating resistance.

Broken order blocks can signal trend changes or invalidation of a zone.

Risk Management:
Stop-loss levels can be placed below bullish order blocks (for longs) or above bearish order blocks (for shorts).

The indicator’s clear visualization aids in setting precise price targets.

Trend Confirmation:
Repeated rejections at order blocks can confirm the strength of a trend.

Broken order blocks may indicate a shift in market structure.

Multi-Timeframe Analysis:
Traders can apply the indicator on higher timeframes (e.g., daily) to identify significant order blocks, then use lower timeframes for precise entries.

Strengths
Customizability: Extensive input options allow tailoring to different markets, timeframes, and trading styles.

Dynamic Behavior: The ability to extend lines until broken aligns with real-time price action.

Clear Visualization: Distinct colors and optional display of broken levels reduce chart clutter.

Versatility: Suitable for stocks, forex, cryptocurrencies, and other markets supported by TradingView.

Limitations
Lag in Pivot Detection: Pivot points require confirmation (right-side bars), introducing a delay in order block identification.

Parameter Sensitivity: The effectiveness depends on appropriate leftLen and rightLen settings, which may require optimization for specific assets.

Clutter with Many Pivots: In volatile markets, numerous order blocks may overcrowd the chart, especially with showOldLevels = true.

No Predictive Power: Like all technical indicators, it reflects past price action and does not predict future movements.

How to Use
Add to Chart:
Import the indicator into TradingView and apply it to your chart.

Configure Settings:
Choose 'Wicks' or 'Body' based on whether you prioritize full price range or candle body.

Adjust leftLenH, rightLenH, leftLenL, and rightLenL to suit the market’s volatility and timeframe (e.g., shorter lengths for lower timeframes).

Set colors to ensure visibility against your chart background.

Enable extendLines for dynamic analysis or disable for fixed-length lines.

Decide whether to show old/broken levels based on your preference for chart clarity.

Interpret Signals:
Monitor price reactions at order blocks for potential reversals or continuations.

Use broken order blocks to assess changes in market structure.

Combine with Other Tools:
Pair with indicators like moving averages, RSI, or volume to confirm signals.

Use alongside candlestick patterns or trendlines for confluence.

Conclusion
The Pivot Order Blocks - Lines indicator is a powerful and flexible tool for traders seeking to identify and trade key price zones based on pivot points. Its ability to dynamically extend lines, customize pivot detection, and visualize broken levels makes it suitable for both novice and experienced traders. By highlighting potential support and resistance zones, it aids in making informed trading decisions, particularly in strategies focused on price action and institutional order flow. However, traders should optimize its parameters and combine it with other analysis methods to maximize its effectiveness across different markets and timeframes.

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。