OPEN-SOURCE SCRIPT
Pattern Match & Forward Projection – Weekly (EN)

Overview
This indicator searches for recurring price patterns in weekly data and projects their average forward performance.
The logic is based on historical pattern repetition: it scans past price sequences similar to the most recent one, then aggregates their forward returns to estimate potential outcomes.
⚠️ Important: The indicator is designed for weekly timeframe only. Using it on daily or intraday charts will trigger an error message.
Settings (Inputs)
Pattern Settings
Pattern length (weeks): Number of weeks used to define the reference pattern.
Forward length (weeks): Number of weeks into the future to evaluate after each pattern match.
Lookback (weeks): Historical window to scan for past pattern matches.
Normalize by shape (z-score): If enabled, patterns are normalized by z-score, focusing on shape similarity rather than absolute values.
Distance threshold (Euclidean): Maximum allowed Euclidean distance between the reference pattern and historical candidates. Smaller values = stricter matching.
Min. required matches: Minimum number of valid matches needed for analysis.
Quality Filters
Min required Hit%: Minimum percentage of positive outcomes (upside forward returns) required for the pattern to be considered valid.
Return filter mode:
Either: absolute average return ≥ threshold
Long only: average return ≥ threshold
Short only: average return ≤ -threshold
Min avg return (%): Minimum average forward return threshold for validation.
Visual Options
Highlight historical matches (labels): Marks where in history similar patterns occurred.
Max match labels to draw: Caps the number of match markers shown to avoid clutter.
Draw average projection: Displays the average projected forward curve if conditions are met.
Show summary panel: Enables/disables the information panel.
Show weekly avg curve in panel: Adds a breakdown of average returns week by week.
Projection color: Choose the color of the projected forward curve.
What the Screen Shows
Summary Panel (top-left by default)
Total matches found in history
Matches with valid forward data
Average, minimum, and maximum distance (similarity measure)
Average forward return and Hit%
Distance threshold and normalization setting
Weekly average forward curve (if enabled)
Quality filter results (pass/fail)
Projection Curve (dotted line on price chart)
Drawn only if enough valid matches are found and filters are satisfied
Represents the average forward performance of historical matches, anchored at the current bar
Historical Match Labels (▲ markers)
Small arrows below past bars where similar patterns occurred
Tooltip: “Historical match”
Forecast Logic
The indicator does not predict the future in a deterministic way.
Instead, it relies on a pattern-matching algorithm:
The most recent N weeks (defined by Pattern length) are taken as the reference.
The algorithm scans the last Lookback (weeks) for segments with similar shape and magnitude.
Similarity is measured using Euclidean distance (optionally z-score normalized).
For each valid match, the subsequent Forward length weeks are collected.
These forward paths are averaged to generate a composite forward projection.
The summary panel reports whether the current setup passes the quality filters (Hit% and minimum average return).
Usage Notes
Best used as a contextual tool, not a standalone trading system.
Works only on weekly timeframe.
Quality filters help distinguish between noisy and statistically meaningful patterns.
A higher number of matches usually improves reliability, but very strict thresholds may reduce sample size.
📊 This tool is useful for traders who want to evaluate how similar historical setups have behaved and to visualize potential forward paths in a statistically aggregated way.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.