NexusFi: Find Your Edge


Home Menu

 





New OnStartUp() method in NT7 B8


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one aslan with 3 posts (5 thanks)
    2. looks_two bukkan with 1 posts (0 thanks)
    3. looks_3 gregid with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,997 views
    2. thumb_up 6 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
 

New OnStartUp() method in NT7 B8

 
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127

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.

Started this thread
Thanked by:

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Tao te Trade: way of the WLD
24 thanks
Spoo-nalysis ES e-mini futures S&P 500
19 thanks
Bigger Wins or Fewer Losses?
19 thanks
GFIs1 1 DAX trade per day journal
16 thanks
 
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623


Excellent news! No more "myInit" or whatever else one used to call it!

 
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

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.

Baruch

 
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271

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

 
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127


baruchs View Post
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.
Baruch

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.

Started this thread
 
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


bukkan View Post
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

[off-topic]

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 .

[/off-topic]

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter
Thanked by:
 
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127


sam028 View Post
[off-topic]

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 .

[/off-topic]

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.

Started this thread
Thanked by:

 



Last Updated on February 5, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts