Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing DataSeries elements in Multi-timeframe Strategies

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

    Referencing DataSeries elements in Multi-timeframe Strategies

    When using multi-timeframe Strategies, how can I reference the elements of a secondary timeframe based DataSeries? I've setup an example strategy where I'm entering 1000t as the primary timeframe in the Strategy Analyzer and 200t for a secondary timeframe in the code. I've attached the example simple strategy which is composed of the following code:

    Variables
    private DataSeries myOpen;

    Initialize()
    Add(PeriodType.Tick, 200); // secondary 200t timeframe
    myOpen = new DataSeries(this);

    OnBarUpdate()
    if (BarsInProgress == 1) // work with secondary timeframe
    {
    if (CurrentBar == 0) {
    myOpen.Set(0);
    return;
    }
    myOpen.Set(Open[0]); // set myOpen to secondary timeframe Open

    Print("myOpen[1]("+myOpen[1]+") myOpen[0]("+myOpen[0]+")");
    }

    Output:
    08/28/08 12:27:42 PM myOpen[1](0) myOpen[0](1296)
    08/28/08 12:28:25 PM myOpen[1](0) myOpen[0](1295.75)
    08/28/08 12:28:51 PM myOpen[1](0) myOpen[0](1296.25)
    08/28/08 12:29:25 PM myOpen[1](0) myOpen[0](1297)
    08/28/08 12:30:24 PM myOpen[1](0) myOpen[0](1296.5)
    08/28/08 12:31:24 PM myOpen[1](1296.5) myOpen[0](1296.25)
    08/28/08 12:32:27 PM myOpen[1](1296.5) myOpen[0](1296.75)
    08/28/08 12:33:41 PM myOpen[1](1296.5) myOpen[0](1296.25)
    08/28/08 12:34:15 PM myOpen[1](1296.5) myOpen[0](1295.75)
    08/28/08 12:34:32 PM myOpen[1](1296.5) myOpen[0](1295.25)
    08/28/08 12:35:44 PM myOpen[1](1295.25) myOpen[0](1295.25)

    The use of overload 'myOpen[0]' works properly, but using 'myOpen[1]' gives me a value that only changes when the primary timeframe (1000t) updates which is 1 time for every 5 times of the secondary timeframe (200t) updates. How can I specify, set and reference DataSeries values based on the secondary timeframe?

    Thanks,

    David
    dbw451
    Attached Files

    #2
    Could this help?

    RayNinjaTrader Customer Service

    Comment


      #3
      Yes, it works. Pretty tricky... The key is to use an arbitrary indicator with a secondary bar IDataSeries input to sync the DataSeries with the secondary bar object when constructing the DataSeries. In my example, I moved the 'new' statement from the Initialize() event to the OnBarUpdate() event and passed an arbitrary indicator using BarsArray[1] to construct the DataSeries:

      OnBarUpdate()
      if (myOpen == null)
      myOpen =
      new DataSeries(SMA(BarsArray[1], 1));

      Now the output works correctly:

      08/28/08 12:21:45 PM myOpen[1](1295) myOpen[0](1295.5)
      08/28/08 12:21:59 PM myOpen[1](1295.5) myOpen[0](1295)
      08/28/08 12:22:18 PM myOpen[1](1295) myOpen[0](1295.25)
      08/28/08 12:22:27 PM myOpen[1](1295.25) myOpen[0](1295.25)
      08/28/08 12:22:50 PM myOpen[1](1295.25) myOpen[0](1295.25)
      08/28/08 12:23:37 PM myOpen[1](1295.25) myOpen[0](1295.5)
      08/28/08 12:24:13 PM myOpen[1](1295.5) myOpen[0](1295.5)
      08/28/08 12:24:45 PM myOpen[1](1295.5) myOpen[0](1295.5)
      08/28/08 12:25:11 PM myOpen[1](1295.5) myOpen[0](1295.25)
      08/28/08 12:25:33 PM myOpen[1](1295.25) myOpen[0](1295.5)
      08/28/08 12:25:58 PM myOpen[1](1295.5) myOpen[0](1295)

      I had previously searched through the forum trying to find posts that relate, but I did not see Josh's post. Thanks for pointing it out.

      Regards,

      David

      Comment

      Latest Posts

      Collapse

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