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)
Well NT7 Beta 8 was released, and they finally broke down and made a change to add a new method called OnStartUp(). This method is called once before an indicator starts up (after Initialize() and before first call to OnBarUpdate(). It is an ideal place to put your startup code instead of having a static flag and startup routine that you call once out of OnBarUpdate(). Another key item is the Bars var is initialized, which was the main problem with putting code in the Initialize() routine. The signature is
protected override void OnStartUp() {
}
This will help clean code up by allowing you to put code where it belongs.
This routine is also the best place to allocate resources, and then deallocate them in the matching OnTermination() to avoid memory leaks.
Hi,
I'm not so frill about this new function.
I'll continue to use my Init routine. The reason why is that NT makes mistakes, and one mistake I can catch and fix with my own Init.
The mistake is that sometimes when you run a backtest the first bar that you run on is not the first bar of a day. So if you do have some code for each day like if Bars.FirstBarOfSession it won't execute on the first bar in data series and it can be a disaster.
OnStartUp is a very good feature. there are multiple instances of Initialization, onstartup dont have such issues. again not many things can be accessed in init. onstartup solves that prob
It sounds like you are confusing the real purpose of the routine. It is meant for indicator initialization, not functional code. So if you have code that runs for each day, that is not indicator init, and you should continue to run that code in OnBarUpdate(). This routine runs only once before OnBarUpdate() is called and allows for one time startup type functions.
In the grand scheme of things it is fairly minor, but it allows for cleaner code and gets rid of that annoying check at the start of your OnBarUpdate. The other benefit if used properly is to make it easier to get resource allocation/destruction correct, but pairing your allocation and dispose methods in the OnStartUp() and OnTermination() routines.
Of course you don't have to use it, so if you like the way you are doing it, that works too.
OnStartup() and the other features added on Beta 8 are good features, for sure, but this also means we'll not see a non-beta before a long time imho.
If NT guys can add something like OnStartup() on a Beta 8, many things can happen before the final version...
I modified some NT6.5 indicators for let them work with NT7, but I'm not spending to much time on it, as I feel that many things can already change before the final version.
So it might be a good idea to don't go to fast in changing your precious .cs .
I agree the final form of NT7 is aways off, they still have to do a full beta, which will expose more issues as well.
There are enough code breaking changes, that it is getting difficult to keep 6.5 and 7.0 around. I've recently decided to go with 7.0 only with 6.5 as a backup, but I am already waiting for fixes in B9.