Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieving secondary series bar number for specific time

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

    Retrieving secondary series bar number for specific time

    Hi,

    I would appreciate your help with solving the below issue.

    For my strategy, I am trying to get the difference in numbers between the current bar and the bar that happened during specific time in the past, as below

    Code:
    int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2006, 12, 18, 9, 0, 0));
    This works fine for the primary data series, however I have a hard time making it work for the secondary data series. I am trying the different combinations of the below but it doesn't work on the Bars.GetBar side. CurrentBars[1] works fine

    Code:
    int barsAgo = CurrentBars[1] - Bars.GetBars(new DateTime(2006, 12, 18, 9, 0, 0))[1];
    Could you help me to figure that out how to adjust the Bars.GetBar to work for the secondary data series?

    Best,

    #2
    Hello Wdmal,

    If you're using the multi-time frame, you don't need to have 2 codes. The same code would work for 2nd data series. Here's an example:

    Code:
        Print(Time[0]);
        Print("BarsInProgress: " + BarsInProgress);
    
        int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2015, 12, 18, 9, 0, 0));
        Print("Bars Ago: " + barsAgo);
    
        Print("");
    Let me know if it works
    I build useful software systems for financial markets
    Generate automated strategies in NinjaTrader : www.stratgen.io

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X