Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-14-2011, 07:34 AM   #1
nt2010
Member
 
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default GetDayBar - whats wrong

Hi there,

iīd like to add an requirement to my automated trading strategy.

I like to add a filter - to trade only days, where the close of one day ago was higher then the close of two days ago.

I tryed to implement it this way:

protected override void OnBarUpdate()
....
if ( Bars.GetDayBar(1).Close > Bars.GetDayBar(2).Close && the other requirements)

before adding this filter, everything worked fine. but after adding this filter i get the message:
Error on calling 'OnBarUpdate' method for stratgy xy
-when enableling the strategy.

It would be great if you could give me a hint how to solve the problem.

Thank You !
nt2010 is offline  
Reply With Quote
Old 05-14-2011, 10:50 AM   #2
koganam
Senior Member
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 4,668
Thanks: 31
Thanked 1,938 times in 1,582 posts
Send a message via Skype™ to koganam
Default

GetDayBar() requires a null reference check/escape.

http://www.ninjatrader.com/support/h...?getdaybar.htm
koganam is offline  
Reply With Quote
Old 05-14-2011, 12:33 PM   #3
nt2010
Member
 
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Coganam,

thank you that was easy.
Here the new code for others who have the same problem:


protected override void OnBarUpdate()
....
if ( Bars.GetDayBar(1) != null && Bars.GetDayBar(2) != null && Bars.GetDayBar(1).Close > Bars.GetDayBar(2).Close && the other requirements)

Thanx
nt2010 is offline  
Reply With Quote
Old 05-18-2012, 02:35 AM   #4
fel17
Member
 
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

I have a similar problem, so I try to ask in this thread.

I need history of last 20 days which is queried by GetDayBar (1/2/.../20). The "Days to load" property of the chart is set to 60 - enough for my purposes. The chart itself has 15 or 30 minutes time frame. In the properties of indicator I set "Maximum bars to look back" on infinite.
But I still can't access days 18, 19 and 20. GetDayBar(18 to 20, sometimes already for 16 or 15) is null.

How I can solve this problem?
fel17 is offline  
Reply With Quote
Old 05-18-2012, 05:32 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,468
Thanks: 420
Thanked 1,604 times in 1,569 posts
Default

fel17, are you working in a indicator or strategy here? Single or MultiSeries?

Thanks,
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-18-2012, 05:39 AM   #6
koganam
Senior Member
 
Join Date: Feb 2008
Location: http://omegasigmaindicators.com
Posts: 4,668
Thanks: 31
Thanked 1,938 times in 1,582 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by fel17 View Post
I have a similar problem, so I try to ask in this thread.

I need history of last 20 days which is queried by GetDayBar (1/2/.../20). The "Days to load" property of the chart is set to 60 - enough for my purposes. The chart itself has 15 or 30 minutes time frame. In the properties of indicator I set "Maximum bars to look back" on infinite.
But I still can't access days 18, 19 and 20. GetDayBar(18 to 20, sometimes already for 16 or 15) is null.

How I can solve this problem?
Check your chart to be sure that enough days have been actually loaded. It is not what you ask to load that matters; it is what is actually loaded.
koganam is offline  
Reply With Quote
Old 05-18-2012, 06:19 AM   #7
fel17
Member
 
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
fel17, are you working in a indicator or strategy here? Single or MultiSeries?
Indicator. I don't know what MultiSeries are, I assume I'm working with Single series. I have only one "Value" in one time frame. Basically the easiest case. I also have 3-4 other indicators (provided by NT), but I don't think they disturb my indicator.

Now I have this problem even with GetDayBar (1). I can see in my 15 minutes frame complete yesterday, but GetDayBar(1) = null

Generally, GetDayBar seems to be very instable (buggy?) and uncomfortable for programming. I know, I have to check for NULL value, but what can I do if GetDayBar IS null? How I can force loading of enough history thru coding?
Unfortunately there is no alternative to GetDayBar, besides of PriorDayOHLC which works only for prior day.
fel17 is offline  
Reply With Quote
Old 05-18-2012, 06:39 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,468
Thanks: 420
Thanked 1,604 times in 1,569 posts
Default

