Announcement

Collapse
No announcement yet.

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

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        627 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        359 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        562 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X