OPEN-SOURCE SCRIPT
AetherEdge - Contrastive Similarity Engine

🖊️ Overview
The Contrastive Learning Similarity Engine is a pattern-matching engine inspired by the principles of contrastive learning (SimCLR). It encodes the current market state into a feature embedding, contrasts it against every past window via cosine similarity, and surfaces the closest historical analogue. When a high-similarity pattern is found, it overlays that analogue's subsequent price action onto the present as a translucent Ghost Chart — "last time this shape appeared, price did this."
🔶 Key Features
SimCLR-inspired contrastive similarity space: shape-based cosine matching
Adaptive feature weights: a contrastive adaptation that online-learns which features proved predictive
Top-K matching: extracts the several closest historical analogues
Ghost Chart overlay: projects the analogue's "what happened next," anchored at current price
Ghost-all-top-K: overlays multiple historical outcomes as a fan distribution
Match-origin marker: shows where in history the analogue occurred
Match-accuracy tracking: learns and displays how often high-similarity projections were correct
Exploratory palettes (Spectral Scan et al.) with an integrated HUD
🧠 Technical Architecture
This tool is a translation that realizes SimCLR's core idea within Pine, which has neither autodiff nor deep nets. The encoder converts a price window into successive log returns, then mean-removes and L2-normalizes them into a shape vector (capturing form, not absolute price, so it's level-independent). Matching computes the weighted cosine similarity between the current vector and every past window, extracting the best match and Top-K.
The contrastive learning layer checks, after an outcome horizon, whether the direction a high-similarity match projected was actually correct, then reinforces (pulling positives together) or attenuates (pushing misleading ones apart) the feature weights — an online realization of SimCLR's contrastive adaptation. Because compute is O(search depth × window length), it runs only on the last bar to avoid Pine's loop limit. The Ghost Chart applies the matched analogue's subsequent cumulative return to the current price, drawing it forward as translucent lines.
⚙️ Recommended Settings & Tuning Guide
Tuned with crypto in mind. Pattern Window 20 and Search Depth ~400 are a starting point. Min Similarity sets match strictness — 0.80+ accepts only strong matches with closely-aligned shapes. For short-term patterns use Pattern Window near 10; for larger structures near 40. Raising Search Depth explores richer history but is heavier — reduce it if slow. Enabling Ghost All Top-K reveals the spread of multiple historical outcomes rather than a single one.
💡 How to Use in Practice
The Ghost Chart visualizes how past analogous situations resolved, serving as a hypothesis for how the current pattern might resolve. When multiple Top-K ghosts converge in one direction, conviction in that direction is relatively higher; when they fan out widely, the same shape historically led to diverse outcomes — read as hard to predict. If the HUD's match accuracy stably exceeds 50%, it suggests pattern repetition carries predictive power on this instrument and timeframe. Overlaying with other structure tools and support/resistance, and favoring moments where the ghost's direction agrees with other evidence, is effective.
⚠️ Important Notes
This tool is SimCLR-inspired, not a true backprop-trained contrastive network; within Pine's constraints it reproduces the core idea in a feasible form. The Ghost Chart is a replay of past analogues, not a prediction — there is no guarantee the same shape leads to the same outcome. Matching runs only on the last bar and does not repaint confirmed history. Learning the feature weights requires accumulated data and cannot overcome the fundamental constraint of market predictability. Excessively large Search Depth may approach the runtime limit.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No match or ghost guarantees future prices, and past performance does not indicate future results. All trading decisions are made at your own risk.
The Contrastive Learning Similarity Engine is a pattern-matching engine inspired by the principles of contrastive learning (SimCLR). It encodes the current market state into a feature embedding, contrasts it against every past window via cosine similarity, and surfaces the closest historical analogue. When a high-similarity pattern is found, it overlays that analogue's subsequent price action onto the present as a translucent Ghost Chart — "last time this shape appeared, price did this."
🔶 Key Features
SimCLR-inspired contrastive similarity space: shape-based cosine matching
Adaptive feature weights: a contrastive adaptation that online-learns which features proved predictive
Top-K matching: extracts the several closest historical analogues
Ghost Chart overlay: projects the analogue's "what happened next," anchored at current price
Ghost-all-top-K: overlays multiple historical outcomes as a fan distribution
Match-origin marker: shows where in history the analogue occurred
Match-accuracy tracking: learns and displays how often high-similarity projections were correct
Exploratory palettes (Spectral Scan et al.) with an integrated HUD
🧠 Technical Architecture
This tool is a translation that realizes SimCLR's core idea within Pine, which has neither autodiff nor deep nets. The encoder converts a price window into successive log returns, then mean-removes and L2-normalizes them into a shape vector (capturing form, not absolute price, so it's level-independent). Matching computes the weighted cosine similarity between the current vector and every past window, extracting the best match and Top-K.
The contrastive learning layer checks, after an outcome horizon, whether the direction a high-similarity match projected was actually correct, then reinforces (pulling positives together) or attenuates (pushing misleading ones apart) the feature weights — an online realization of SimCLR's contrastive adaptation. Because compute is O(search depth × window length), it runs only on the last bar to avoid Pine's loop limit. The Ghost Chart applies the matched analogue's subsequent cumulative return to the current price, drawing it forward as translucent lines.
⚙️ Recommended Settings & Tuning Guide
Tuned with crypto in mind. Pattern Window 20 and Search Depth ~400 are a starting point. Min Similarity sets match strictness — 0.80+ accepts only strong matches with closely-aligned shapes. For short-term patterns use Pattern Window near 10; for larger structures near 40. Raising Search Depth explores richer history but is heavier — reduce it if slow. Enabling Ghost All Top-K reveals the spread of multiple historical outcomes rather than a single one.
💡 How to Use in Practice
The Ghost Chart visualizes how past analogous situations resolved, serving as a hypothesis for how the current pattern might resolve. When multiple Top-K ghosts converge in one direction, conviction in that direction is relatively higher; when they fan out widely, the same shape historically led to diverse outcomes — read as hard to predict. If the HUD's match accuracy stably exceeds 50%, it suggests pattern repetition carries predictive power on this instrument and timeframe. Overlaying with other structure tools and support/resistance, and favoring moments where the ghost's direction agrees with other evidence, is effective.
⚠️ Important Notes
This tool is SimCLR-inspired, not a true backprop-trained contrastive network; within Pine's constraints it reproduces the core idea in a feasible form. The Ghost Chart is a replay of past analogues, not a prediction — there is no guarantee the same shape leads to the same outcome. Matching runs only on the last bar and does not repaint confirmed history. Learning the feature weights requires accumulated data and cannot overcome the fundamental constraint of market predictability. Excessively large Search Depth may approach the runtime limit.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No match or ghost guarantees future prices, and past performance does not indicate future results. All trading decisions are made at your own risk.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.