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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        98 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        142 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        125 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        77 views
        0 likes
        Last Post PaulMohn  
        Working...
        X