Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I've updated my ExportChartData indicator in the downloads/Ninja/Misc section to add some new functionality. Based on some code I found from Mike and some comments from Sam, I'm now trying to convert that Indicator to a Strategy.
I'm getting an exception in the OnBarUpdate method, "Object reference not set to an instance of an object."
Below is the OnBarUpdate area of the Strategy code:
And I've attached the zip file for both the Indicator ExportChartData (works fine) and Strategy ExportData (exception thrown). Any help on this would be greatly appreciated.
FWIW my next steps in the evolution of the code is to try an incorporate Enums for the output file types by playing some more with manipulating DateTime objects and strings, and look at ways to optionally export indicator data as well.
But I need it to work with the current features first!
Thanks for your time and input.
Can you help answer these questions from other members on NexusFi?
Interesting, looks like the compiler took 0 as null and assumed you were comparing CurrentBar to it. And CurrentBar being an int (I believe) and null being a reference ...
MX, you should avoid putting your file stuff in the OnBarUpdate(), and put it in Initialize().
OnBarUpdate() is called every bar update (really ), so it have to be as light as possible, for performance aspects.
So, in your example, you'll just have to write in the file, not open/create it, and not closing it after each bar !!!
So:
- the creation/init of the file: in Initialize() (or OnStartUp() with NT7)
- the close of it in Dispose() (or OnTermination() with NT7).
Hmm, I'm not sure, and can't test it now.
But if it's the problem, you can:
- use a random, or whatever file name
- store your Instrument.FullName+BarsPeriod.Id+BarsPeriod.Value" in a public variable, inside OnBarUpdate()
- rename your file at the end ( File.Move(...)), in Dispose().
I'm not sure if it is an issue, but I'm always open to ways to code things better. I'm at C# 101 right now . Feel free to make it better.
I just ran that 'strat against the S&P500 list that comes with Ninja and my own instrument list of all IShares ETFs (daily data, one year back), and all was fine (one bad ticker exception on the S&P list that I'll look at tomorrow). Personally I think that is pretty cool. I don't do equities but building an S&P500 correlation or covariance matrix using R and Ninja that updates daily would be a good demonstration tool of what can be done for free these days. A good reminder that "edge" is fleeting.
My next journey with this is the enum/DateTime one, neither of which I fully understand but using a non-production utility 'strat (like this) instead of a live trading 'strat takes some pressure off.
The code below works fine with the OnStartUp() and OnTermination() methods. Is whats left in OnBarUpdate() OK? Thanks for taking the time to educate me in writing better code.