![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
|
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 ! |
|
|
|
|
|
#2 |
|
Senior Member
|
GetDayBar() requires a null reference check/escape.
http://www.ninjatrader.com/support/h...?getdaybar.htm |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
Member
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
fel17, are you working in a indicator or strategy here? Single or MultiSeries?
Thanks,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Senior Member
|
Quote:
|
|
|
|
|
|
|
#7 | |
|
Member
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
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. |
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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?
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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... |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Just tell me what does GetDayBar(1) mean?
Yesterday or "depends on"? |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
...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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Aug 2009
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 01:05 PM |
| Bars.GetDayBar(1).Time returning null | drolles | General Programming | 9 | 01-18-2011 02: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 |