OPEN-SOURCE SCRIPT
Refined Supertrend ATR + TSL + Filters [Nifty/BankNifty] V2

This is a trend-following strategy built for Nifty 50 and Bank Nifty (and similar Indian index futures/options), designed to capture strong trending moves while using multiple layers of risk management.
Core Idea
It uses the Supertrend indicator as the primary trend detection and trailing mechanism, enhanced with:
Trend confirmation filters
Multi-level profit taking
Dynamic trailing stop (TSL)
Breakeven protection
Entry Rules
Long Entry:
Price crosses above the Supertrend line
Optional Filters:
Price is above 200 EMA (if enabled)
ADX > 20 (trend strength filter, if enabled)
Trade only during Indian market hours (9:15–15:30 IST) if session filter is on
Longs disabled if "Short Only" mode is active
Short Entry:
Price crosses below the Supertrend line
Same filters as above (price below 200 EMA + ADX > 20)
Shorts disabled if "Long Only" mode is active
Exit Rules (Risk Management)
The strategy uses a hybrid exit system:
Multi-Level Take Profit (Partial Scaling Out)
40% of position closed at 1.5 × ATR profit
30% of position closed at 3.0 × ATR profit
30% of position closed at 5.0 × ATR profit
Trailing Stop (Dynamic)
Supertrend line acts as the base trailing stop
Extra ATR Trailing Stop (custom TSL): Tightens the stop to Close - 2.0 × ATR (default) as price moves in favor
The stop is the higher of Supertrend and the custom ATR TSL (for longs)
Breakeven
Once price reaches 1.5 × ATR in profit, the stop moves to entry price (locks in breakeven)
This combination allows the strategy to:
Book partial profits early
Let winners run with a trailing stop
Protect capital with breakeven
Key Settings & Filters
Feature Default Purpose Supertrend ATR Length10 Sensitivity of trend Supertrend Factor 3.0 Distance of band200 EMA Filter Enabled Trade only in direction of major trend ADX Filter Enabled Avoid choppy/sideways markets Extra ATR TSL2.0Tight trailing stopBreakeven1.5 ATR Move to breakeven Position Size10% equity Risk per trade Commission0.04% Realistic for Indian brokers
Visual Elements
Green/Red Supertrend line (main trend indicator)
Orange 200 EMA
Purple ADX in separate pane
Background coloring (light green/red) when both Supertrend + EMA agree
Entry labels ("LONG"/"SHORT")
Best Use Case
Nifty 50 & Bank Nifty futures/options
Trending market conditions (works poorly in sideways/choppy markets — hence the ADX filter)
Intraday or short swing trades
Works on 5-minute to 15-minute timeframes typically.
Core Idea
It uses the Supertrend indicator as the primary trend detection and trailing mechanism, enhanced with:
Trend confirmation filters
Multi-level profit taking
Dynamic trailing stop (TSL)
Breakeven protection
Entry Rules
Long Entry:
Price crosses above the Supertrend line
Optional Filters:
Price is above 200 EMA (if enabled)
ADX > 20 (trend strength filter, if enabled)
Trade only during Indian market hours (9:15–15:30 IST) if session filter is on
Longs disabled if "Short Only" mode is active
Short Entry:
Price crosses below the Supertrend line
Same filters as above (price below 200 EMA + ADX > 20)
Shorts disabled if "Long Only" mode is active
Exit Rules (Risk Management)
The strategy uses a hybrid exit system:
Multi-Level Take Profit (Partial Scaling Out)
40% of position closed at 1.5 × ATR profit
30% of position closed at 3.0 × ATR profit
30% of position closed at 5.0 × ATR profit
Trailing Stop (Dynamic)
Supertrend line acts as the base trailing stop
Extra ATR Trailing Stop (custom TSL): Tightens the stop to Close - 2.0 × ATR (default) as price moves in favor
The stop is the higher of Supertrend and the custom ATR TSL (for longs)
Breakeven
Once price reaches 1.5 × ATR in profit, the stop moves to entry price (locks in breakeven)
This combination allows the strategy to:
Book partial profits early
Let winners run with a trailing stop
Protect capital with breakeven
Key Settings & Filters
Feature Default Purpose Supertrend ATR Length10 Sensitivity of trend Supertrend Factor 3.0 Distance of band200 EMA Filter Enabled Trade only in direction of major trend ADX Filter Enabled Avoid choppy/sideways markets Extra ATR TSL2.0Tight trailing stopBreakeven1.5 ATR Move to breakeven Position Size10% equity Risk per trade Commission0.04% Realistic for Indian brokers
Visual Elements
Green/Red Supertrend line (main trend indicator)
Orange 200 EMA
Purple ADX in separate pane
Background coloring (light green/red) when both Supertrend + EMA agree
Entry labels ("LONG"/"SHORT")
Best Use Case
Nifty 50 & Bank Nifty futures/options
Trending market conditions (works poorly in sideways/choppy markets — hence the ADX filter)
Intraday or short swing trades
Works on 5-minute to 15-minute timeframes typically.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。