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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X