NexusFi: Find Your Edge


Home Menu

 





How to Reveal anaSuperTrendU11 Trend Direction?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 12 posts (35 thanks)
    2. looks_two bstzgr with 11 posts (1 thanks)
    3. looks_3 master trader with 2 posts (2 thanks)
    4. looks_4 aventeren with 2 posts (8 thanks)
      Best Posters
    1. looks_one aventeren with 4 thanks per post
    2. looks_two Fat Tails with 2.9 thanks per post
    3. looks_3 master trader with 1 thanks per post
    4. looks_4 bstzgr with 0.1 thanks per post
    1. trending_up 12,227 views
    2. thumb_up 48 thanks given
    3. group 17 followers
    1. forum 31 posts
    2. attach_file 3 attachments




 
Search this Thread

How to Reveal anaSuperTrendU11 Trend Direction?

  #21 (permalink)
 bstzgr 
Memphis TN
 
Experience: Intermediate
Platform: Ninjatrader
Trading: CL
Posts: 23 since Apr 2014
Thanks Given: 7
Thanks Received: 4

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?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
 
  #22 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


bstzgr View Post
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?

You need to create an instance of the anaSuperTrendU11 before you can access the BoolSeries and DataSeries objects.

 
Code
#region Variables
......
private double multiplier = 2.618; 
private int rangePeriod = 14;
private int basePeriod = 13;
private anaSuperTrendU11BaseType thisBaseType = anaSuperTrendU11BaseType.SMA; 
private anaSuperTrendU11OffsetType thisOffsetType = anaSuperTrendU11OffsetType.SMA; 
private anaSuperTrendU11VolaType thisVolaType	= anaSuperTrendU11VolaType.True_Range; 
private Indicator.anaSuperTrendU11 STU;
private double lastStopValue;
....
#endregion

protected override void Initialize()
{
   ....
   STU = anaSuperTrendU11(basePeriod, multiplier, rangePeriod, false, thisBaseType, thisOffsetType, thisVolaType);
   Add(STU);
   ....
}

protected override void OnBarUpdate()
{
   ......
   if (CalculateOnBarClose)
   {
       if ((STU.UpTrend[0] && !STU.UpTrend[1]) || (!STU.UpTrend[0] && STU.UpTrend[1]))
         lastStopValue = STU.StopDot[0]
   }
   ....
}



I had simplified the code as I thought that you would be able to modify it as needed.

Reply With Quote
  #23 (permalink)
 bstzgr 
Memphis TN
 
Experience: Intermediate
Platform: Ninjatrader
Trading: CL
Posts: 23 since Apr 2014
Thanks Given: 7
Thanks Received: 4


Sincerely, thank you for all of your help @FatTails. I would not have been able to do what I wanted without your help.

Reply With Quote
  #24 (permalink)
 pbailey19 
Denver, CO
 
Experience: Intermediate
Platform: ToS, NT
Trading: ES
Posts: 11 since Aug 2013
Thanks Given: 8
Thanks Received: 2

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.

Reply With Quote
  #25 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


pbailey19 View Post
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.


Reply With Quote
  #26 (permalink)
 pbailey19 
Denver, CO
 
Experience: Intermediate
Platform: ToS, NT
Trading: ES
Posts: 11 since Aug 2013
Thanks Given: 8
Thanks Received: 2

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.

Reply With Quote
Thanked by:
  #27 (permalink)
 
master trader's Avatar
 master trader 
Calgary AB, Canada
 
Experience: Master
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, GC, ZB
Posts: 124 since Apr 2010
Thanks Given: 43
Thanks Received: 41


Fat Tails View Post
@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.









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 ....


Thanks.

Reply With Quote
  #28 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


master trader View 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 ....


Thanks.

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.

Reply With Quote
Thanked by:
  #29 (permalink)
 
master trader's Avatar
 master trader 
Calgary AB, Canada
 
Experience: Master
Platform: NinjaTrader
Broker: Zen-Fire
Trading: CL, GC, ZB
Posts: 124 since Apr 2010
Thanks Given: 43
Thanks Received: 41


Fat Tails View Post
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.







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.

Reply With Quote
Thanked by:
  #30 (permalink)
 
WilleeMac's Avatar
 WilleeMac 
Prospect, KY. USA
 
Experience: None
Platform: Sierra Chart
Broker: Infinity
Trading: /CL
Posts: 687 since Jan 2012
Thanks Given: 309
Thanks Received: 617


I'm a little late to the party

Thank you @Fat Tails

-William

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on August 26, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts