OPEN-SOURCE SCRIPT
Updated

Supertrend Trading

2 462
✨ Supertrend Trading by Mars ✨

This indicator is an extension to the popular Supertrend indicator, adding trading information (long only) and a built-in backtest feature that helps you find the best stocks to trade using the Supertrend strategy.

Core Features
  • Clear entry signals (🟢) when trend turns bullish (with alert)
  • Clear exit signals (🔴) when trend reverses or stop loss is hit (with alert)
  • Built-in statistics table showing win rate, profit factor, and more
  • Risk:Reward visualization with target levels
  • Stop loss guidance with distance percentage
  • Active trade tracking with current P/L


How It Works
This indicator uses standard Supertrend calculation (ATR-based) to determine trend direction, but adds entry and exit rules with visual markers:

Entry Rules:
  • Enter long when Supertrend flips from bearish to bullish (red to green)
  • Entry marked with green circle (🟢)


Exit Rules:
  • Exit when Supertrend flips from bullish to bearish
  • Exit when price touches/crosses below the Supertrend line during uptrend
  • Exit when price gaps down below stop loss level
  • Exit marked with red circle (🔴)


Finding The Best Stocks
The built-in statistics table helps identify which stocks work best with the Supertrend strategy:

  • Look for win rates above 50%
  • Target profit factors above 2.0
  • Check for reasonable drawdowns (under 15-20%)
  • Review the automatic performance rating (Strong ✨, Good ✅, Mixed 📋, Poor ⚠️)
  • The ATR multiple used will significantly impact the trades performance, try 1.5, 2 or 3.


Risk Management Tools
The indicator provides multiple risk management features:

  • Stop loss line with percentage distance
  • R-multiple levels to visualize potential reward (1R, 2R, 3R)
  • Maximum drawdown tracking
  • Current position status with P/L percentage


Statistics Table
The backtest results display key metrics:
  • Total trades and win rate
  • Average win/loss percentages
  • Profit factor (total gains divided by total losses)
  • Maximum drawdown during trades
  • Average days held per trade


Usage Tips
  • Apply to multiple timeframes (daily/weekly recommended)
  • Compare backtest results across different stocks/instruments
  • Use R-multiple levels to set realistic profit targets
  • The statistics table helps identify which market environments work best
  • Default settings (10, 1.5) should work well for daily charts


This indicator provides a complete trading system based on Supertrend - from entry to exit, with performance tracking. The backtest feature lets you quickly test different stocks to find those that respond best to Supertrend strategy.

I welcome your feedback and suggestions!
Release Notes
included max_bars_back to prevent error
Release Notes
Days -> Periods since this works on multiple time frames

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.