NC SuperTrend Description
NC SuperTrend is a supertrend indicator for NinjaTrader 8, and it comes with the full C# source code. SuperTrend is hugely popular, yet there is very little magic behind it: it's an ATR trailing stop that switches sides when price closes through it. I wanted a clean version where every step is easy to see and build on. Like any trend-following tool it shines in trends; in a sideways market price crosses the line more often, so expect more flips.
How it works. On every bar it builds two bands around the median price, the middle of the bar's high and low: the median plus and minus Multiplier times the ATR, the Average True Range over Period bars. The defaults are Multiplier 3 and Period 10. When a bar closes above the previous upper band, the trend turns up; when it closes below the previous lower band, it turns down. In between, the trend stays and the line trails price: in an uptrend the lower band is held whenever it would drop, and in a downtrend the upper band is held whenever it would rise. That's why the line runs flat for a while and then steps toward price.
What you see. One line on the price chart: green below price in an uptrend, red above it in a downtrend. A lime dot marks each turn up and a red dot each turn down. A hidden Signal plot, visible in the Data Box, reads 1 after the last turn up and -1 after the last turn down (0 until the first turn), so a strategy can read the trend direction. It calculates on bar close.
How to use it. Use the line as a trailing stop or a trend filter: take longs only while it's green and shorts only while it's red, or exit when it changes color. Raise the Multiplier for wider bands, fewer flips and longer rides; lower it for faster signals. Because the distance is measured in ATR, the bands adapt to each instrument's volatility, so it works on any instrument and timeframe.
Make it yours. Like all my frameworks, it comes with a code review video that explains the logic behind the ATR trail. Use it as is, learn from the code, or change it yourself or with AI like Claude. You could add an alert when the trend flips, let your strategy enter on a change of the Signal value, or build the bands from the close or an EMA instead of the median. The whole calculation is one short method, so it's a nice first indicator to study if you're new to NinjaScript. Have some good trades!