• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting a number of days in AddDataSeries

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

    Setting a number of days in AddDataSeries

    I am trying to get the value of a 22 Period Daily Moving average. I am using the following to add the series:

    Code:
    AddDataSeries("SPY",BarsPeriodType.Day,1,22);
    I understand that to be adding 22 Daily bars. Is this not the correct way? I am getting an error that these are not the correct parameters. I just need to calc the 22 period average of those one time to set a fixed value that the indicator will use. Any help with the MA would be a bonus. Thanks

    #2
    Hello swcookie,

    The error would be correct, there is no overload pattern like this. You can find the accepted patterns in the help guide here: https://ninjatrader.com/support/help...=adddataseries

    The closest to what you are asking for would be the overload that includes a number of bars to load. You could calculate the number of bars you want that would equate to 22 days and then add that. For a daily series you would just need to use 22 for 22 Bars of daily data.


    Code:
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)
    Alternatively, you would add just the daily series using the normal overload set,
    Code:
    AddDataSeries(string instrumentName, BarsPeriodType periodType, int period)
    and then use 22 days to load in the chart or where the strategy is applied.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I am having a little trouble with the overload pattern. This is what I am using:
      Code:
      AddDataSeries("SPY",BarsPeriodType.Day,22,"Use instrument settings",true);
      Still not able to compile. I am not seeing any real life examples on the forum or in the docs, of what this looks like when its overloaded this way. Can you assist?

      Comment


        #4
        Hello swcooke,

        Thanks for the reply.

        The method is expecting you to make a new BarPeriod object and enter the name of the session template you want to use:

        AddDataSeries("SPY", new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, 22, "US Equities RTH", true);

        To find the default trading hours template an instrument is using, go to Tools>Instruments>Search the instrument>Open the instrument configuration menu>look at the Trading Hours field.

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks for that. I am trying to calculate the 22 period MA 1 time at the beginning of the script so that the script can use its' value. Here is what I have but it does not match the 22 period MA that I add to a chart as just a basic indicator:

          Code:
          else if (State == State.Configure)
          {
              AddDataSeries("SPY", new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 }, 22, "US Equities RTH", true);
          }
          else if (State == State.DataLoaded)
          {
              Print("Value is " + SMA(BarsArray[1], 22)[0]);  //this does not match what an SMA Indicator is returning for the last bar
          }

          Comment


            #6
            Hello swcooke,

            Thank you for the reply.

            In this case, you need to move your logic out of OnStateChange to OnBarUpdate. You cannot access price or indicator values in DataLoaded.

            Additionally, if you access the indicator on the first bar or once, that would either be before the BarsRequiredToPlot or would just be the first value for your indicator. The SMA changes over time so to get the same values you see on the chart, you would have to check its value for each OnBarUpdate call.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ralett, Today, 11:44 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Spencer  
            Started by DMDINAZ, Today, 11:03 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by sukhob, Today, 10:14 AM
            4 responses
            10 views
            0 likes
            Last Post sukhob
            by sukhob
             
            Started by beaacontreras, Today, 09:27 AM
            1 response
            20 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by fxSol, 03-17-2019, 04:17 AM
            5 responses
            28 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Working...
            X