Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetBar Functionality

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

    GetBar Functionality

    I'm using the GetBar function to find bars between two data series. I am using a 2500 Volume chart as the main series and 1 tick data as the secondary series. When I try to find a bar in the secondary series I believe that it is not finding the correct bar.

    For example:
    I am trying find the start and end bars for the session. The instrument i am using is ES. The first series is 2500 Volume bars, the secondary series is 1 Tick bars. I have a rectangle drawn on the start and end bars for the day. I use the following code:

    leftBarsAgo = BarsArray[1].GetBar(Times[0][globalLine.StartBarsAgo]);
    rightBarsAgo = BarsArray[1].GetBar(Times[0][globalLine.EndBarsAgo]);
    since the getBar is arranged in the opposite direction of Times Dataseries I use the following:
    rightBarsAgo = Times[1].Count - rightBarsAgo;
    leftBarsAgo = Times[1].Count - leftBarsAgo;

    Times[1][rightBarsAgo] is equal to 4/2/2014 1:14:59
    Times[1][rightBarsAgo - 86] is still equal to 4/2/2014, so I am missing 86 ticks of data because it is not being aligned properly. I believe this is because ninjatrader is finding the first instance of 4/2/2014 1:14:59 and returning this bar. I guess this is not unexpected since the times are the same, but these bars are not aligned. The 2500V bar last bar is not returning the corresponding last tick. My question is, is GetBar optimized in anyway to efficiently find bars, or is it simply comparing each date and moving to the next bar?
    Last edited by habibalex; 04-03-2014, 12:07 AM.

    #2
    habibalex, it compares the timestamps and would return the 1st bar from oldest to newest. I tried to reproduce with your chart combo on Kinetick but did not see any unexpected outcomes so far, I've used the start end timestamps of the 2500 ES Volume from yesterday on ETH hours as reference stamps and check from both BarsInProgress.

    public class GetBarsTest : Indicator
    {
    private DateTime ref1 = new DateTime(2014, 04, 02, 17, 14, 59);
    private DateTime ref2 = new DateTime(2014, 04, 01, 18, 05, 16);

    protected override void Initialize()
    {
    Overlay = true;
    Add(PeriodType.Tick, 1);
    }

    protected override void OnBarUpdate()
    {
    if (ToDay(Time[0]) == 20140402 && ToTime(Time[0]) >= ToTime(ref1) && BarsInProgress == 0)
    {
    int barsAgo1 = CurrentBars[1] - BarsArray[1].GetBar(ref1);
    int barsAgo2 = CurrentBar - Bars.GetBar(ref1);

    int barsAgo3 = CurrentBars[1] - BarsArray[1].GetBar(ref2);
    int barsAgo4 = CurrentBar - Bars.GetBar(ref2);

    Print(CurrentBar + " " + Time[0] + " 1Tick: " + barsAgo1 + " 2500V: " + barsAgo2 + " 1Tick: " + barsAgo3 + " 2500V: " + barsAgo4);
    }
    }
    }

    Comment

    Latest Posts

    Collapse

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