NinjaTrader Support Forum  

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

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-18-2012, 08:20 AM   #1
egan857
Senior Member
 
Join Date: Jan 2012
Location: Austin Texas
Posts: 126
Thanks: 31
Thanked 4 times in 4 posts
Default Fundamental Data in IB

Hi, I'm using Interactive Brokers and have a strategy based on daily bars. Most of the strategy only needs three bars (today, yesterday, day before), but I also want the average daily volume, and I honestly don't care if it's 10-, 20-, or 30-day volume and I don't care if it's exponential or simple average.

My strategy uses the variable VOLMA(10)[1], which means I need to set Min Bars Required to 11 and Days To Load to 22 (double the bars because it's using an exponential average).

To reduce the number of bars required, I tried using FundamentalDataType : AverageDailyVolume, but it appears that IB doesn't support this.

So, does IB support AverageDailyVolume?

If yes, how do I get the AverageDailyVolume from IB? I used the sample code in the reference manual under FundamentalDataEventArgs.

If no, is there a more efficient way to calculate the average volume than VOLMA? For example, is there a way to get a simple moving average for the last 10 daily bars, which would allow me to reduce Days To Load from 22 to 11?
egan857 is offline  
Reply With Quote
Old 01-18-2012, 08:32 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi egan857,

You would need to check with IB if they support the average volume data. If you want to show what you've tried so far with OnFundamentalData() I'm happy to verify the technique.

Best may be to manually calculate an average of volume, using your preferred averaging technique. This is not computationally expensive, even with CalculateOnBarClose = false. Any performance gains reducing minimum bars required from 20 bars to 10 is also negligible / unnoticeable.

double myVolume = SMA(VOL(), 10)[0];
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-18-2012, 11:45 AM   #3
egan857
Senior Member
 
Join Date: Jan 2012
Location: Austin Texas
Posts: 126
Thanks: 31
Thanked 4 times in 4 posts
Default

Hi RyanM,

I lifted the code for OnFundamentalData straight from the reference manual, so if it doesn't work I'm just going to assume IB doesn't support it.

Thank you for the alternate average calculation. I'm not concerned with performance as much as I'm concerned about the amount of historical data that has to be loaded.

Here's the odd thing. Even using the formula SMA(VOL(),10)[1], the strategy requires Days To Load to be at least 20. I can understand that happening with VOLMA(10)[1] because it's an exponential moving average, but SMA is a simple average. Why would it require twice as many bars as the size of the average? I'm sure there's nothing else in the code that looks back more than 10 bars.

If you know why this is happening, please let me know. If you've never seen this before, it's not important enough to investigate. The workaround is simple: set Days To Load to 20. I'm trying to increase the number of symbols I can load before getting the dreaded "pacing problem" error.

The other workaround, of course, is to upgrade to Kinetick, which will probably happen very soon.
egan857 is offline  
Reply With Quote
Old 01-18-2012, 12:21 PM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Thanks for the reply. I see your motivation to reduce historical data requests now. If you're using daily bars, you could use the free connection to Kinetick to load this and wouldn't run into IB pacing limits. You can connect to both at the same time, and if Kinetick is first it will be used for daily charts.

The strategy shouldn't require that minimum bars required is set to 20. You could set lower, but will typically want it set it to at least the largest lookback used for your indicator calculations.

I've not seen where the strategy requires minimum bars setting of 20. Is it overwriting your input here?
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-18-2012, 12:54 PM   #5
egan857
Senior Member
 
Join Date: Jan 2012
Location: Austin Texas
Posts: 126
Thanks: 31
Thanked 4 times in 4 posts
Default

Actually, this is a multi-timeframe strategy with 3 timeframes: daily (goes back 10 days for avg volume, 2 days for price history, plus today); minute (goes back 10 bars); and minute for symbol DIA (also 10 bars). So I can't benefit from free Kinetick and I'm making IB grab at least 30 bars of history. The best I could hope for is to reduce that number to 22 by using fundamental data, and this issue is forcing me to pull in 40 bars (20 daily bars plus 10 1-min plus 10 1-min DIA).

When I start the strategy with Min Bars Required set to less than 11 or Days To Load to less than 20, it will enable (there are some combinations of settings where it won't even enable), but it'll never qualify for a strategy, even when I loosen the entry conditions wide open. It's not overwriting the input, it's just not enabling, or it's enabling and not firing, based on the inputs I enter.
egan857 is offline  
Reply With Quote
Old 01-18-2012, 01:33 PM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

I see. Minimum bars required does need to be satisfied for all series in the strategy. I would check log tab of control center when it doesn't enter to see if there are any error messages.

The best choice that I can see here is supplementing the IB connection with a data only provider like Kinetick, so that you're not running into pacing limits and can just focus on designing the strategy you want. You may be able to save a day or two here and there in your code, but it will be lot more convenient for you not having a download size restriction.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-18-2012, 01:45 PM   #7
egan857
Senior Member
 
Join Date: Jan 2012
Location: Austin Texas
Posts: 126
Thanks: 31
Thanked 4 times in 4 posts
Default

Hi RyanM,

I agree. The best solution is to supplement the feed with Kinetick, which is what I just did. I've been messing with this all day and most of yesterday, so it's already cost me as much as a month's worth of Kinetick.

As always, thanks for your help.
egan857 is offline  
Reply With Quote
Old 01-18-2012, 01:50 PM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Great to hear. I'm sure it will work much better for you. Have a great day and please let us know if we can be of further assistance.
NinjaTrader_RyanM is offline  
Reply With Quote
The following user says thank you to NinjaTrader_RyanM for this post:
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
Convert IB Real-time Data into Historical data ghtrader Connecting 1 09-19-2011 03:37 PM
I have 1 min data off IB but no tick data for range bars dcmdp Charting 1 03-04-2011 02:21 PM
IB: Error in requesting historical data from IB Asing Connecting 18 07-19-2010 09:54 AM
Fundamental screens/backtests? oyz79 Miscellaneous Support 2 01-17-2010 02:01 PM
IB fundamental data in Strategy AnalyserHi all, OLIVER97 General Programming 3 07-25-2008 03:08 AM


All times are GMT -6. The time now is 07:10 AM.