Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Nested indicators - synchronisity and onbarupdate event
Collapse
X
-
Hello b16_aln,
Thank you for your reply.
I have addressed your questions below:- the onbarupdate event gets fired from the ChartControl of owner chart?
- OnBarUpdate() is an event driven method and it is called whenever a bar is updated. It is driven by the input series for the script, and in the case of multi-timeframe and instrument scripts that call AddDataSeries() there will be additional calls of OnBarUpdate() for each time an added series is updated as well. OnBarUpdate() is not tied to ChartControl; it is also called in the case of a script that is not on a chart, like a strategy run from the strategies tab of the Control Center or a SuperDOM indicator. It is tied to and driven by Bars objects of a data series.
- Only base1 will receive the Onbarupdate trigger ?
- base1 will receive OnBarUpdate() and then the 3 options I mentioned in my previous post are ways to ensure that OnBarUpdate() will function and be called for the hosted script, such as ad1. It is not that base1 is the only script that will receive OnBarUpdate() events for its bars objects, the concept is that you must ensure that the bars objects() from the hosted/child script are synced properly to receive OnBarUpdate() events as well
- In order for ad1 to receive an onbarupdate trigger I need to call the Update method from base1?
- Calling Update() is one way to ensure that the hosted script, such as ad1, would receive OnBarUpdate() triggers. There is a reference sample script that demonstrates how to expose indicator values that are not plots found here:
- https://ninjatrader.com/support/help...alues_that.htm
- In this example, the strategy SampleBoolSeriesStrategy is the host script and it calls the indicator SampleBoolSeries, the hosted script. If you search for Update() in SampleBoolSeries.cs you should see it in line 120 where Update() is called to ensure exposedVariable is up-to-date when it is called in the print statement in line 79 of the strategy script SampleBoolSeries.Strategy.cs
Your concern about a script being updated twice is not correct; if the values are already up to date, Update() will not be run. This is noted in the definition on the following page:
I hope this helps to clarify. Please don't hesitate to reach out with any additional questions or concerns.
Leave a comment:
- the onbarupdate event gets fired from the ChartControl of owner chart?
-
Hello Emily,
Thank you for the detailed response and suggestions.
To clarify regarding onbarupdate and nested indicators;- the onbarupdate event gets fired from the ChartControl of owner chart?
- Only base1 will receive the Onbarupdate trigger ?
- In order for ad1 to receive an onbarupdate trigger I need to call the Update method from base1?
ThanksLast edited by b16_aln; 07-13-2023, 01:57 AM.
Leave a comment:
-
Hello b16_aln,
Thank you for your post.
One thing to note, as mentioned on the help guide page for OnStateChange(), is that "Resources created in State.Configure and not disposed of immediately will be kept and utilized if the NinjaScript object resides in grids (e.g. Strategy tab on Control Center), even if it is not enabled. Try to create resources in State.Historical or State.DataLoaded instead, if possible." I am bringing this up since you mentioned you will declare and instantiate indicators in State.Configure; this could potentially result in a performance impact and a better practice would be to do this in State.Historical or State.DataLoaded.
As for the states that the indicators will go through or if the host indicator (base1) will wait in a certain state for the hosted indicators (ad1) to reach a certain state, there is no rule of thumb to go by. You could add prints inside of each indicator and review the output in the NinjaScript Output window to understand which state each indicator is in and when.
What you would be doing by calling the hosted indicator(s) and saving them to their own instance would simply store a reference to that specific indicator instance so that it may be reused throughout the script. This is described on the NinjaScript Best Practices page and, as it mentions there, this practice is by no means a requirement and this process does not need to be followed strictly:
To ensure OnBarUpdate() functionality of a hosted indicator within a host script, there are three options:
1) Calling Update on the hosted indicator within the host script
2) Including a plot in the hosted indicator and accessing the plot in the host script
3) Including a plot in the hosted indicator and adding the indicator to the chart with AddChartIndicator (this is for strategies only and would not apply in your case of an indicator calling other indicators)
For more information regarding OnBarUpdate():
Please let us know if we may be of further assistance.
Leave a comment:
-
Nested indicators - synchronisity and onbarupdate event
I want to have a base indicator "base1" which can call and run other indicators e.g "ad1", "ad2" etc
I will declare "ad1" and instantiate in "base2" state= configure
First question; is will "ad1" be added to "base1" in a syncronous fashion? i.e will base1 wait in state configure until ad1 has reached a certain state and what state willl that be?
Second question; Once both base1 and ad1 are instantiated, will they both receive onbarupdates at the same time and how to then get a value from ad1 output into base1 in a syncronous fashion. i.e I would like onbarupdate runs on ad2 which then outputs a value back to base1 will then waits for next onbarupdate.
ThanksTags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Pointtoni, Yesterday, 11:41 PM
|
3 responses
25 views
0 likes
|
Last Post
![]()
by jenacie.com
Today, 12:47 PM
|
||
Started by DayTradingDEMON, Yesterday, 02:10 PM
|
5 responses
31 views
0 likes
|
Last Post
![]() |
||
Started by Nate G, 03-17-2025, 02:53 PM
|
4 responses
63 views
1 like
|
Last Post
![]()
by timko
Today, 11:13 AM
|
||
Started by several, 03-18-2025, 03:53 AM
|
11 responses
176 views
1 like
|
Last Post
![]()
by timko
Today, 10:53 AM
|
||
Started by Amelie4262, Today, 10:45 AM
|
0 responses
10 views
0 likes
|
Last Post
![]()
by Amelie4262
Today, 10:45 AM
|
Leave a comment: