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 gemify, 11-11-2022, 11:52 AM
        6 responses
        803 views
        2 likes
        Last Post ultls
        by ultls
         
        Started by ScottWalsh, Today, 04:52 PM
        0 responses
        3 views
        0 likes
        Last Post ScottWalsh  
        Started by ScottWalsh, Today, 04:29 PM
        0 responses
        7 views
        0 likes
        Last Post ScottWalsh  
        Started by rtwave, 04-12-2024, 09:30 AM
        2 responses
        22 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by tsantospinto, 04-12-2024, 07:04 PM
        5 responses
        70 views
        0 likes
        Last Post tsantospinto  
        Working...
        X