OPEN-SOURCE SCRIPT

Pivot MA Structure

4 891
Pivot MA Structure— Complete User Guide

1. General Purpose
This indicator combines several independent market-reading components into one framework:

Pivot-controlled directional moving averages
Bullish and Bearish market-structure shifts
Pre-break structure candidates
Trend-continuation markers
Shift-direction MA retests
Anchored VWAP equilibrium
RSI 50 equilibrium
Fair Value Gaps and breakers
Long/Short health scores
A real-time information dashboard
Selectable alerts
It is an indicator, not an automated strategy. It does not place orders, calculate position size, or automatically manage stop-loss and take-profit orders.

Its primary objective is to answer five questions:

What is the latest structural direction?
Which directional Pivot MA is currently active?
Do structure and the active MA agree?
Do VWAP and RSI support the same direction?
Is there a suitable continuation or retest location for entry?
2. The Core Reading Model
The indicator separates market information into three layers.

Structural layer
This layer detects:

Bullish Shift
Bearish Shift
Bullish continuation
Bearish continuation
Unbroken bullish and bearish candidates
A Shift represents a change in the direction of confirmed structure breaks.

Directional MA layer
This layer determines whether the active moving-average condition is:

Bullish
Bearish
Ghost/inactive
Still waiting for a valid pivot
Only one directional MA can be active at a time.

Confirmation layer
The following secondary filters measure the quality of the directional condition:

Anchored VWAP
RSI relative to 50
Fair Value Gaps
Directional MA retests
Health score
A structural signal does not automatically imply that all confirmation filters agree.

3. Pivot Moving Average System
Default settings
MA type: EMA
MA length: 50
Pivot strength: 5
Pivot qualification: All Confirmed Pivots
Source: Pivot Side
The MA type can be changed to:

EMA
SMA
WMA
RMA
HMA
Pivot Side source
When MA Source = Pivot Side:

The bullish MA is calculated from low.
The bearish MA is calculated from high.
This creates two distinct directional averages:

Green MA for bullish conditions
Red MA for bearish conditions
If Close or HL2 is selected, both averages use the selected common source.

How a Pivot MA is created
A bullish Pivot MA becomes available after a qualifying confirmed low pivot.

A bearish Pivot MA becomes available after a qualifying confirmed high pivot.

The pivot does not become known immediately. With Pivot Strength set to 5, the system requires five bars on the right side of the pivot before confirming it.

Therefore, pivot activation is intentionally delayed.

Pivot Qualification
All Confirmed Pivots
This is the default mode.

Every confirmed low pivot can refresh the bullish MA state.
Every confirmed high pivot can refresh the bearish MA state.
This allows higher lows in an uptrend to reactivate the bullish side and lower highs in a downtrend to refresh the bearish side.

HH / LL Only
This is a more selective mode.

A bearish MA trigger requires a pivot high above the previous pivot high.
A bullish MA trigger requires a pivot low below the previous pivot low.
This mode generates fewer MA refresh events and may leave an MA in ghost mode for longer.

4. Active and Ghost MA Logic
Active bullish MA
The bullish MA is eligible to become active when:

The bullish MA exists.
It has not remained locked by an unresolved break.
Price is at or above the bullish MA.
The bullish MA is rising.
Active bearish MA
The bearish MA is eligible when:

The bearish MA exists.
It has not remained locked by an unresolved break.
Price is at or below the bearish MA.
The bearish MA is falling.
One active MA at a time
The indicator does not allow both MAs to be active simultaneously.

If only the bullish side is eligible:

Bullish MA becomes active.
Bearish MA becomes ghost.
If only the bearish side is eligible:

Bearish MA becomes active.
Bullish MA becomes ghost.
If neither side is eligible:

Both lines can appear as ghost lines.
If both sides are technically eligible during compression:

A new bearish pivot or downward bar movement gives priority to the bearish MA.
Otherwise, the bullish MA receives priority.
Active line thickness
The active directional MA is always displayed one step thicker than a ghost MA.

This allows the currently accepted directional condition to be identified visually without relying only on color.

Ghost lines
A ghost line is a faded directional MA.

Ghost status means that the MA still exists and is still calculated, but it is not currently accepted as the active directional condition.

