OPEN-SOURCE SCRIPT
DTW Template Tracker [forexobroker]

DTW Template Tracker uses simplified Dynamic Time Warping with a Sakoe-Chiba band (width 2) to align recent z-scored closes against monotone bull (linear rise) and bear (linear fall) templates. DTW allows time stretching that cosine similarity does not. Lower distance = closer match; signal fires when one template's distance is materially lower than the other and below an absolute threshold.
🔶 ALGORITHM
1. Z-score the recent N closes using rolling mean and stdev.
2. Build templates: bull = linspace(-1, +1) over N points; bear = -bull.
3. DTW with Sakoe-Chiba band W = 2: cost matrix D[i,j] is filled only within |i - j| <= W. D[i,j] = |x - t[j]| + min(D[i-1,j-1], D[i-1,j], D[i,j-1]).
4. Bull and bear distances = D[N-1, N-1] under each template.
5. Match when one distance < other AND <= threshold.
🔶 SIGNAL LOGIC
- Buy: bull match edge AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: bear match edge.
- Position-lock state machine.
🔶 INPUTS
- Template Length (default 15)
- DTW Distance Threshold (default 2.0)
- Cooldown Bars (default 4)
- Visual: dashboard, glow (flag with "match"), template overlay, buy / sell colors
🔶 ALERTS
DTT Buy, DTT Sell, DTT Any Signal, DTT Bull Match, DTT Bear Match, DTT Bull Tight, DTT Bear Tight, DTT Strong, DTT Webhook JSON.
🔶 LIMITATIONS
- DTW cost grows ~ N * W per bar; defaults (N = 15, W = 2) keep compute reasonable. Larger N exceeds Pine compute budget.
- Sakoe-Chiba band W = 2 limits stretch to +/- 2 bars; useful for 1:1 matching with minor jitter.
- Monotone templates only — V-shaped or W-shaped patterns require additional template definitions.
- Z-scoring removes scale; the indicator is invariant to absolute price level.
🔶 ALGORITHM
1. Z-score the recent N closes using rolling mean and stdev.
2. Build templates: bull = linspace(-1, +1) over N points; bear = -bull.
3. DTW with Sakoe-Chiba band W = 2: cost matrix D[i,j] is filled only within |i - j| <= W. D[i,j] = |x - t[j]| + min(D[i-1,j-1], D[i-1,j], D[i,j-1]).
4. Bull and bear distances = D[N-1, N-1] under each template.
5. Match when one distance < other AND <= threshold.
🔶 SIGNAL LOGIC
- Buy: bull match edge AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: bear match edge.
- Position-lock state machine.
🔶 INPUTS
- Template Length (default 15)
- DTW Distance Threshold (default 2.0)
- Cooldown Bars (default 4)
- Visual: dashboard, glow (flag with "match"), template overlay, buy / sell colors
🔶 ALERTS
DTT Buy, DTT Sell, DTT Any Signal, DTT Bull Match, DTT Bear Match, DTT Bull Tight, DTT Bear Tight, DTT Strong, DTT Webhook JSON.
🔶 LIMITATIONS
- DTW cost grows ~ N * W per bar; defaults (N = 15, W = 2) keep compute reasonable. Larger N exceeds Pine compute budget.
- Sakoe-Chiba band W = 2 limits stretch to +/- 2 bars; useful for 1:1 matching with minor jitter.
- Monotone templates only — V-shaped or W-shaped patterns require additional template definitions.
- Z-scoring removes scale; the indicator is invariant to absolute price level.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.