Trendline Break & Retest Strategy + Filters

The script looks for pivot points:
A swing high is when a high is higher than surrounding candles.
A swing low is when a low is lower than surrounding candles.
These points act as anchor points for trendlines.
2. Simulated Trendlines
Since Pine Script can’t draw truly dynamic trendlines, it mathematically simulates:
A downward resistance trendline from the last swing high.
An upward support trendline from the last swing low.
These lines estimate where resistance or support would exist if you were manually drawing trendlines.
3. Breakout Detection
The strategy checks:
If price breaks above the resistance trendline (bullish breakout).
If price breaks below the support trendline (bearish breakout).
It looks for a clean break with candle close beyond the line, not just a wick.
4. Retest Confirmation
To avoid chasing breakouts, the strategy waits for a retest:
After a breakout, price must come back close to the broken trendline (within a % tolerance).
This simulates the classic "break → retest → go" pattern.
Only after a valid retest will the strategy consider entering.
5. Technical Filters (for Better Accuracy)
Once a valid breakout + retest is detected, the strategy applies filters:
✅ RSI Filter
Go long only if RSI > 50 (bullish momentum).
Go short only if RSI < 50 (bearish momentum).
✅ Volume Filter
Only enter trades when current volume is greater than the 20-period average, ensuring market participation.
✅ EMA Trend Filter
Long trades only if price is above the 50 EMA (uptrend).
Short trades only if price is below the 50 EMA (downtrend).
This avoids going against the dominant trend.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.