Supertrend adapted to strategy
Apr 18, 2020

The Supertrend adapted to strategy indicator provides a comprehensive backtesting framework for the classic Supertrend trend-following logic, featuring advanced exit mechanisms such as trailing stop losses and profit triggers.
Usage
This tool can be used to identify trend direction and test the viability of Supertrend-based strategies across various assets and timeframes. Users can execute long or short positions based on the crossover of price and the Supertrend line.
The strategy incorporates two main exit layers:
- Initial Stop Loss: A fixed percentage stop loss that protects the position immediately after entry.
- Trailing Take Profit: A dynamic exit system that activates once a specific price trigger is reached. Once active, the tool trails the price at a set percentage, allowing for profit maximization during extended trends.
Details
The script is based on the original Supertrend calculation by KivancOzbilgic, utilizing the Average True Range (ATR) to determine volatility-adjusted trend lines. It offers the flexibility to choose between the standard ATR calculation and a Simple Moving Average (SMA) of the True Range.
The strategy logic is designed to handle position states strictly, ensuring that "TP" (Take Profit) and "Close" signals are clearly visualized on the chart. It also includes a time filter, allowing users to backtest specific date ranges to avoid periods of abnormal market volatility.
Settings
Date Range
- From/To Day, Month, Year: Defines the specific period for strategy execution and backtesting.
Risk Management
- Use stop Loss for buy/sell entries: Toggles the initial fixed percentage stop loss.
- Stop Loss value for entries (%): Sets the percentage distance for the initial stop loss.
- Use take profit for buy/sell entries: Enables the trailing profit-taking logic.
- SL Trigger candle (%): The percentage price movement required to activate the trailing stop mechanism.
- Stop Loss for trail candle entries (%): The percentage distance used for trailing the price once the trigger is hit.
Supertrend Parameters
- ATR Period: The lookback period used for ATR calculations.
- Source: The price input used for calculations (default is HL2).
- ATR Multiplier: The factor applied to the ATR to determine the distance of the Supertrend line.
- Change ATR Calculation Method: Switches between ta.atr() and an SMA-based calculation.
- Show Buy/Sell Signals / Highlighter: Visual toggles for signals and trend background coloring.
FAQ
How do I use the trailing profit feature?
Enable "Use take profit" and set an "SL Trigger candle (%)". Once the price moves in your favor by that percentage, a neutral-colored trigger line will appear, and the strategy will begin trailing your profit using the "Stop Loss for trail candle entries (%)" value.
Can I change the sensitivity of the trend detection?
Yes, by adjusting the ATR Period and ATR Multiplier. A lower period or multiplier will make the indicator more sensitive to price changes, while higher values will result in a smoother, slower trend line.
How can I access Supertrend adapted to strategy?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.