## Super trend indicator construction

I’ve been doing more research into the super trend indicator construction and I think I finally understand exactly how it works. It’s basically an ATR trailing stop indicator. The two inputs for the indicator are number of periods and a multiplier. The number of periods lets call it (N) is used to get the ATR. So ATR(N). The default setting is 10. So N=10. It can be whatever value you want it to be but I think the most commonly used settings for ATR are 10 and 14.

The multiplier is simply a number greater than zero. The multiplier lets call it (M) is multiplied by the ATR(N) value which gives us a stop distance. This stop distance is then either added or subtracted (depending if up trend or down trend) from the median (mid) price. The median price is calculated by (high+low)/2.

Below is the code that can be used to program the indicator in proRealTime. I have put line numbers against each line of the code and will explain (or least attempt to explain) what is happening on each line of code.

Line No. Explination
1 make a = ATR for number of periods based on the close price
2 make b = the multiplier value passed in by the user
3 if we are looking at the first bar (bar = 1) of the chart. So this would be the first entry we have in our chart. Then do the following:
4 Set T=1 (T is how we are defining our trend, T=1 is an uptrend, T=-1 is a down trend
5 Set L1 = low of the first bar on the chart
6 Set H1 = high of the first bar on the chart
7 if we are not looking at the first bar
8 if T (the previous value for the trend) is 1 (so an uptrend)
9 if the close for the current bar is greater than, L1 (the previous value for L1)
10 set L1 to be the maximum value of the previous L1 value and the median price minus our ATR value
11 make ST equal to the new L1 value
12 if the close is less than or equal to L1 (the previous value for L1)
13 make H1 = median price plus our ATR value
14 make ST equal the new H1 value
15 Set T=-1 switching from up trend to down trend
16 ends the if statement started on line 9
17 Else if T is not equal to 1 (so -1 or downtrend)
18 if the close is less than H1 (the previous value for H1)
19 set H1 to be the minimum value of the previous H1 value and the median price plus our ATR value
20 make ST equal to the new H1 value
21 else if close is greater than or equal to the H1(the previous value for H1)
22 make L1 = median price minus our ATR value
23 make ST equal to the new L1 value
24 set T =1 switching from downtrend to uptrend
25 ends the if statement started on line 18
26 ends the if statement started on line 8
27 ends the if statement started on line 3
28 Return the value of ST (Super Trend)

Below is the same super trend indicator code if you want to copy and paste it.

a = AverageTrueRange[periods](close)
b = Multiplier

if barindex < 2 then     T = 1     L1 = low     H1 = high Else     if T = 1 then        if close > L1 then
L1 = MAX(L1,medianprice - a*b)
ST = L1
Else
H1 = medianprice + a*b
ST = H1
T = -1
Endif
Else
if close < H1 then           H1 = MIN(H1,medianprice + a*b)           ST = H1        Else           L1 = medianprice - a* b           ST = L1           T = 1        endif     endif Endif Return ST

If you have any comments or feedback please post them on the forum