Unfortunately there would be supported way to force a loading of the data through code - as koganam advised please double check the chart contains the data you for the complete session you wish to access / build on with the virtual GetDayBar.

For testing, I've attached a simple test indicator for you that work just fine on my ES 06-12 15 min charts running here on 'instrument default' sessions, so the CME US Index Futures ETH / Globex hours.

If there was an issue loading your data from the provider connected to, right click on the chart and select 'Reload Historical Data'.

Thanks,
Attached Files
File Type: cs GetPriorCloses.cs (7.1 KB, 17 views)
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-22-2012, 10:03 AM   #9
fel17
Member
 
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for example Bertrand.

I still do not understand how to load last days and I think this function is a little bit buggy. I've found a workaround: in OnBarUpdate() I return as long GetDayBar(1) is null. I can see in debug output that after 10-20 such returns Day(1) will be loaded and I can query the OHLC values.

Ok, but now I have another problem.
tradingDaysBars in Bars.GetDayBar(int tradingDaysBack) means the number of days back. So GetDayBar(1) = yesterday.
But the real behaviour is different. GetDayBar(1)means first day in the chart, not yesterday! I've checked values and this is definitely true. I have about two months loaded in the chart and I receive OHLC values from first day (two months ago). Is this a bug or feature?
fel17 is offline  
Reply With Quote
Old 05-22-2012, 10:07 AM   #10
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,468
Thanks: 420
Thanked 1,604 times in 1,569 posts
Default

Thanks for the reply, so you would see the behavior you described with my example posted, is this correct? If so, which exact chart, timeframe, datafeed and session template + days loaded setting do yo use on your end?

Then I could attempt reproducing here to check into.

Thanks,
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-22-2012, 10:15 AM   #11
fel17
Member
 
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

I just looked your code, I did not run your indicator with real data.

Now I checked OHLC values for GetDayBar(2). High and Low are the same as for GetDayBar(1), but different in the chart. No clue...
fel17 is offline  
Reply With Quote
Old 05-22-2012, 10:23 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,468
Thanks: 420
Thanked 1,604 times in 1,569 posts
Default

I would suggest giving the sample code prepared a run on your end and chart to doublecheck - you would also need to be mindful when exactly accessing the values and comparing, so Time[0] print + CurrentBar print is needed in debugging - if you plot / draw the results it would be more visual and thus likely easier.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-22-2012, 10:28 AM   #13
fel17
Member
 
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Just tell me what does GetDayBar(1) mean?
Yesterday or "depends on"?
fel17 is offline  
Reply With Quote
Old 05-22-2012, 10:36 AM   #14
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,468
Thanks: 420
Thanked 1,604 times in 1,569 posts
Default

...the previous trading session. Please see attached, ES 5 min running on RTH hours, highlighted is the previous session close level > compare to the plotted GetDayBar(1).Close in orange please for reference.
Attached Images
File Type: png fel17_GPC.PNG (128.2 KB, 13 views)
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-22-2012, 10:44 AM   #15
fel17
Member
 
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, I would also expect this behaviour. It corresponds to manual.

But in my case I get the values from the first day in the chart, which is 2 month ago. I can see these values if I scroll to the start of the chart.

I work with 15min chart for FGBL future, as example.
fel17 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
Bars.GetDayBar on Multi Time Frame AntiMatter General Programming 6 04-23-2012 07:38 AM
whats wrong here? meegwell Strategy Analyzer 14 02-07-2011 02:05 PM
Bars.GetDayBar(1).Time returning null drolles General Programming 9 01-18-2011 03:42 AM
Whats wrong Baruch Strategy Development 7 03-24-2009 05:49 AM
Whats new changes Bogan7 Suggestions And Feedback 1 11-01-2007 04:07 PM


All times are GMT -6. The time now is 04:22 PM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.