![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
If indicator I1 is accessing two vars of indicator I2, is it OK to avoid a redundant call to I2 Update() from the vars get properties and instead just call I2 Update() directly?
From this (I1 code): // I2 vars properties contain Update() Print(I1().var1); Print(I2().var2); To this: // I2 vars properties don't contain a call to Update() I2().Update(); Print(I1().var1); Print(I2().var2); |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
savekad,
I can't think of any reason that would cause any issues. Let us know if you run into any.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
|
Quote:
The way I understood it, we need to Update() in the Property getter because the asynchronous, event-driven nature of NT means that the value may not yet have been updated when we try to access it, so we need to force an update. Somehow, I think this will probably be more of an issue if COBC is false, but I can still envisage a scenario where it could still be an issue with COBC as true. |
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
koganam, can you elaborate?
I think that even if COBC is false, it would still be faster to call OBU just once for any further var accesses than to fire it every time you access a var from the same OBU call of the original indicator (I1 in our case), wouldn't it? |
|
|
|
|
|
#5 |
|
Senior Member
|
It will be faster, as you are evidently calling updates less often. I doubt if it will be accurate, again because one may be accessing a value that has not yet been updated, because the system was off doing something else. Such is the nature of asynchronous events.
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jul 2012
Posts: 158
Thanks: 28
Thanked 4 times in 4 posts
|
So you say that by removing Update() from a var getter, it might be inaccurate to access it even if the access is made right after an explicit call to Update() ?
|
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Update() will only trigger if it needs an Update to get "up to speed". So you wont waste unneeded CPU cycles if the value is already up to date. Its always a good idea to have Update there as an insurance policy to make sure you always have up to date and correct values. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#8 | |
|
Member
Join Date: Feb 2011
Location: Georgia, USA
Posts: 32
Thanks: 17
Thanked 15 times in 9 posts
|
Quote:
I have been wondering about this because I am refactoring some code into multiple indicators to be used by other indicators and strategies. Can you elaborate on your statement, "Update() will only trigger if it needs an Update to get "up to speed"."? I take this to mean that if I call Update() from within a property or from outside the indicator, the OnBarUpdate() method will only be called if it needs to "get up to speed". How does it know whether or not it needs to get up to speed? I was thinking that, for when COBC is true, I could put something like the following in the beginning of the OnBarUpdate() method, but it sounds from your comment that this would be redundant; that NT already manages that. Code:
private int lastBarCalced = -1;
protected override void OnBarUpdate()
{
if (CurrentBar = lastBarCalced) return;
lastBarCalced = CurrentBar;
// continue with the method...
}
Many Thanks. Scott
Scott Daggett
NinjaLaunchPad.com NinjaScript Programmer's Launch Pad Tutorial ebook at ninjalaunchpad.com |
|
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Sure basically its a good idea to add Update() in the property so that when access a value it makes sure that you have the most update to date variables as possible. How it works is it will update to the current CurrentBar index if it is not already there. If COBC=False however this would always force an update since we would have to assume we are not up to date since we have no index to check against as your question lead me believe that is what you are asking on. There is no cost saving measures we could do on COBC = false like what we can on COBC = true. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Brett for this post: |
|
|
|
#10 |
|
Senior Member
|
That sequence seems to be identical to just using "if (FirstTickOfBar)...". No?
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#11 | |
|
Member
Join Date: Feb 2011
Location: Georgia, USA
Posts: 32
Thanks: 17
Thanked 15 times in 9 posts
|
Quote:
Scott
Scott Daggett
NinjaLaunchPad.com NinjaScript Programmer's Launch Pad Tutorial ebook at ninjalaunchpad.com |
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Right if COBC = true you should not have to worry about the extra calls as NT wont force OnBarUpdate to run if it already has processed that bar. If COBC = false however then it would recalculate each time. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Brett for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Basing one Property/Parameter on Another Property/Parameter | gregschr | General Programming | 5 | 08-10-2010 11:31 AM |
| ChartOnly property | David Lean | Indicator Development | 1 | 12-11-2009 07:11 AM |
| Historical property | tamas | Strategy Analyzer | 2 | 06-28-2009 11:46 PM |
| Added Property to Strategy but Not Showing on Property Grid | stocastix | Automated Trading | 2 | 11-07-2008 04:00 PM |
| Make trail stop value update intra bar without indicator update. | dendy | Strategy Development | 26 | 10-21-2007 09:14 AM |