I get the error StopDot does not exist in the current context, also one for UpTrend when I add this to the code. I added private double lastStopValue to the variables and what you said into the Initialize block. Am I missing something?
I've been reading through the forums for three hours now, so if I've made a stupid mistake, please keep your flamethrower setting to "gentle".
I've recently been exploring SuperTrend indicators. The most popular one is probably this one ... the anaSuperTrendU11 indicator. However, I've also been playing with an older one, called TSSuperTrend v 2.4. I've fiddled around with both, but I've actually been happier with the TSSuperTrend version. Now, my intent here is not to start a food fight. In fact, I'd rather stick with newer versions of an indicator. So I've been trying to replicate the results I get from TSSuperTrend v 2.4, using FatTails' anaSuperTrendU11. But I haven't been successful.
So, here are my hopefully not-too-repetitive questions:
(1) Are anaSuperTrendU11 and TSSuperTrend v 2.4 different implementations of the same base algorithm, with different features and flexibility - or are they fundamentally different trend indicators?
(2) FatTails' anaSuperTrendU11 indicator seems to have more flexibility. How can I configure it to replicate the results from TSSuperTrend v 2.4 (on its default parameter values, say)?
(3) My intent is to use these trend indicators in an automated strategy. Which of the DataSeries/BoolSeries are the key ones to refer to, to expose trend direction? I'm a software developer, so I'm pretty comfortable fiddling with C# code.
@pbailey19: Let me summarize some of the key differences between the TSSuperTrend and anaSuperTrendU11.
The SuperTrend indicator is basically derived from a moving average and a measure for volatility. The calculation of the stop line is done in two steps: First you calculate the value of a moving average. Then in a second step a multiple of the average true range is subtracted (uptrend) or added (downtrend). That is about all.
Originally such indicators were created to be used with daily data. Traders waited to receive the printed charts, then performed calculations. They never calculated indicator values for broken days. With modern charting programs available you can now calculate indicator values for unstable bars. Many users love to set their indicators to CalculateOnBarClose = false, and that is where the problem starts
(1) first this leads to false values for some indicators
(2) second this increases CPU load
Let us have a look at the ATR. It takes its prior value and the true range of the current bar. Unfortunately, the true range of a new bar is close to zero, which means that the ATR always increases during the life of a bar. The ATR is therefore one of the indicators, which should never be used with setting CalculateOnBarClose = false. Applied to the TSSuperTrend used in COBC = false this means that the stopline contracts when a new bar prints and then gradually expands as the range of the new bar develops. I do not think that this behavior is useful, and therefore the indicator uses the ATR one bar ago. Another advantage of this solution is that the ATR of the last bar only needs to be calculated once with the first tick of each bar. It also reduces the CPU load.
The same applies to the moving averages or median. Some of them use a complex algorithm, and it is unnecessary to recalculate the moving average with every incoming tick. If you think about it, Bollinger Bands are even worse. When price moves up, the moving average moves up as well, and the standard deviation increases during the life of the bar. Therefore, when price approaches the upper Bollinger Band, the Bollinger Band has already moved away, and price has to catch up. The whole thing reminds me the paradox of Achilles and the Tortoise...
The whole behavior can be avoided by simply calculating both moving average and average true range one bar ago. For this reason the indicator is called anaSuperTrendU11 - 1 bar ago for the SMA and 1 bar ago for the ATR.
This is the main difference between the anaSuperTrendU11 and the TSSuperTrend. Other differences are:
- anaSuperTrend shows dots + connectors, while TSSuperTrend shows line
- anaSuperTrend shows where the stopline is touched
- both indicators have a paintbar options, but only the TSSuperTrend has background flooding
- anaSuperTrendU11 works with 29 different moving averages, TSSuperTrend with 11
- anaSuperTrendU11 can calculate volatility from true range, simple range and standard deviation, while TSSuperTrend uses average true range, dual thurst or adaptive
- anaSuperTrendU11 can be set to change direction intra-bar (this setting is independent from the COBC setting, that is it can also be used within a strategy that is set to COBC = true)
- anaSuperTrend exposes the trend information as BoolSeries (good for use with automated strategies, but cannot be used with Strategy Builder and Market Analyzer), while TSSuperTrend exposes the trend information as DataSeries (good for Strategy Builder and Market Analyzer)
But now to your question. The chart attached shows the TSSuperTrend with the following settings:
SuperTrend mode = ATR
Period for ATR = 10
Multiplier = 1.5
Moving average type = EMA
Period for EMA = 3
Now let us translate this to the anaSuperTrendU11. The anaSuperTrendU11 does not have the original ATR inbuilt. The ATR uses Wilder's smoothing. With a period of 10, Wilder's average uses a smoothing constant of 1/N = 1/10. A modern EMA has a smoothing constant of 2/(N+1), therefore you have to select a period of N = 19 for the EMA to obtain the ATR(10) or otherwise put
ATR(10) = EMA( TrueRange, 19)
Also remember that the anaSuperTrendU11 does not take into account the current bar, therefore we would use an EMA(TrueRange, 18) to come as close to the TSSuperTrend. In a similar fashion, we would use the EMA(2) one bar ago to get an approximation of the EMA(3) calculated by the TSSuperTrend. This results in the following settings:
Baseline Smoothing = EMA
Offset Smoothing = EMA (to build the ATR)
Offset Type = True_Range Reverse intra-bar = false
Baseline period = 2 (reduced by 1)
Offset multiplier = 1.5
Offset period = 18 (as per calculation above)
The result is shown in the chart attached. The blue/red stoplines show the anaSuperTrendU11, the green/gold stoplines the TSSuperTrend. The behavior of both indicators is similar.
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).
The following 11 users say Thank You to Fat Tails for this post:
First of all, thank you a million times over. I could never have asked for such a rich, detailed answer, and it's everything I wanted to know. I especially appreciate your description of the fundamentals of the indicator (what it basically is), and the details of the implementation.
Ironically, I'm also trying to duplicate the SuperTrend indicator's functionality in a customized, simplified indicator, and one of the things I'm trying to do is convert it to run with CalculateOnBarClose = true. So I may be able to significantly simplify the code, now.
The following user says Thank You to pbailey19 for this post:
Good job FT, your're certainly very knowledgeable in this. You used a 15 min chart in this example. When you use smaller timeframe, how do the settings change? For example if you're to use a 6 Range chart in that example, what would be your settings for anaSupperTrend for:
Baseline period ...
Offset multiplier ...
Offset period ....
One of the properties of the SuperTrend is that it autoadjusts to volatility. When volatility rises the stops will be wider, while stops will be narrower after volatility has declined. This adjustment to volatility is achieved via the average true range, which is a measure for volatility, if you use it with minute charts.
If you apply the indicator to range bars, the average true range will be constant most of the time, as it only reflects the selected range. Therefore the indicator can no longer adjust to volatility when used with range bars. It becomes a different animal and works more like a fixed channel.
I have never used this indicator with range bars.
The following 2 users say Thank You to Fat Tails for this post:
WOW! I value that response so much. In other words this indicator only works as originally intended when used with time-based charts. Tick charts and range charts will give results and they may be good results but they are not the original purpose of the indicator. I hope those using the indicator will take note of that. Thanks FT.
Last edited by master trader; May 19th, 2015 at 03:14 PM.
The following 2 users say Thank You to master trader for this post: