Essentially this is an trailing stop, of which there are several versions available (eg see the Sylvain Vervoort version programmed by H Potter). SuperTrend differs by referring the stop back from the middle of the bar (High+Low)/2. This is similar to using the Vervoort with a tweak to the number of ATR's considered. At the end of the day its a matter of preference and what works best for you.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.
//SuperTrend - Originally by Olivier Seban //Programmed by BlindFreddy //Blog: http://blindfreddy.postagon.com study(title="SuperTrend BF", overlay = true) Length = input(10, minval=1), mult = input(3, type="float",minval=1) avgTR = atr(Length) newshortband= hl2 + avgTR * mult newlongband= hl2 - avgTR * mult longband=close>longband? max(newlongband,longband) : newlongband shortband=close<shortband? min(newshortband,shortband) : newshortband trend = close > shortband ? 1: close< longband? -1: nz(trend,1) supt = trend==1? longband: shortband dotcolor = trend==1? green: maroon plot(supt, color= dotcolor , style=circles, linewidth=3,title="SuperTrend")
Good trading to all !
A couple of points when using this indicator, if you're monitoring it mid-bar you may not be seeing the final position of the dot. For instance, on weekly bars if you look at a stock that's down on say Wednesday, it may be below the green and flip up to red. However if it makes a recovery back above the green dot by Friday then it will show only the green dot. It is the closing price that is used for this indicator and that is how I personally use it - I ignore mid-bar gyrations. An example on this chart would be the May 2010 earnings release, where you see the tail hanging below the green dot. Just this week I was monitoring my position in Gilead Sciences and it did a similar move where the dot flipped over to red mid-week but finished up green. If you use this indicator for setting stop-losses and you enter the stop price in the market (rather than selling manually), you could get stopped out when you didn't intend to, although this would not happen terribly often.
Also, in my copy of the script I have changed the ">" to ">=" in line 10 and the "<" to "<=" in line 11. This makes no difference apart from the once in a blue moon occasion when a stock closes at exactly the same price as the dot.