Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling price data from second data series

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

    Calling price data from second data series

    Hi,

    I am developing an indicator which will compare the strength of a stock against SPY.

    I have added the SPY data series to my code as below...
    else if (State == State.Configure)
    {
    AddDataSeries("SPY", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
    }

    In the calculation I want to compare the close of the current bar of SPY against the previous bar of SPY. If I used close[0] this would use the data value from the stock as the primary instrument, not SPY as the second instrument.

    How can I call the closing price of SPY for the current bar and the previous bar?

    Thanks,

    Neil

    #2
    Hello burtoninlondon,

    Thank you for your note.

    When you're using multiple data series, you'd want to refer to the Closes series, which is an array of ISeries<double> objects holding historical bar close prices. A Close series is added to this array when calling the AddDataSeries() method for each added series. So, you can easily refer to the close price of the added SPY series using the following:

    double lastSPYClose = Closes[1][0] // assuming SPY is the first/only added series, get the most recent close value of the SPY added series
    double priorSPYClose = Closes[1][1] // get the close price of the SPY bar 1 bar ago



    I'd advise reviewing our help guide section on multi-time frame/instrument scripts here:



    Please let us know if we may be of further assistance to you.

    Comment


      #3
      NinjaTrader_Kate - I think I understand that, I'll give it a shot and get back to you if I have any issues.

      ...presumably if I had a 3rd data series (1st = stock, 2nd = SPY, 3rd = another) then I'd access the 3rd series current bar close by using Closes [2][0]?

      On a similar note, my calculation also compares the 20-period ATR of the stock with the 20-period ATR of SPY...I would use ATR(20)[0] for the stock but would I use ATR([1],20)[0] for the SPY data series?

      Thanks again.

      Comment


        #4
        Hello burtoninlondon,

        Thank you for your reply.

        You're spot on on accessing the 3rd series using Closes[2][0]. You'd use Closes[0][0] to get the close of the primary series.

        As far as using the series as an input for the ATR, you'd use BarsArray[1] to use the added SPY series to calculate the ATR:

        ATR(BarsArray[1], 20)[0]

        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X