Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicators with built in DataSeries behaving different from NT7

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

    Indicators with built in DataSeries behaving different from NT7

    I have a 3 custom indicators that work close enough to their ninjatrader 7 counterparts on a chart (Error<5%) to make me satisfied. However when used in a strategy it doesn't function because I get an error cause by the indicator creating a data series when it initializes. It's creating a 1 minute data series so it can't load the indicator from the strategy. If I edit the indicator to accept a 1 minute data series argument from the strategy it's nothing close to the chart it is supposed to emulate. The example shown here is an edited ATR to show the ATR of a period of time on a range or renko chart(which don't use time).

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class MinuteATRVisual : Indicator
        {
            private PeriodBasis     basis = PeriodBasis.Default; // Default setting for SecondBased
            private int                barsAgo;
            private int                array = 0;
            private int                timePeriod    = 1;
            private Series<double>    TrueRange;
            private double             trueRange;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionATR;
                    Name                        = "MinuteATRVisual";
                    IsSuspendedWhileInactive    = true;
                    Period                        = 300;
                    barsAgo = Period;
    
    //                TrueRange        = new DataSeries(this);
                    AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameATR);
                }
    
                else if (State == State.DataLoaded)
                    TrueRange        = new Series<double>(this);
    
                else if (State == State.Configure)
                {
                    barsAgo                     = Period;
                    if (basis == PeriodBasis.MinuteBased)
                    {
                        AddDataSeries(BarsPeriodType.Minute, timePeriod);
                        array                         = 1;
                    }
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBars[array] < barsAgo * 2
                    && CurrentBars[0] < 10)
                {
    //                Value[0] = (1);
                    return;
                }
    
                if (array == 1 &&
                    BarsInProgress == 0)
                {
                    Value[0] = (Value[1]);
    
                    return;
                }
    
                if (BarsInProgress != array)
                    return;
    
                if (basis == PeriodBasis.SecondBased)
                    barsAgo = CurrentBars[array] - Bars.GetBar(Time[0].AddSeconds((Period * (-1)) * timePeriod));
    
                double high0    = High[0];
                double low0        = Low[0];
    
                if (CurrentBar <= barsAgo * 2)
                    Value[0] = high0 - low0;
                else
                {
                    trueRange = MAX(High, barsAgo)[0] - MIN(Low, barsAgo)[0];
                    TrueRange[0] = Math.Max(Math.Abs(MIN(Low, barsAgo)[0] - Close[1]), Math.Max(trueRange, Math.Abs(MAX(High, barsAgo)[0] - Close[1])));
                    Value[0] = EMA(EMA(TrueRange, barsAgo), 10)[0];
                }
            }
    
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
            public int Period
            { get; set; }
    
            /// <summary>
            /// </summary>
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Description("Numbers of bars used for calculations.")]
            public int TimePeriod
            {
                get { return timePeriod; }
                set { timePeriod = Math.Max(1, value); }
            }
    
            [NinjaScriptProperty]
            [Description("")]
            public PeriodBasis PeriodBasis
            {
                get { return basis; }
                set { basis = value; }
            }
            #endregion
        }
    }
    
    public enum PeriodBasis
    {
        Default,
        SecondBased,
        MinuteBased
    }
    It should in theory be the same if I give it a minute series rather than setting it to "PeriodBasis.MinuteBased" but not only are the raw numbers different by > 5% up to 50% but the behavior itself is vastly different as well. My NT7 strategy depends on the behavior of this indicator and is less than 50% as effective because of its malfunction in NT8.

    #2
    Hello magnatauren,

    I'm not sure I am understanding the issue.

    Are you trying to use Closes[1] or BarsArray[1] for the input series of an indicator?


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea, sorry for the late response, I got caught up in another project. That was the error I didn't carry over from NT7. Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      640 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X