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

Doing per bar operations on added data series

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

    Doing per bar operations on added data series

    Hi,

    I have a couple of questions. First, how do I do computations on added data series? For example, in this sample I'm adding the VIX and VIX9D indices as additional data types

    OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    ...
    AddPlot(Brushes.White, "VIX9DtoVIXDiff");
    }
    ...
    else if (State == State.Configure)
    {
    AddDataSeries("^VIX9D", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
    AddDataSeries("^VIX", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
    }

    OnBarUpdate()
    {
    ...
    VIX9DtoVIXDiff[0] = current bar ^VIX9D minus current bar ^VIX
    }

    To keep things simple, assume the main instrument is also a daily bar. I understand and am familiar with BarsInProgress etc., just looking for the syntax for accessing the data for the added series. Should it be simply using Closes[1][0] and Closes[2][0], or do I need something more elaborate like using BarsArray[] in some form or another?

    Second question, how do I add data series using the current BarsPeriodType, i.e. what is the syntax? For instance if I switch to an hourly chart I would want VIX and VIX9D to automatically be in the same format and not as daily types.

    Thanks.

    #2
    Hi silverm3170, thanks for posting.

    Additional series can be accessed using the BarsInProgress context. When BarsInProgress = 0, OnBarUpdate is being called for the primary series, and when BarsInProgress = 1, OnBarUpdate is being called for the secondary series and so on. E.g.

    OnBarUpdate()
    {
    if(BarsInProgress == 0)
    {
    Print("Daily " + Closes[0][0]);
    }
    if(BarsInProgress == 1)
    {
    Print("^VIX9D " + Closes[1][0]);
    }
    }

    There are examples of using BarsPeriod in AddDataSeries here:


    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris. How can I add the data series using the same time bar type as the master instrument, e.g. if 5 minute, then 5 minute, if daily, then daily, etc. Is there a format of the call that does this implicitly, or must we always explicitly declare the bar type when adding series?

      Comment


        #4
        Found it, just AddDataSeries(instrument name);

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pechtri, 06-22-2023, 02:31 AM
        9 responses
        122 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by frankthearm, 04-18-2024, 09:08 AM
        16 responses
        64 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by habeebft, Today, 01:18 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by benmarkal, Today, 12:52 PM
        2 responses
        13 views
        0 likes
        Last Post benmarkal  
        Started by f.saeidi, Today, 01:38 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X