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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-18-2010, 02:29 PM   #1
bluelou
Senior Member
 
Join Date: Apr 2008
Posts: 503
Thanks: 3
Thanked 1 time in 1 post
Default BarsRequired and min bars required

I'm looking to clear up some issues using BarsRequired and to understand when to use min bars required.

1) In the attached .jpg file is the Initialize() method for a strategy. Will the BarsRequired = 30; statement require 30 bars for each of the 3 preceding Add() statements or only the last Add() statement?

Background:
2) In this particular strategy I use or reference functions that use BarsRequired in a few places and I want to make sure I understand what's happening:

a.] The strategy calls an indicator and this indicator, let's call it Indicator1, has BarsRequired = 16 in its Initialize method.

b.] In the strategy, there is a function which uses Indicator1. This function uses BarsArray[2] which are 1 day bars. The function requires 30 bars. Thats's why I've included BarsRequired = 30 in the strategy Initialize() method.

3) So, according to the simple math I should set DaysToLoad = 16 + 30 = 46 and I set min bars required = 0 since all of the bars required by the strategy are already addressed in the BarsRequired statements

4) However, I'm not able to get the variables to populate with sufficient data unless I set DaysToLoad >= 66.

Questions:
1) Why do I need need to add the 20 extra bars (66 - 46 = 20) to get sufficient data into the function included in my strategy code?

2) If I use BarsRequired throughout my indicator and strategy code will that supersede min bars required? If so, then why would I ever use min bars required? I'd really like to avoid using min bars required b/c it's caused a lot of problems for my strategy.

3) Why does min bars required work differently in Backtest mode vs. Real-time trading? In backtest mode I didn't need BarsRequired statements at all. I just set min bars required = 66 and the code ran properly. But, in strategy mode, if I exclude BarsRequired statements and set DaysToLoad = 66 and min bars required = 66 the code doesn't run. I can't even force an exception or an error message to occur. BTW, I wasted 2 weeks trying to get my code to run before I figured out this difference b/t backtest mode and real-time mode and how to correct for it.

Lastly, while I'm glad I figured this out on my own, I can't believe that in my many requests for help from NT support on this issue that no one mentioned this difference b/t min bars required in backtest vs. real-time mode.
Attached Images
File Type: jpg BarsReq.JPG (19.0 KB, 34 views)
bluelou is offline  
Reply With Quote
Old 08-18-2010, 03:45 PM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

bluelou, we will get back to you tomorrow.
NinjaTrader_Austin is offline  
Reply With Quote
Old 08-18-2010, 03:46 PM   #3
bluelou
Senior Member
 
Join Date: Apr 2008
Posts: 503
Thanks: 3
Thanked 1 time in 1 post
Default

okay, thx for the reply.

BTW, I can send you the code if you'd like to see how min bars required works differently in backtest mode vs. real-time mode.
Last edited by bluelou; 08-19-2010 at 08:04 AM.
bluelou is offline  
Reply With Quote
Old 08-19-2010, 08:28 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

bluelou, here's how it works - DaysToLoad determines how much historical data is loaded on your chart, if you set the min bars to this setting as well, there's no data point to work with as you're adding a daily series to your strategy.

The MinBarsRequired has to be fulfilled for all series in the strategy, then the OnBarUpdate() would be called and the strategy could start calculating.

The BarsRequired in an indicator is for visualization purposes only, you can setup how many bars it should wait from the start of the chart before it would display a value, so you can give it some room to stabilize for example.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-19-2010, 08:48 AM   #5
bluelou
Senior Member
 
Join Date: Apr 2008
Posts: 503
Thanks: 3
Thanked 1 time in 1 post
Default

Bertrand,
That doesn't fully answer my question and I don't agree with you entirely. However, it's not worth debating since it appears that my code is working properly at the moment. Really, my post was for the hapless NT user trying to wrestle with min bars required and to let them know that there's hope.

I have a separate question regarding a problem w/an output log but I'll put that in a separate thread.

Thx,
Lou
Last edited by bluelou; 08-19-2010 at 08:58 AM.
bluelou is offline  
Reply With Quote
Old 07-19-2012, 02:53 AM   #6
adam_norsworthy
Junior Member
 
Join Date: Feb 2012
Location: Canary Islands
Posts: 16
Thanks: 2
Thanked 0 times in 0 posts
Default Behaviour I don't understand with BarsRequired

Hi there...I have a strategy where I have set the BarsRequired to 5. when I run this strategy it doesn't load,. When I set the BarsRequired to 20 it does.

It uses 144 volume bars and the EMA indicator.

My thinking was that if the strategy can load fine with BarsRequired=20, then surely it would load with BarsRequired=5, because if ther are 20 bars on the chart, then of course there are 5!

What am I missing? Many thanks, Adam
adam_norsworthy 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
Bug in BarsRequired and/or Min. Bars Required ChuckAllen Version 7 Beta General Questions & Bug Reports 4 07-23-2010 03:45 PM
Min. bars required for Strategy TAJTrades Strategy Development 1 07-20-2009 01:31 PM
Min. bars required SystemTrading Strategy Development 5 06-11-2009 10:37 AM
Min. Bars Required Question... BigDog008 Automated Trading 3 12-26-2008 11:57 PM
Min Bars required under strategy backtesting Sidhartha Strategy Development 4 04-08-2008 07:17 AM


All times are GMT -6. The time now is 11:41 AM.