Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Ninjascript under the hood: what I've learned so far...
Collapse
X
-
Originally posted by koganam View PostNo. NT is no longer trolling the cache, because it does not need to. You are referencing a specific named object.
That is the point of OOP. If you specify an object, its location is always known. And you are keeping the object up to date.
Then again, it is really your choice. Stick on a profiler and check it for yourself. In a simple case, it might not make much difference. In most use cases where the indicator has to be referenced multiple times, and COBC is false, you will see what a difference it makes. So much so, that in NT8, NT Development has finally itself adopted the model in its Strategy Builder.
You might want to read this post: it explains how we came to be here now.
ref: http://ninjatrader.com/support/forum...87&postcount=3
I'm brand new to NT, so please forgive me if I'm way off. I appreciate your expertise on the subject.
Leave a comment:
-
Originally posted by YD777 View PostThanks, this is similar to what I always do, except I had to add the dummy variable you suggested. Nice trick. The code does run faster, but I still believe NT's hidden check of completeness would still run each time "dummy = yada_SMA[0[" is encountered in the code (which would now be every bar). I'm sure it's not heavy on resources, but nonetheless seems inefficient and unavoidable since it's occurring in NT code we can't see/change.
That is the point of OOP. If you specify an object, its location is always known. And you are keeping the object up to date.
Then again, it is really your choice. Stick on a profiler and check it for yourself. In a simple case, it might not make much difference. In most use cases where the indicator has to be referenced multiple times, and COBC is false, you will see what a difference it makes. So much so, that in NT8, NT Development has finally itself adopted the model in its Strategy Builder.
You might want to read this post: it explains how we came to be here now.
ref: http://ninjatrader.com/support/forum...87&postcount=3Last edited by koganam; 07-22-2016, 01:54 PM.
Leave a comment:
-
Originally posted by koganam;
[CODEprivate SMA yada_sma; //this is a named instance of the SMA.
double dummy = 0.0; //this dummy variable will hold the value of our named instance.[/CODE]
Code:protected override void OnStartUp() { yada_SMA = SMA(Close, 5); //etc; }
Code:protected override void OnBarUpdate() { dummy = yada_SMA[0]; //et.c. }
Leave a comment:
-
Is there a way in NT8 to bypass this a #FORCE ALL UPDATES?
Should there be?
Just curious....
Leave a comment:
-
Originally posted by YD777 View PostThanks for sharing your experiences, Koganam. Could you post a small example of what you would write in your code to accomplish this? Your solution definitely seems to keep your indicator up to date, but wouldn't it still be subjected to whatever hidden check that NT uses to make sure of this? Maybe I'm missing something.
Leave a comment:
-
Originally posted by YD777 View PostThanks for sharing your experiences, Koganam. Could you post a small example of what you would write in your code to accomplish this? Your solution definitely seems to keep your indicator up to date, but wouldn't it still be subjected to whatever hidden check that NT uses to make sure of this? Maybe I'm missing something.
You have to declare the SMA variable as a class variable.
Then you can assign/instantiate it in OnStartUp().
Then you use it in OnBarUpdate().
Because it was defined as a object type (a named instance of the class), you assign it without the "new" keyword.
Code:private SMA yada_sma; //this is a named instance of the SMA. double dummy = 0.0; //this dummy variable will hold the value of our named instance.
Code:protected override void OnStartUp() { yada_SMA = SMA(Close, 5); //etc; }
Code:protected override void OnBarUpdate() { //here is where you use your named instance; //To force it to update on evey tick, just assign it to a dummy variable, //with local slope or class slope. I use class scope here, as it is, //arguably, more efficient. dummy = yada_SMA[0]; //et.c. }
Leave a comment:
-
Assign a double to your EMA that isn't being called every time in OnBarUpdate.
Leave a comment:
-
Thanks for sharing your experiences, Koganam. Could you post a small example of what you would write in your code to accomplish this? Your solution definitely seems to keep your indicator up to date, but wouldn't it still be subjected to whatever hidden check that NT uses to make sure of this? Maybe I'm missing something.
Leave a comment:
-
My particular questions at this point are:
1) Is there a way to make the indicator run in the background so it does not need to "catch up" when it is later called?
2) Does anyone have any info on how Ninjascript handles "catching up"? I can't imagine this being more efficient than simply calculating on each bar in real time in the first place. Even in strategies' that call an indicator every single bar, the check to see if the indicator is up to date will take a toll (although slight one).
I did not bother because for me, it is simply more intuitive to use a named instance of the indicator, and make it update on every bar. I can then just reference the then, now already current, indicator object. I am not sure if it is necessarily more efficient computationally, but it almost certainly is faster in runtime.
Leave a comment:
-
Hello YD777,
I have submitted a feature request to the product management team for this kind of documentation. I will follow up with more information as it is available. If the feature request already exists, a vote will be added to it. Please let us know if there are any other ways we can help.
Leave a comment:
-
Ninjascript under the hood: what I've learned so far...
Through the Visual Studio debugger and Print() commands, I've learned the following:
1. When an indicator method is encountered in a strategy (e.g. SMA(Period)), the program checks to see if that indicator already exists in the cache, and if it does, then the indicator's OnBarUpdate( ) is run. If that indicator is NOT found in the cache, then a new indicator object is initialized, and then the indicator's OnBarUpdate( ) is run for all bars up to the current bar.
2. Code from an indicator's OnBarUpdate( ) does not run in the background at the close of each bar, but rather only runs when the indicator is referenced in the strategy's OnBarUpdate(). This distinction is obvious in situations when an indicator is only called sporadically from the strategy. For example, let's say you have anything like this in your strategy:
Code:OnBarUpdate() { //statements ... If SMA(Period)[0]>X If EMA(...) //Do something }
If anyone has other details they know of, please let me know.
My particular questions at this point are:
1) Is there a way to make the indicator run in the background so it does not need to "catch up" when it is later called?
2) Does anyone have any info on how Ninjascript handles "catching up"? I can't imagine this being more efficient than simply calculating on each bar in real time in the first place. Even in strategies' that call an indicator every single bar, the check to see if the indicator is up to date will take a toll (although slight one).Last edited by YD777; 07-21-2016, 09:06 AM.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
5 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
214 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
||
Started by TheWhiteDragon, 01-21-2019, 12:44 PM
|
4 responses
547 views
0 likes
|
Last Post
by PaulMohn
Today, 04:09 AM
|
Leave a comment: