Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetBar() has broken my brain!

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

    GetBar() has broken my brain!

    Here is my partial code:

    Code:
                barsAgo = Bars.GetBar(new DateTime(Current.Year,1,1,0,0,0));
                Yhigh = HighestBar(High,barsAgo);
                Print(Yhigh+", "+barsAgo);
                Ylow = LowestBar(Low,barsAgo);
                Print(Ylow+", "+barsAgo);
                Yopen = Open[barsAgo];
                Print(Yopen+", "+barsAgo);
                barsAgo = Bars.GetBar(new DateTime(Current.Year,Current.Month,1,0,0,0));
                Mhigh = HighestBar(High,barsAgo);
                Print(Mhigh+", "+barsAgo);
                Mlow = LowestBar(Low,barsAgo);
                Print(Mlow+", "+barsAgo);
                Mopen = Open[barsAgo];
                Print(Mopen+", "+barsAgo);
                barsAgo = Bars.GetBar(new DateTime(Current.Year,Current.Month,Current.Day,0,0,0));
                Whigh = HighestBar(High,barsAgo);
                Print(Whigh+", "+barsAgo);
                Wlow = LowestBar(Low,barsAgo);
                Print(Wlow+", "+barsAgo);
                Wopen = Open[barsAgo];
                Print(Wopen+", "+barsAgo);
                barsAgo = Bars.GetBar(new DateTime(Current.Year,Current.Month,Current.Day,0,0,0));
                Dhigh = HighestBar(High,barsAgo);
                Print(Dhigh+", "+barsAgo);
                Dlow = LowestBar(Low,barsAgo);
                Print(Dlow+", "+barsAgo);
                Dopen = Open[barsAgo];
                Print(Dopen+", "+barsAgo);
                barsAgo = Bars.GetBar(new DateTime(Current.Year,Current.Month,Current.Day,0,0,0));
                Phigh = HighestBar(High,barsAgo);
                Print(Phigh+", "+barsAgo);
                Plow = LowestBar(Low,barsAgo);
                Print(Plow+", "+barsAgo);
                Popen = Open[barsAgo];
                Print(Popen+", "+barsAgo);
                DrawHorizontalLine("Yhigh",Yhigh, Color.Red, DashStyle.Solid,1);
                DrawHorizontalLine("Ylow",Ylow, Color.Blue, DashStyle.Solid,1);
                DrawHorizontalLine("Yopen",Yopen, Color.Green, DashStyle.Solid,1);
                DrawHorizontalLine("Mhigh",Mhigh, Color.Red, DashStyle.Dash,1);
                DrawHorizontalLine("Mlow",Mlow,Color.Blue,DashStyle.Dash,1);
                DrawHorizontalLine("Mopen",Mopen,Color.Green,DashStyle.Dash,1);
                DrawHorizontalLine("Whigh",Whigh,Color.Red,DashStyle.DashDot,1);
                DrawHorizontalLine("Wlow",Wlow,Color.Blue,DashStyle.DashDot,1);
                DrawHorizontalLine("Wopen",Wopen,Color.Green,DashStyle.DashDot,1);
                DrawHorizontalLine("Dhigh",Dhigh,Color.Red,DashStyle.DashDotDot,1);
                DrawHorizontalLine("Dlow",Dlow,Color.Blue,DashStyle.DashDotDot,1);
                DrawHorizontalLine("Dopen",Dopen,Color.Green,DashStyle.DashDotDot,1);
                 DrawHorizontalLine("Phigh",Phigh,Color.Red,DashStyle.Dot,1);
                DrawHorizontalLine("Plow",Plow,Color.Blue,DashStyle.Dot,1);
                DrawHorizontalLine("Popen",Popen,Color.Green,DashStyle.Dot,1);
                DrawText("YhighText","Years High",20,Yhigh,Color.Black);
                DrawText("YlowText","Years Low",20,Ylow,Color.Black);
                DrawText("YhighText","Years Open",20,Yopen,Color.Black);
                DrawText("MhighText","Months High",20,Mhigh,Color.Black);
                DrawText("MlowText","Months Low",20,Mlow,Color.Black);
                DrawText("MhighText","Months Open",20,Mopen,Color.Black);
                DrawText("WhighText","Weeks High",20,Whigh,Color.Black);
                DrawText("WlowText","Weeks Low",20,Wlow,Color.Black);
                DrawText("WhighText","Weeks Open",20,Wopen,Color.Black);
                DrawText("DphighText","Previous Days High",20,Phigh,Color.Black);
                DrawText("DplowText","Previous Days Low",20,Plow,Color.Black);
                DrawText("DphighText","Previous Days Open",20,Popen,Color.Black);
                DrawText("DhighText","Days High",20,Dhigh,Color.Black);
                DrawText("DlowText","Days Low",20,Dlow,Color.Black);
                DrawText("DhighText","Days Open",20,Dopen,Color.Black);
    My output window shows:

    0, 0
    0, 0
    1113.75, 0
    0, 9993
    0, 9993

    I suppose I have Horizontal lines but not at 1113.75!
    Last edited by Sleeping Troll; 03-16-2010, 04:50 AM.

    #2
    Sleeping Troll, have you already looked at this sample here to help clarify?



    GetBar() would return 0 if you pass in a future DateTime value.

    Comment


      #3
      I have now, and honestly I have before...
      I still am not clear on the need for use of Time[], regardless I can handle some bad values I will just test before plotting.
      Thx for the help!

      Comment


        #4
        For the GetBar() you simply pass in DateTime of interest and then it returns you the interger # of bars ago this was 'true' == 'hit'.

        If the DateTime you passed in is older than what;s loaded as first bar on the chart > the CurrentBar # since this fist bar is used.

        If the DateTime lies in the future, you get 0 returned.

        You may run into issues passing the actual DateTime in (formatting wise), so I would suggest simplifying the code as much as possible and printing the DateTime entered.

        Comment


          #5
          It turns out, I should really learn to pay more attention to my error log!
          I am getting the error:

          DrawText: startBarsAgo out of valid range

          I cannot figure why, I have isolated the offender to this line of code:

          DrawText("YopenText","Years Open",1,Yopen,Color.Black);

          Must be something simple... what am I missing?

          Comment


            #6
            You try accessing bars that are not present at the OnBarUpdate() start, please check into this link here - http://www.ninjatrader-support2.com/...ead.php?t=3170

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            599 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            345 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
            558 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X