OPEN-SOURCE SCRIPT

Triangle Breakout Strategy with TP/SL, EMA Filter

317
📌 Triangle Breakout Strategy with TP/SL, EMA Filters, and Backtest – Explained.

✅ 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.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.