A ghost line is not frozen. Its value continues to move because the underlying MA calculation continues.

MA break behavior
The bullish MA is broken when price crosses below it according to the selected break confirmation.

The bearish MA is broken when price crosses above it.

The break method can be:

Close: requires the closing price to cross the MA.
Wick: reacts to the bar’s low or high crossing the MA.
After a genuine break, the line becomes ghosted. A new qualifying same-side pivot can reset its broken state.

5. Market Structure Engine
Default structure length
Structure Length: 12
The engine uses an odd-length fractal model. An even input is internally advanced to the next odd number.

Therefore:

Input 12 becomes an internal 13-bar fractal.
Pivot strength becomes 6 bars on each side.
This is different from using 12 left bars and 12 right bars. It is a full fractal-window interpretation.

Confirmed structure pivots
The engine continuously tracks:

Latest confirmed fractal high
Latest confirmed fractal low
These become potential break candidates.

A structure pivot appears only after its required right-side bars have completed.

6. Candidate Lines
Bullish Break Candidate
A confirmed fractal high creates a bullish break candidate.

It is displayed as:

Green dotted line
Bullish Break Candidate text above the line
This level represents the price that must be exceeded for an upward structure break.

Bearish Break Candidate
A confirmed fractal low creates a bearish break candidate.

It is displayed as:

Red dotted line
Bearish Break Candidate text below the line
This level represents the price that must be broken for a downward structure break.

Candidate projection
The default projection is five bars to the right.

The candidate does not extend infinitely. On every new bar:

Its right endpoint moves forward.
It remains five bars ahead of the current bar.
It stops when broken or replaced by a newer same-side pivot.
Candidate replacement
When a newer confirmed pivot of the same side appears:

The previous unbroken candidate is deleted.
A new candidate begins from the newer pivot.
This ensures that the chart emphasizes the latest actionable structure level.

7. Bullish and Bearish Shift Logic
The internal logic follows a CHoCH-style direction-change model, but the chart does not display the word “CHoCH.”

It uses:

Bullish Shift
Bearish Shift
Bullish Shift
A Bullish Shift occurs when:

The last confirmed structure break was downward.
Price subsequently breaks the latest unbroken fractal high.
The break can be confirmed by:

Close above the level, or
Wick above the level
depending on the selected Break Confirmation.

When confirmed:

The candidate line ends at the breakout bar.
The line becomes a stronger green dotted shift segment.
Bullish Shift appears above the middle of the segment.
The dashboard’s Latest Shift changes to Bullish Shift.
The bullish retest detector becomes armed.
Bearish Shift
A Bearish Shift occurs when:

The last confirmed structure break was upward.
Price subsequently breaks the latest unbroken fractal low.
When confirmed:

The candidate line ends at the breakdown bar.
It becomes a stronger red dotted shift segment.
Bearish Shift appears below the middle of the line.
The dashboard changes to Bearish Shift.
The bearish retest detector becomes armed.
First structure break
The first break establishes the initial direction.

Because no previous opposite break exists, it is not classified as a Shift.

It is treated as a continuation break and receives a directional triangle.

8. Trend-Continuation Triangles
The indicator does not draw BOS lines.

Instead, a same-direction continuation break is marked directly on the breaking candle.

Bullish continuation
A bullish continuation is shown as:

Green upward triangle
Located below the breakout candle
It means that an upward break occurred without reversing the previous break direction.

Bearish continuation
A bearish continuation is shown as:

Red downward triangle
Located above the breakdown candle
It means that a downward break occurred without reversing the previous break direction.

How to interpret continuation marks
Continuation triangles are not fresh reversal signals.

They are better interpreted as confirmation that the existing structural direction is continuing.

A continuation marker is generally more useful when:

The matching directional MA is active.
Price is on the correct side of VWAP.
RSI supports the same direction.
The breakout is not entering directly into an opposing FVG or major swing level.
Avoid treating every continuation triangle as an automatic market entry. Entering immediately after an extended breakout can create poor risk-to-reward.

9. Directional MA Retest — “R” Marker
Important definition
In the current version, the R marker detects a retest of the same-direction Pivot MA, not the horizontal dotted shift line.

