Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

(Using the Bar High / Low Trailing Stop) indicator

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

    (Using the Bar High / Low Trailing Stop) indicator

    Good Morning !

    im looking a indicator to move stop loss 2 ticks below a last bar when close like

    this video https://www.youtube.com/watch?v=hIVvW6ikOdY


    if no have this indicator, how I program this indicator

    thanks !

    #2
    Hello Alberl,

    Thank you for writing in. I am not aware of any free strategies that accomplish this but please feel free to search our forums here: http://www.ninjatrader.com/support/f...?action=search

    If you wish to develop this yourself, you would need to use a NinjaScript strategy.
    The stop loss portion of the strategy would look something like this:

    1. Get the price of 2 ticks below the close of the previous bar to dynamically adjust the Stop Loss inside of the OnBarUpdate() method
    Code:
    SetStopLoss(Close[1] - 2 * TickSize);
    For more information on working with the SetStopLoss() method, please see our help guide: http://www.ninjatrader.com/support/h...ub=setstoploss

    If you are new to NinjaScript, please make sure to read through our NinjaScript tutorials: http://www.ninjatrader.com/support/h..._resources.htm

    If we may be of further assistance, please let us know.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      I use chart trader in strategy it can not use chart trader in the video he maintains chart trader open using the system

      Comment


        #4
        this is a ATR trailing stop indicator code:


        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        ///
        /// </summary>
        [Description("Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.")]
        public class ATRTrailingStop : Indicator
        {
        #region Variables
        private int period = 5;
        private double multi = 3.5;
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
        Add(new Plot(Color.Blue, PlotStyle.Line, "Trailing Stop"));
        CalculateOnBarClose = true;
        Overlay = true;
        BarsRequired = 1;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        { SetStopLoss(Close[1] - 1 * TickSize);
        if (CurrentBar < 1)
        return;

        // Trailing stop
        double trail;
        double loss = ATR(Input, Period)[0] * Multi;

        if (Close[0] > Value[1] && Close[1] > Value[1])
        trail = Math.Max(Value[1], Close[0] - loss);

        else if (Close[0] < Value[1] && Close[1] < Value[1])
        trail = Math.Min(Value[1], Close[0] + loss);

        else if (Close[0] > Value[1])
        {
        trail = Close[0] - loss;
        DrawArrowDown(CurrentBar.ToString(), false, 1, Value[1], Color.Orange);
        }

        else
        {
        trail = Close[0] + loss;
        DrawArrowUp(CurrentBar.ToString(), false, 1, Value[1], Color.Orange);
        }

        Value.Set(trail);
        }

        #region Properties
        [Description("ATR period")]
        [Category("Parameters")]
        public int Period
        {
        get { return period; }
        set { period = Math.Max(1, value); }
        }

        [Description("ATR multiplication")]
        [Category("Parameters")]
        public double Multi
        {
        get { return multi; }
        set { multi = Math.Max(0, value); }
        }
        #endregion
        }
        }

        #region NinjaScript generated code. Neither change nor remove.
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        public partial class Indicator : IndicatorBase
        {
        private ATRTrailingStop[] cacheATRTrailingStop = null;

        private static ATRTrailingStop checkATRTrailingStop = new ATRTrailingStop();

        /// <summary>
        /// Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.
        /// </summary>
        /// <returns></returns>
        public ATRTrailingStop ATRTrailingStop(double multi, int period)
        {
        return ATRTrailingStop(Input, multi, period);
        }

        /// <summary>
        /// Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.
        /// </summary>
        /// <returns></returns>
        public ATRTrailingStop ATRTrailingStop(Data.IDataSeries input, double multi, int period)
        {
        if (cacheATRTrailingStop != null)
        for (int idx = 0; idx < cacheATRTrailingStop.Length; idx++)
        if (Math.Abs(cacheATRTrailingStop[idx].Multi - multi) <= double.Epsilon && cacheATRTrailingStop[idx].Period == period && cacheATRTrailingStop[idx].EqualsInput(input))
        return cacheATRTrailingStop[idx];

        lock (checkATRTrailingStop)
        {
        checkATRTrailingStop.Multi = multi;
        multi = checkATRTrailingStop.Multi;
        checkATRTrailingStop.Period = period;
        period = checkATRTrailingStop.Period;

        if (cacheATRTrailingStop != null)
        for (int idx = 0; idx < cacheATRTrailingStop.Length; idx++)
        if (Math.Abs(cacheATRTrailingStop[idx].Multi - multi) <= double.Epsilon && cacheATRTrailingStop[idx].Period == period && cacheATRTrailingStop[idx].EqualsInput(input))
        return cacheATRTrailingStop[idx];

        ATRTrailingStop indicator = new ATRTrailingStop();
        indicator.BarsRequired = BarsRequired;
        indicator.CalculateOnBarClose = CalculateOnBarClose;
        #if NT7
        indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
        indicator.MaximumBarsLookBack = MaximumBarsLookBack;
        #endif
        indicator.Input = input;
        indicator.Multi = multi;
        indicator.Period = period;
        Indicators.Add(indicator);
        indicator.SetUp();

        ATRTrailingStop[] tmp = new ATRTrailingStop[cacheATRTrailingStop == null ? 1 : cacheATRTrailingStop.Length + 1];
        if (cacheATRTrailingStop != null)
        cacheATRTrailingStop.CopyTo(tmp, 0);
        tmp[tmp.Length - 1] = indicator;
        cacheATRTrailingStop = tmp;
        return indicator;
        }
        }
        }
        }

        // This namespace holds all market analyzer column definitions and is required. Do not change it.
        namespace NinjaTrader.MarketAnalyzer
        {
        public partial class Column : ColumnBase
        {
        /// <summary>
        /// Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.ATRTrailingStop ATRTrailingStop(double multi, int period)
        {
        return _indicator.ATRTrailingStop(Input, multi, period);
        }

        /// <summary>
        /// Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.
        /// </summary>
        /// <returns></returns>
        public Indicator.ATRTrailingStop ATRTrailingStop(Data.IDataSeries input, double multi, int period)
        {
        return _indicator.ATRTrailingStop(input, multi, period);
        }
        }
        }

        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        public partial class Strategy : StrategyBase
        {
        /// <summary>
        /// Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.ATRTrailingStop ATRTrailingStop(double multi, int period)
        {
        return _indicator.ATRTrailingStop(Input, multi, period);
        }

        /// <summary>
        /// Indicator as described in Sylvain Vervoort's 'Average True Range Trailing Stops' June 2009 S&C article.
        /// </summary>
        /// <returns></returns>
        public Indicator.ATRTrailingStop ATRTrailingStop(Data.IDataSeries input, double multi, int period)
        {
        if (InInitialize && input == null)
        throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

        return _indicator.ATRTrailingStop(input, multi, period);
        }
        }
        }
        #endregion
        -----------------------------------------------------------------------------------------------------------------------------------------------------
        Where I put the code of the stop loss ???

        Comment


          #5
          Hello Alberl,

          I apologize for the confusion. What you are trying to do is not officially supported within NinjaTrader 7. Please feel free to search our forums as there are other users who have accomplished working with order methods/functions/values within an indicator: http://www.ninjatrader.com/support/f...ad.php?t=74190

          Please let us know if we may be of further assistance.
          Michael M.NinjaTrader Quality Assurance

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by r68cervera, Today, 05:29 AM
          0 responses
          2 views
          0 likes
          Last Post r68cervera  
          Started by geddyisodin, Today, 05:20 AM
          0 responses
          3 views
          0 likes
          Last Post geddyisodin  
          Started by JonesJoker, 04-22-2024, 12:23 PM
          6 responses
          33 views
          0 likes
          Last Post JonesJoker  
          Started by GussJ, 03-04-2020, 03:11 PM
          12 responses
          3,239 views
          0 likes
          Last Post Leafcutter  
          Started by AveryFlynn, Today, 04:57 AM
          0 responses
          6 views
          0 likes
          Last Post AveryFlynn  
          Working...
          X