Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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);
    }
    }
    }
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    2 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    11 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    10 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    12 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,982 views
    3 likes
    Last Post jhudas88  
    Working...
    X