OPEN-SOURCE SCRIPT
MA4 Alignment with Forward Projection

This indicator is a moving-average alignment and projection overlay built on a simple core idea:
MA4 (a 4-period moving average) represents the current short-term mean of price.
MA4[1] is the prior value of that same moving average, used as a 1-bar delayed reference.
From those two series, the script provides four layers of information:
Live alignment (MA4 vs MA4[1])
A forward projection of a sampled historical MA pattern
Projected cross markers (vertical lines) when the projected MA4 would cross projected MA4[1]
A compact table summarizing current alignment and the most recent live cross event
This is designed to help traders visualize:
whether short-term mean behavior is strengthening or weakening, and
where a future cross could plausibly occur if a selected historical pattern repeats.
This script is informational only and does not place trades.
Chart Setup Note (Important)
Because this tool samples a historical pattern window and projects it forward, it is important to let the chart fully load/merge historical data before interpreting the projection.
If the chart history is not fully loaded, the sampled window may be incomplete, which can shift the projection and projected cross markers.
Once the chart is fully merged, the projection remains stable and consistent during scrolling and replay.
What Makes It Different
This is not a basic “MA crossover” indicator. The core differentiator is:
The script extracts a historical MA4 pattern from a user-defined window,
shifts it forward into the future, and
marks projected future crosses between the projected MA4 and projected MA4[1].
It also builds projected deviation envelopes from the sampled window and uses those envelopes for optional stretch/invalidation alerts.
How the Projection Works (Concept)
1) Sample a historical MA “pattern window”
You define a window in the past using:
Pattern Start (bars back)
Pattern End (bars back)
The script collects MA4 values across that window into an internal pattern array.
2) Shift the pattern forward
Shift Pattern Forward (bars) controls how far into the future the sampled pattern is plotted.
3) Delta-anchor projection (optional)
If Delta-anchor projection is enabled, the script projects the shape of the pattern while re-centering it around the current MA4 level.
This keeps the projection visually relevant to current price scale instead of “pasting” old absolute values.
Projected Cross Vertical Lines
When projection is enabled, the script checks for projected cross events:
Bull projected cross: projected MA4 rises through projected MA4[1]
Bear projected cross: projected MA4 falls through projected MA4[1]
When a projected cross occurs, a vertical line marks that projected bar as a possible timing point.
Vertical line visibility is made more consistent by using a deviation-based height (with ATR fallback) so the marker remains readable across different symbols and volatility regimes.
Projected Deviation Envelopes + Alerts (Band 3 / Band 4)
The script measures historical deviation from MA4 within the sampled window using the standard deviation of:
(close − MA4)
That deviation is then applied to the projected MA4 path to form projected envelopes:
Band 3 (Stretch): ±(StDev × 1.618 by default)
Band 4 (Invalidation): ±(StDev × 2.618 by default)
Optional alerts can trigger when price breaches these projected envelopes:
Band 3 Breach: price stretched outside the projected range
Band 4 Breach: price exceeded the larger projected boundary (often treated as invalidation context)
Alerts can be set to use wicks or close.
Table: What It Shows
The table summarizes the current state at a glance:
MA4 value
MA4[1] value
Alignment: Bullish / Bearish / Neutral
Most recent live cross event:
BUY (MA4 crossed above MA4[1])
SELL (MA4 crossed below MA4[1])
This helps confirm what you’re seeing without relying on visual estimation.
How to Use It (Simple Workflow)
Read live alignment
MA4 above MA4[1] = bullish bias
MA4 below MA4[1] = bearish bias
Enable projection for timing awareness
Turn on Projection
Watch projected cross VLines as “possible next inflection timing” markers
Use Band 3 / Band 4 as context
Band 3 breach can indicate stretch vs the projected path
Band 4 breach can indicate the projected path is less reliable (invalidation context)
Use the table for quick confirmation
It summarizes alignment and the latest live cross state.
MA4 (a 4-period moving average) represents the current short-term mean of price.
MA4[1] is the prior value of that same moving average, used as a 1-bar delayed reference.
From those two series, the script provides four layers of information:
Live alignment (MA4 vs MA4[1])
A forward projection of a sampled historical MA pattern
Projected cross markers (vertical lines) when the projected MA4 would cross projected MA4[1]
A compact table summarizing current alignment and the most recent live cross event
This is designed to help traders visualize:
whether short-term mean behavior is strengthening or weakening, and
where a future cross could plausibly occur if a selected historical pattern repeats.
This script is informational only and does not place trades.
Chart Setup Note (Important)
Because this tool samples a historical pattern window and projects it forward, it is important to let the chart fully load/merge historical data before interpreting the projection.
If the chart history is not fully loaded, the sampled window may be incomplete, which can shift the projection and projected cross markers.
Once the chart is fully merged, the projection remains stable and consistent during scrolling and replay.
What Makes It Different
This is not a basic “MA crossover” indicator. The core differentiator is:
The script extracts a historical MA4 pattern from a user-defined window,
shifts it forward into the future, and
marks projected future crosses between the projected MA4 and projected MA4[1].
It also builds projected deviation envelopes from the sampled window and uses those envelopes for optional stretch/invalidation alerts.
How the Projection Works (Concept)
1) Sample a historical MA “pattern window”
You define a window in the past using:
Pattern Start (bars back)
Pattern End (bars back)
The script collects MA4 values across that window into an internal pattern array.
2) Shift the pattern forward
Shift Pattern Forward (bars) controls how far into the future the sampled pattern is plotted.
3) Delta-anchor projection (optional)
If Delta-anchor projection is enabled, the script projects the shape of the pattern while re-centering it around the current MA4 level.
This keeps the projection visually relevant to current price scale instead of “pasting” old absolute values.
Projected Cross Vertical Lines
When projection is enabled, the script checks for projected cross events:
Bull projected cross: projected MA4 rises through projected MA4[1]
Bear projected cross: projected MA4 falls through projected MA4[1]
When a projected cross occurs, a vertical line marks that projected bar as a possible timing point.
Vertical line visibility is made more consistent by using a deviation-based height (with ATR fallback) so the marker remains readable across different symbols and volatility regimes.
Projected Deviation Envelopes + Alerts (Band 3 / Band 4)
The script measures historical deviation from MA4 within the sampled window using the standard deviation of:
(close − MA4)
That deviation is then applied to the projected MA4 path to form projected envelopes:
Band 3 (Stretch): ±(StDev × 1.618 by default)
Band 4 (Invalidation): ±(StDev × 2.618 by default)
Optional alerts can trigger when price breaches these projected envelopes:
Band 3 Breach: price stretched outside the projected range
Band 4 Breach: price exceeded the larger projected boundary (often treated as invalidation context)
Alerts can be set to use wicks or close.
Table: What It Shows
The table summarizes the current state at a glance:
MA4 value
MA4[1] value
Alignment: Bullish / Bearish / Neutral
Most recent live cross event:
BUY (MA4 crossed above MA4[1])
SELL (MA4 crossed below MA4[1])
This helps confirm what you’re seeing without relying on visual estimation.
How to Use It (Simple Workflow)
Read live alignment
MA4 above MA4[1] = bullish bias
MA4 below MA4[1] = bearish bias
Enable projection for timing awareness
Turn on Projection
Watch projected cross VLines as “possible next inflection timing” markers
Use Band 3 / Band 4 as context
Band 3 breach can indicate stretch vs the projected path
Band 4 breach can indicate the projected path is less reliable (invalidation context)
Use the table for quick confirmation
It summarizes alignment and the latest live cross state.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.