Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Wilder ATR trailing stop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Wilder ATR trailing stop

    Does anybody know where I can get the code for Wilder's ATR trailing stop

    I was told it came with ninja script but I cannot find it under the indicators

    thanks in advance

    #2
    Originally posted by delta20 View Post
    Does anybody know where I can get the code for Wilder's ATR trailing stop

    I was told it came with ninja script but I cannot find it under the indicators

    thanks in advance
    Is it simply the ATR indicator in NT?

    [Description("The Average True Range (ATR) is a measure of volatility. It was introduced by Welles Wilder in his book 'New Concepts in Technical Trading Systems' and has since been used as a component of many indicators and trading systems.")]

    Comment


      #3
      Well there is the average true range which calculates the average movement over a certain period usually referred to as the ATR. This is on ocsillator which does come with Ninja.

      The ATR trailing stop (forgive my explanation if it is confusing) is usually represented on the chart itself with dots above or below price action. The most common setting is 2xs a 5 period ATR. There is also a modified and unmodified version the modified version is the norm.

      Lets say the ATR is 4 points and we are in a long ATR position (price above trailing stop). There will be a trailing stop of 4 below the price. As the ATR changes and the price moves up the stop will trail by the ATR amount. The stop can never go down only up.

      Once the stop is broken to the down side the trailing stop (dot) will appear above the price action now and the same thing in reverse.

      I do not believe this formula is in Welles book I am pretty familar with that book.

      Here is the code from Think or Swim think script. I am not much of a programmer and not sure this would really help but not sure how else to explain it.


      input trailType = {default modified, unmodified};
      input ATRPeriod = 5;
      input ATRFactor = 3.5;
      input firstTrade = {default long, short};

      assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

      def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
      def HRef = if low <= high[1]
      then high - close[1]
      else (high - close[1]) - 0.5 * (low - high[1]);
      def LRef = if high >= low[1]
      then close[1] - low
      else (close[1] - low) - 0.5 * (low[1] - high);
      def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

      def loss;
      switch (trailType) {
      case modified:
      loss = ATRFactor * ATRMod;
      case unmodified:
      loss = ATRFactor * AvgTrueRange(high, close, low, ATRPeriod);
      }

      rec state = {default init, long, short};
      rec trail;
      switch (state[1]) {
      case init:
      if (!IsNaN(loss)) {
      switch (firstTrade) {
      case long:
      state = state.long;
      trail = close - loss;
      case short:
      state = state.short;
      trail = close + loss;
      }
      } else {
      state = state.init;
      trail = Double.NaN;
      }
      case long:
      if (close > trail[1]) {
      state = state.long;
      trail = Max(trail[1], close - loss);
      }
      else {
      state = state.short;
      trail = close + loss;
      }
      case short:
      if (close < trail[1]) {
      state = state.short;
      trail = Min(trail[1], close + loss);
      }
      else {
      state = state.long;
      trail = close - loss;
      }
      }

      def BuySignal = Crosses(state == state.long, 0, CrossingDirection.Above);
      def SellSignal = Crosses(state == state.short, 0, CrossingDirection.Above);

      plot TrailingStop = trail;

      TrailingStop.SetPaintingStrategy(PaintingStrategy. POINTS);
      TrailingStop.DefineColor("Buy", GetColor(0));
      TrailingStop.DefineColor("Sell", GetColor(1));
      TrailingStop.AssignValueColor(if state == state.long
      then TrailingStop.color("Sell")
      else TrailingStop.color("Buy"));

      Comment


        #4
        I would also suggest revieweing the ATR trailing indicator found in our sharing section, perhaps that's closer to what you seek - http://www.ninjatrader.com/support/f...rch=ATR&desc=1
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks

          That is pretty much it

          It has slightly different parameters than I am used. It has a rachet affect which is similar to the parabolic sars

          will definitely work thanks again

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mgco4you, Today, 09:46 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by wzgy0920, Today, 09:53 PM
          0 responses
          3 views
          0 likes
          Last Post wzgy0920  
          Started by Rapine Heihei, Today, 08:19 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 08:25 PM
          0 responses
          6 views
          0 likes
          Last Post Rapine Heihei  
          Started by f.saeidi, Today, 08:01 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X