OPEN-SOURCE SCRIPT

Refined Supertrend ATR + TSL + Filters [Nifty/BankNifty] V2

1 198
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.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。