NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 03-15-2010, 08:44 PM   #1
Sleeping Troll
Senior Member
 
Join Date: Mar 2010
Location: Tampa, FL
Posts: 186
Thanks: 0
Thanked 3 times in 1 post
Send a message via Yahoo to Sleeping Troll
Default GetBar() returning 0's

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 at 04:50 AM.
Sleeping Troll is offline  
Reply With Quote
Old 03-16-2010, 05:09 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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

http://www.ninjatrader-support2.com/...ad.php?t=19176

GetBar() would return 0 if you pass in a future DateTime value.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-16-2010, 05:56 AM   #3
Sleeping Troll
Senior Member
 
Join Date: Mar 2010
Location: Tampa, FL
Posts: 186
Thanks: 0
Thanked 3 times in 1 post
Send a message via Yahoo to Sleeping Troll
Default

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!
Sleeping Troll is offline  
Reply With Quote
Old 03-16-2010, 06:16 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-16-2010, 06:56 AM   #5
Sleeping Troll
Senior Member
 
Join Date: Mar 2010
Location: Tampa, FL
Posts: 186
Thanks: 0
Thanked 3 times in 1 post
Send a message via Yahoo to Sleeping Troll
Default

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?
Sleeping Troll is offline  
Reply With Quote
Old 03-16-2010, 07:11 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetBar() vs Bars.GetBar() aslane Indicator Development 1 11-04-2009 09:47 AM
GetBar() performance aslane Indicator Development 5 10-31-2009 02:01 PM
GetBar() Question r2kTrader Strategy Development 2 08-30-2009 01:07 PM
GetBar value at tick level binwang2 General Programming 1 08-19-2009 12:31 PM
Bars.GetBar(time) Lost Trader Indicator Development 2 04-02-2009 12:22 PM


All times are GMT -6. The time now is 10:36 PM.