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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.