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

Dataseries Array Comparison I Need Help!

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

    Dataseries Array Comparison I Need Help!

    NinjaTrader 7 Help

    I am attempting to utilize 2 DataSeries to compare my current candles Low to the low of a specific time
    of day. If the current candles low does indeed show that it is lower, then i check to see if the candle
    close is less than the lower Bollinger band. I am confused with how to look back at a particular time within the second array to get the low of the particular set time i have stored. Can anyone help?

    In one array i am setting the low of say Time 3:01 and the array length is one since it only needs to keep one Value. The other DataSeries would keep multiple values and check against the shorter
    array. As time advances i will check back to 301 again and again until it is time to reset 301 for the next day.

    private DataSeries[]EntryLow; // Short Array
    private DataSeries myDataSeries; // Long Array

    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    EntryLow = new DataSeries[1];// Array Size
    //EntryLow = new DataSeries(this);
    myDataSeries = new DataSeries(this, MaximumBarsLookBack.Infinite);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    myDataSeries.Set(Low[0]);


    if(ToTime(Time[0]) == ToTime(3,01,0))
    {
    EntryLow.Set(Low[0]);
    }

    if(ToTime(Time[0]) > ToTime(3,01,0)
    && myDataSeries[0] < EntryLow [0] //Not sure how to call EntryLow stored value
    && Low[0] < Bollinger(2, 14).Lower[0])
    {
    DrawHorizontalLine("My horizontal line" + CurrentBar, 5, Color.Chartreuse);
    }
    }

    #2
    Hello NewCode,

    A dataseries will hold a value for every bar on the chart, so that its possible to access data historically. For example if you wanted to store custom calculated values so that this can be used as the input series for an indicator call like the SMA.

    In your code, you seem to only be wanting the current bars value and not any previous bars, is this correct?
    If so, you may not be wanting to use a data series.

    An array would hold several values, but would not be synced with the bars on the chart. This means if you wanted to store a handful of values you wanted to be able to call at any time, any array would be suitable for this.

    If you are only wanting a value for the current bar to store the low or your custom value, a double would be suitable for this.

    Further, with the code:
    private DataSeries[]EntryLow;

    This would be attempting to create an array of dataseries. I would recommend against this.

    For a single series
    Code:
    private DataSeries EntryLow;
    
    protected override void Initialize()
    {
    EntryLow = new DataSeries(this);
    }
    
    protected override void OnBarUpdate()
    {
    EntryLow.Set(Low[0]);
    Print(EntryLow[0]);
    }
    Below is a publicly available link to the help guide on the DataSeries class.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have run the code you have shown and am still getting compiler errors. I have also added the SMA portion as you mentioned and am not sure how to call on the current SMA value and compare it to the set 301 or EntryLow value.

      public class ArrayTrade : Strategy
      {
      private DataSeries EntryLow;
      protected override void Initialize()
      {

      EntryLow= new DataSeries(this);

      CalculateOnBarClose = true;
      }

      protected override void OnBarUpdate()
      {
      if(ToTime(Time[0]) == ToTime(3,01,0))
      {
      EntryLow.Set(Low[0]);
      Print(EntryLow[0]);
      }

      if (DefaultInput[0] + EMA(14)[0] + Low[0] * TickSize < EntryLow[])
      {
      DrawHorizontalLine("My horizontal line" + CurrentBar, 5, Color.Chartreuse);
      }
      }

      Comment


        #4
        Hello NewCode,

        It appears you have called EntryLow without an index (a pair of empty brackets). This will not compile.

        Which historical bar did you want?

        Use the barsAgo value for that bar.

        ( don't feel that a data series is the correct object here)
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        2 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,263 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X