Triangle Breakout Strategy with TP/SL, EMA Filter

✅ 1. Pattern Detection – Triangle Breakout
The script scans for triangle patterns by detecting local pivot highs and pivot lows.
It uses two recent highs and two recent lows to draw converging trendlines (upper and lower boundaries of the triangle).
If the price breaks above the upper trendline, a bullish breakout signal is generated.
🎯 2. TP (Take Profit) & SL (Stop Loss)
When a bullish breakout is detected:
A buy order is placed using strategy.entry.
TP and SL levels are calculated relative to the current close price:
TP = 3% above the entry price
SL = 1.5% below the entry price
These are defined using strategy.exit.
📊 3. EMA Filter
An optional filter checks if:
Price is above both EMA 20 and EMA 50
Only if this condition is met, the strategy allows a long entry.
You can toggle the filter on or off with useEMAFilter.
📈 4. Backtesting with Strategy Tester
This script uses strategy() instead of indicator() to enable TradingView’s built-in backtest engine.
Every buy entry and exit (based on TP or SL) is recorded.
📌 5. Visuals
EMA 20 and EMA 50 lines are plotted on the chart.
A label is shown when a breakout is detected: "Breakout Up"
Results (profit, win rate, drawdown, etc.) can be viewed in the Strategy Tester panel.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.