PROTECTED SOURCE SCRIPT

Valid Pullbacks [keypoems]

378
Valid Pullbacks

This indicator marks Valid Pullbacks on a chart. The core of the script is designed to find significant swing points by maintaining and validating candidate highs and lows.

Notice this is very different than other swing marker (fractals or otherwise). This is the base used to draw DTFX/Supply and Demand Zones. I am starting a full rewrite of all the components of my market structure indicator and this is part 1.

Core Concepts

The script operates in a stateful manner, alternating between searching for a Valid Pullback High and a Valid Pullback Low.

Initial State: At the beginning, the script assumes it is searching for the first Valid Pullback High.
Alternating Search: Once a Valid Pullback High is confirmed, the script switches its state to search for a Valid Pullback Low. Conversely, after a Valid Pullback Low is confirmed, it begins searching for a Valid Pullback High. This ensures a proper sequence of alternating swing points.

Defining a Swing Point
The script uses two primary ways to define a swing point, depending on user settings:

Wick-Based Swing (Default):

A Swing High occurs when the high of a candle is higher than the high of the candle immediately before and after it. (high[1] > high and high[1] > high[2])

A Swing Low occurs when the low of a candle is lower than the low of the candle immediately before and after it. (low[1] < low and low[1] < low[2])

Close-Based Swing:

A Swing High is identified based on a more complex relationship involving the closes and highs/opens of the three most recent candles, requiring the swing point to be formed by an "up-close" candle.
A Swing Low is identified similarly, requiring the swing point to be formed by a "down-close" candle.

* The Logic
This logic to update the internal state runs on every bar of the chart to update the status of candidate highs and lows.

1. Candidate Selection
The script continuously searches for the best possible candidate for the next valid swing.

Searching for a Candidate High:

This happens only if the last confirmed swing was a Valid Pullback Low (or at the very start).
On every new bar, the script checks if the previous bar represents a better candidate than the current one.
A "better" candidate is one with a higher price. The specific price checked (high or close) depends on whether the close-based or wick-based definition of a swing is being used.
If a better candidate is found, it replaces the existing candidateHigh. The candidate's price is always recorded as the high of that bar.

Searching for a Candidate Low:

This happens only if the last confirmed swing was a Valid Pullback High.
The logic is the mirror opposite of the high search. It looks for a "better" candidate with a lower price on every new bar.
If a better candidate is found, it replaces the existing candidateLow. The candidate's price is always recorded as the low of that bar.
2. Candidate Confirmation
Once a candidate is being tracked, the script waits for a specific market action to confirm it as a Valid swing.

Confirming a Valid Pullback High:

A candidateHigh is confirmed and becomes a Valid Pullback High if the price breaks below the low of the candidate bar.

When this happens:
The candidateHigh is stored in the validHighs array.
Both the candidateHigh and candidateLow are completely reset.
The script's state switches to now search for a Valid Pullback Low.
Confirming a Valid Pullback Low:

A candidateLow is confirmed and becomes a Valid Pullback Low if the price breaks above the high of the candidate bar.

When this happens:
The candidateLow is stored in the validLows array.
Both the candidateLow and candidateHigh are completely reset.
The script's state switches to now search for a Valid Pullback High.

This continuous process of searching, updating, and confirming candidates allows the script to dynamically identify and plot the most recent and relevant valid swing points on the chart.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。