After a Bullish Shift:

The indicator monitors the green bullish Pivot MA.
After a Bearish Shift:

It monitors the red bearish Pivot MA.
Bullish retest
After a Bullish Shift, the retest detector waits for a later candle whose range intersects the green bullish MA:

Candle low is at or below the MA.
Candle high is at or above the MA.
When the first valid touch occurs:

A green R appears below the candle.
The bullish retest alert can trigger.
The retest detector stops waiting until a new Shift occurs.
The green line can be active or ghost. The retest detector only requires the corresponding bullish MA to exist.

Bearish retest
After a Bearish Shift, the first later candle that intersects the red bearish MA produces:

A red R
Located above the candle
A bearish retest alert opportunity
Why an R may not appear
An R will not appear when:

No valid Bullish or Bearish Shift has occurred.
The contact happens on the Shift candle itself.
The candle does not actually intersect the MA value.
The first retest after that Shift has already been marked.
A new opposite Shift replaced the previous retest direction.
The corresponding directional MA does not yet exist.
Show Directional MA Retests is disabled.
The visual toggle does not disable the underlying alert calculation.

10. Anchored VWAP Equilibrium
Default status
The VWAP line is enabled by default.

Available anchors
Session
Week
Month
Session
The VWAP resets with the daily/session boundary.

Week
The VWAP resets at the beginning of each week.

Month
The VWAP resets at the beginning of each month.

Horizontal VWAP presentation
The indicator does not plot the entire conventional curved VWAP history.

Instead, it takes the latest anchored VWAP value and displays it as a horizontal equilibrium reference.

Default presentation:

100 bars to the left
10 bars to the right
VWAP label on the right
Dashed neutral-colored line
The right-side length and label offset are adjustable.

Bullish interpretation
Price above VWAP suggests that current price is trading above the volume-weighted equilibrium.

This supports a bullish setup.

Bearish interpretation
Price below VWAP suggests that price is trading below the volume-weighted equilibrium.

This supports a bearish setup.

VWAP as a trade-management filter
For an existing long:

Remaining above VWAP supports the health of the position.
Losing VWAP removes one bullish health point.
Reclaiming VWAP can restore that point.
For an existing short:

Remaining below VWAP supports the bearish condition.
Moving above VWAP weakens the short health score.
VWAP alone is not an entry or exit signal. It is an equilibrium filter.

11. RSI 50 Price Equilibrium
Default settings
RSI Length: 14
RSI line: enabled
Midpoint: 50
HUD interpretation
RSI at or above 50 is bullish.
RSI below 50 is bearish.
Horizontal RSI 50 price line
A literal RSI value of 50 cannot be plotted meaningfully on the same price scale as BTC, forex, or commodities.

Therefore, the indicator stores the closing price where RSI most recently crossed 50.

That price becomes the RSI 50 horizontal equilibrium level.

It represents the latest price associated with a momentum-regime transition.

The line:

Is green when the current RSI is above 50.
Is red when the current RSI is below 50.
Extends a configurable number of bars left and right.
Has an offset label on the right.
Practical use
For a long position:

RSI above 50 supports positive momentum.
RSI falling below 50 reduces long health.
For a short position:

RSI below 50 supports negative momentum.
RSI reclaiming 50 reduces short health.
RSI 50 should be used as confirmation, not as a standalone trigger.

12. Fair Value Gap Engine
The FVG engine is enabled by default.

It supports:

Standard FVG mode
Breaker mode
Bullish and bearish zones
ATR threshold filtering
Multiple mitigation methods
Overlap filtering
Midlines
Optional right extension
Optional raid tracking
Bullish FVG
A bullish FVG is created when the current low is above the high from two bars earlier, producing a three-candle imbalance.

The engine also applies the selected ATR threshold to filter insignificant gaps.

A bullish FVG is normally interpreted as:

An imbalance below price
A possible pullback support area
A potential location for bullish continuation or mitigation
Bearish FVG
A bearish FVG is created when the current high is below the low from two bars earlier.

It is generally interpreted as:

An imbalance above price
A possible resistance area
A potential bearish pullback or mitigation location
Show Last
Show Last determines how many recent bullish and bearish FVGs are displayed.

