NexusFi: Find Your Edge


Home Menu

 





amaSuperTrendU11, need some help in translating


Discussion in NinjaTrader

Updated
    1. trending_up 2,052 views
    2. thumb_up 8 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

amaSuperTrendU11, need some help in translating

  #1 (permalink)
StickRustler
Melbourne, FL
 
Posts: 18 since Jul 2020
Thanks Given: 4
Thanks Received: 2

I discovered this indicator watching one of the videos in futures.io archive.

I find it to be one of the best exit indicators--with the right settings, it latches on to the trend without getting shaken out early.

In my testing, I've found the EMA and HMA baseline smoothing works best.


MotiveWave
On to my question: I'm exploring the MotiveWave charting/trading platform and would like to translate this to java, using the MW built-in SuperTrend as a template (though MW has a ton of built-in indicators, there's a paucity of 3rd-party stuff--especially FREE 3rd-party stuff.)

I do not want or need to do a complete translation, with all the options.

All I need is to get my default setup working, which is:
Baseline smoothing: EMA
Offset smoothing: Default
Offset type: True Range
NT source code
I've gone thru the NT source code trying to grok how this all works.

What I think I understand so far:

Baseline smoothing is a filter applied to closing price

 
Code
baseline = AuEMA(Input, basePeriod).Value;

Offset smoothing is a filter applied to the offset type, in my case using the default rangeSeries = 'True Range', with a rangePeriod = 15.

 
Code
case AuSuperTrendU11OffsetType.Default:
offsetSeries = AuEMA(rangeSeries, rangePeriod).Value; break;

MW java calculation

Here's the basic ST calculation in MW java:
 
Code
    DataSeries series=ctx.getDataSeries();    
    Double atr = series.atr(index, atrPeriod);

    float mid = (series.getHigh(index) + series.getLow(index))/2;
    double up = mid - (mult*atr);
    double down = mid + (mult*atr);
'series' here is the same as 'input' in NT.

As for applying offset smoothing, I believe all that's needed is to create an EMA with atr as its input, substituting that for atr, and using it to calculate up / down.

What I'm unclear about is applying baseline smoothing.
Is it applied directly to series before calculating ATR?
Or is it applied when calculating 'mid' above?

I'd appreciate any help in understanding and implementing this.

Thanks in advance

And thanks to Fat Tails for porting this to NT

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
 
  #2 (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,103

If you want to code it in Java, here are some details about the SuperTrend.

History: The SuperTrend is a simple SAR (Stop-And-Reverse) indicator. It works as a trailing stop, which means that the stop only moves in the direction of the current trend, until it is broken. Once there is a close on the other side of the stop line, it reverts. I think that the indicator originates from the TradeStation universe.

Architecture:

First the indicator calculates a moving average, which is not shown on the chart. In a second step a multiple of the average true range is deducted (during an uptrend) or a multiple of the average true range is added (during a downtrend) to calculate the stop line which is shown on the chart. You may select parameters for the moving average, the average true range and the multiplier as needed. The SuperTrend is a close relative of the Keltner Channel. However, the Keltner Channel may expand, while the trailing stop logic imposed by the SuperTrend prohibits expansion.

Weaknesses:

Most of the indicators in use were developed 50 years ago and applied to printed charts. The printed charts were sent by post.
With modern chartint applications, indicator values are being recaculated with every incoming tick. For example, if you add a Bollinger Band to your chart and let the indicator recalculate with every tick, the Bollinger Band will breathe, as the calculated values for the moving average and the standard deviation are changing intra-bar. In fact, when price approaches the Bollinger Bands, the bands will move away from price, because the moving average will bend towards the bar close and the standard deviataion will increase at the same time. Hitting the Bollinger Bands is like aiming at a moving target. It is a bit like clay pigeon shooting. With a trailing stop, we do not want that the stop moves away when price approaches it. It should be calculated at the bar open and then it should remain where it is. If it stays in place, you may also issue a stop market order to enter a position based on the stop value.

SuperTrendM11:

The appendix "M11" stands for "Median", calculated 1 bar ago, ATR calculated 1 bar ago. The median is used as the moving average, because a median is less dependent on outliers compared to standard moving averages. To avoid that the SuperTrend breathes, moving the stop for the current bar around, median and ATR are calculated from the prior bar. Thus the stop does not change throughout the life of the current bar. This is much more practical than a moving target.

Another question is whether the SuperTrend reverts when the stop line is hit intra-bar, or when there is a bar close beyond the stop line. Traditionally, NinjaTrader indicators will trigger intra-bar when set to Calculate.OnEachTick (or Calculate.OnPriceChange) but trigger at the bar close, when set to Calculate.OnBarClose. The SuperTrendM11 does not show this behavior, but the option to reverse intra-bar or at the bar close can be chosen regardless whether the indicator is set to Calculate.OnEachTick or Calculate.OnBarClose. For example, you may set the indicator to Calculate.OnPriceChange, receive a sound alert or visual alert intra-bar, but only have the trade signal gerenated at the bar close. By the way my backtests have shown that it is better to wait for the bar close most of the time before generating a reversal signal.

To summarize: Moving average and ATR are calculated one bar ago to prevent breathing of the stop line. The reverse intra-bar option is independent from the "Calculate" settings.

SuperTrendU11:

The SuperTrendU11 is built on the model of the SuperTrendM11, but is a more universal indicator. "U11" stands for "Universal moving average" calculated 1 bar ago, "Universal Volatility" calculated 1 bar ago. THe concept is still the same, but you may select the moving average type and the measure of volatility for calculating the stop line:

- It comes with 36 different moving averages to select from.
- Other than the ATR average true range), you may also use the AR (average range), the residual mean absolute deviation or the residual root mean square deviation for calculating the stop line.

In my opinion the SuperTrend it is a better tool for filtering trends and exit timing than for generating trade entries. Trade signals for entries are often generated late. I think this is all you need to know about the indicator.

Reply With Quote
  #3 (permalink)
StickRustler
Melbourne, FL
 
Posts: 18 since Jul 2020
Thanks Given: 4
Thanks Received: 2


Thanks for the detailed explanation.

I spent more time looking at the code and understand how it's calculating now.

For my particular config: EMA on baseline, and the default ATR calc, the formula, with an ATR multiplier of 1, is basically:

 
Code
Long stop =
   EMA(emaPeriod) of price
-  EMA(ATRPeriod) of ATR 

Short stop =
   EMA(emaPeriod) of price
+  EMA(ATRPeriod) of ATR
Now it's on to comprehending how MW SDK works. It's not as simple as NinjaScript.

With NS, you can easily setup an indicator series and access it.
In MW's JDK, it appears the coder is responsible for creating and updating the indicator on each bar close.

Once I figure it out, I may release a simple version on the MW forums, with HMA and EMA baseline smoothing.

Reply With Quote
  #4 (permalink)
StickRustler
Melbourne, FL
 
Posts: 18 since Jul 2020
Thanks Given: 4
Thanks Received: 2


Fat Tails View Post
In my opinion the SuperTrend it is a better tool for filtering trends and exit timing than for generating trade entries. Trade signals for entries are often generated late. I think this is all you need to know about the indicator.

Do you prefer any single indicator for entries, or are your entries based on multiple indicators, or indicators with multiple filters?

Reply With Quote




Last Updated on October 19, 2020


© 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