With a value of 5, the engine can show:

Five recent bullish zones
Five recent bearish zones
subject to mitigation and overlap removal.

Threshold
The threshold applies an ATR-based significance filter.

A value of 0 accepts all qualifying gaps.
Higher values require a stronger displacement relative to ATR.
Increasing the threshold generally produces fewer but more significant FVGs.

Mitigation modes
Close
Uses the candle body boundary as the mitigation trigger.

For a bullish FVG, the body must penetrate below the relevant lower boundary.

For a bearish FVG, the body must penetrate above the relevant upper boundary.

Wick
Uses the candle’s full high/low range.

This is the most sensitive mitigation method.

Avg
Uses the midpoint of the gap.

This treats a move through the FVG’s average price as mitigation.

FVG mode
In standard FVG mode:

The zone remains visible while active.
It is removed when the selected mitigation condition is satisfied.
Breakers mode
In Breakers mode:

The original FVG is tracked.
When mitigated, it becomes a breaker.
Its directional display changes to the opposite-side color.
It remains until the breaker’s opposite invalidation condition occurs.
Hide Overlap
When enabled, overlapping FVGs are filtered.

The newest FVG is compared against:

Older FVGs in the same direction
FVGs in the opposite direction
Overlapping stored zones can be removed to reduce visual clutter.

Midline
When enabled, the midpoint of each FVG is displayed.

The midpoint can be useful as:

A partial mitigation level
A mean-reversion reference
A refined entry or invalidation location
Extend FVG
When disabled, FVG drawings end at the current bar.

When enabled, active FVG zones extend to the right.

Display Raids
Raid tracking looks for liquidity interactions around an active FVG.

For a bullish FVG, it can track a move below the upper FVG boundary followed by a close back above it.

For a bearish FVG, it can track a move above the lower boundary followed by a close back below it.

Raid locations are displayed with a line and an x marker.

13. Information HUD
The information table summarizes the indicator’s current state.

Latest Shift
Possible values:

Bullish Shift
Bearish Shift
Waiting
This row stores the most recent genuine opposite-direction structure break.

It does not reset to neutral after a few bars. It remains bullish or bearish until an opposite Shift occurs.

Bullish Pivot MA
Possible values:

Waiting
Active
Ghost
Waiting
No qualifying bullish pivot has created the bullish MA state yet.

Active
The bullish MA currently satisfies the directional activation logic.

Ghost
The bullish MA exists but is not currently accepted as active.

Bearish Pivot MA
Uses the same status definitions for the red bearish MA.

Shift + MA
Possible values:

Bullish Match
Bearish Match
No Match
Bullish Match
Requires:

Latest Shift is bullish.
Bullish Pivot MA is active.
Bearish Match
Requires:

Latest Shift is bearish.
Bearish Pivot MA is active.
No Match
Structure and the active directional MA do not currently agree.

This is a warning that the setup lacks core confluence.

VWAP
Possible values:

Price Above
Price Below
Unavailable
This reports the current price’s relationship with the selected anchored VWAP.

RSI
Displays:

Current RSI value
Above 50 or Below 50
Example:

56.4 / Above 50

Long Health
The long score counts currently satisfied bullish conditions.

Short Health
The short score counts currently satisfied bearish conditions.

Composite Bias
Possible values:

Bullish
Bearish
Balanced
The result is determined by comparing Long Health with Short Health.

Long Health greater than Short Health → Bullish
Short Health greater than Long Health → Bearish
Equal values → Balanced
Composite Bias is a comparison of rule counts, not a forecast.

14. Health Score Calculation
With all default score filters enabled, each side has four factors.

Long Health factors
One point is awarded for each condition:

Latest Shift is Bullish.
Bullish Pivot MA is active.
Price is above VWAP.
RSI is at or above 50.
Short Health factors
One point is awarded for each condition:

Latest Shift is Bearish.
Bearish Pivot MA is active.
Price is below VWAP.
RSI is below 50.
Score examples
100% — 4/4
All directional conditions agree.

This is the strongest confluence state produced by the dashboard.

It does not mean the trade has a 100% probability of success.

75% — 3/4
The setup is directionally favorable, but one filter disagrees.

Examples:

Bullish Shift and bullish MA are aligned, but RSI is below 50.
Bearish structure is aligned, but price is still above VWAP.
50% — 2/4
The condition is mixed.

This often occurs during:

Transition
Consolidation
Pullback
Delayed confirmation
Conflict between structure and momentum
25% — 1/4
Only one filter supports the direction.

This is generally a weak environment for initiating a new position.

0% — 0/4
None of the directional filters support that side.

Disabling score filters
If VWAP is removed from the score, the denominator decreases.

If RSI is also removed, only two core factors remain:

Shift direction
Active directional MA
The displayed percentage automatically adjusts to the number of enabled factors.

Important limitation
Health is a confluence percentage, not a statistically measured win probability.

A 100% Long Health reading means four out of four programmed bullish conditions are true. It does not mean the market has a 100% chance of rising.

15. Suggested Long Entry Framework
Core long condition
The preferred long environment is:

Latest Shift = Bullish Shift
Bullish Pivot MA = Active
Shift + MA = Bullish Match
This is the minimum structural and directional agreement.

Additional confirmation
A higher-quality long condition may also include:

Price above VWAP
RSI above 50
Long Health at 75% or 100%
Bullish FVG below or around the entry
No large bearish FVG immediately above
A green R retest marker
Aggressive long entry
An aggressive trader may enter near the Bullish Shift breakout.

Risks:

The breakout may be extended.
Stop distance may be large.
Price may return to the broken structure or MA before continuing.
Conservative long entry
A more conservative sequence is:

Bullish Shift appears.
Bullish MA becomes active or remains directionally valid.
Price stays above or reclaims VWAP.
RSI remains above or reclaims 50.
Price pulls back into the green MA.
A green R appears.
The retest candle shows rejection or closes constructively.
This avoids chasing the initial breakout.

Continuation entry
A green triangle can support a continuation entry when:

The dashboard already has bullish alignment.
Price is not excessively extended above the MA.
The continuation break has room before the next bearish FVG or swing resistance.
A triangle by itself is not enough.

16. Suggested Short Entry Framework
Core short condition
The preferred short environment is:

Latest Shift = Bearish Shift
Bearish Pivot MA = Active
Shift + MA = Bearish Match
Additional confirmation
A higher-quality short may include:

Price below VWAP
RSI below 50
Short Health at 75% or 100%
Bearish FVG above or near the entry
No major bullish FVG immediately below
A red R retest marker
Conservative short entry
A conservative bearish sequence is:

Bearish Shift appears.
Bearish Pivot MA becomes active.
Price remains below or rejects VWAP.
RSI remains below 50.
Price rallies back into the red MA.
A red R appears.
The retest candle rejects the MA or closes bearishly.
17. How to Stay in a Position
Staying in a long
A long remains structurally healthier while:

Latest Shift remains bullish.
Bullish Pivot MA remains active.
Price remains above VWAP.
RSI remains above 50.
Long Health remains at 75% or 100%.
Bullish FVGs below price continue to act as support.
No Bearish Shift is created.
Early long weakness
Potential deterioration begins when:

RSI falls below 50.
Price falls below VWAP.
Bullish MA becomes ghost.
Long Health falls from 100% to 75% or 50%.
One lost factor is not necessarily an exit. It is a warning that confluence is decreasing.

Strong long invalidation
More serious invalidation can include:

Bearish Shift
Bearish Match
Bullish MA break
Price remaining below VWAP
RSI remaining below 50
Bullish FVG support being fully mitigated
Staying in a short
A short remains healthier while:

Latest Shift remains bearish.
Bearish MA remains active.
Price remains below VWAP.
RSI remains below 50.
Short Health remains high.
Bearish FVGs above price act as resistance.
No Bullish Shift appears.
Strong short invalidation
Potential invalidation includes:

Bullish Shift
Bullish Match
Bearish MA break
Sustained price above VWAP
RSI above 50
Bearish FVG resistance being invalidated
18. Stop-Loss and Profit Management
The indicator does not place stops or targets.

Possible stop references include:

For long trades
Below the retest candle low
Below the latest confirmed swing low
Below the bullish FVG
Below the bullish MA with an ATR buffer
Below the structure level that would invalidate the setup
For short trades
Above the retest candle high
Above the latest swing high
Above the bearish FVG
Above the bearish MA with an ATR buffer
Possible profit references
Previous swing high/low
Opposing FVG
Major VWAP deviation area
Fixed risk-to-reward target
Partial exit at 1R and trailing remainder
Opposite Shift
Health score deterioration
Stops should not be moved farther away simply to avoid accepting a loss.

19. Alerts
The script provides selectable conditions for:

Bullish Shift Created
Bearish Shift Created
Bullish Directional MA Retest
Bearish Directional MA Retest
Bullish Pivot MA Broken
Bearish Pivot MA Broken
Bullish Shift + Bullish MA alignment
Bearish Shift + Bearish MA alignment
Alert toggles
The shift and retest alerts have individual enable/disable inputs.

These settings control whether the corresponding alert condition can trigger.

Important TradingView behavior
Enabling an alert condition in the indicator settings does not automatically create a TradingView alert.

You must still:

Open TradingView’s alert dialog.
Select the indicator.
Select the desired alert condition.
Choose the frequency.
Create the alert.
For confirmed signals, using Once Per Bar Close is generally the most consistent choice.

20. Repainting and Confirmation Considerations
Pivot delay
Confirmed pivots require future right-side bars.

This means:

Pivot signals are delayed.
Once confirmed, the historical pivot itself is stable.
The indicator does not know a pivot at the exact moment the pivot bar first forms.
Bar-close confirmation
Confirm Signals On Bar Close is enabled by default.

This reduces intrabar signal changes for:

MA breaks
Structure breaks
Shift creation
Retests
Intrabar movement
The current MA, VWAP, RSI, and live candidate values may still visually move while the current candle is forming.

Using bar-close confirmation does not freeze the current bar’s underlying price calculations.

FVG evolution
FVGs can disappear when:

Mitigated
Invalidated
Removed by overlap filtering
Excluded by the Show Last setting
This is normal lifecycle behavior, not necessarily historical repainting.

21. Practical Decision Hierarchy
A disciplined way to use the indicator is:

Step 1 — Identify structure
Check Latest Shift.

Bullish Shift → prioritize long ideas.
Bearish Shift → prioritize short ideas.
Waiting → insufficient shift history.
Step 2 — Confirm the directional MA
Check Shift + MA.

Bullish Match → bullish structure and MA agree.
Bearish Match → bearish structure and MA agree.
No Match → wait or reduce conviction.
Step 3 — Check equilibrium
For longs:

Prefer price above VWAP.
Prefer RSI above 50.
For shorts:

Prefer price below VWAP.
Prefer RSI below 50.
Step 4 — Check location
Use:

Directional MA retest
FVG support/resistance
Recent swing levels
VWAP
A good directional idea entered at a poor location can still have poor risk-to-reward.

Step 5 — Check health
75–100%: favorable confluence
50%: mixed
0–25%: weak for that direction
Step 6 — Define invalidation before entry
Determine:

Stop level
Position size
Maximum acceptable loss
First target
Conditions for partial or full exit
Disclaimer
This indicator is provided for informational, educational, and analytical purposes only. It does not constitute financial advice, investment advice, trading advice, a solicitation, or a recommendation to buy or sell any financial instrument.

Market-structure shifts, moving averages, VWAP, RSI, Fair Value Gaps, retest markers, continuation symbols, health scores, and alerts are mathematical interpretations of historical and real-time market data. They do not guarantee future price movement or profitable outcomes.

The Health Score is a count of aligned indicator conditions. It is not a probability of success, an expected return, or a measure of actual trade risk.

Trading cryptocurrencies, forex, commodities, futures, CFDs, and other leveraged products involves substantial risk and may result in the loss of some or all invested capital. Historical performance does not guarantee future results. Signals may be delayed because of pivot confirmation, and real-time values may change before a candle closes.

Always perform independent analysis, use appropriate position sizing, define a stop-loss before entering a trade, account for fees and slippage, and never risk capital you cannot afford to lose. The user remains solely responsible for all trading and investment decisions.

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

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