I've found knowing when to implement either in a strategy much more difficult. Anyone have any good rules on when they like to use a double vs series double? Would you use a series double for an indicator output in the strategy?
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
When to use double vs Series<double>
Collapse
X
-
When to use double vs Series<double>
Been working on writing a strategy in NinjaTrader for the last 2 months and so far the hardest part for me has been understanding when to initialize a variable as a private double or a private Series<double>. Ironically it's been easier to understand when an indicator requires either; is your number based on a chart value? If yes then it's most likely a double. Is it a static value, or at least static when it's called to update? It's probably a double.
I've found knowing when to implement either in a strategy much more difficult. Anyone have any good rules on when they like to use a double vs series double? Would you use a series double for an indicator output in the strategy?Tags: None
-
Think deeper.
If you need to maintain a value on a per bar basis -- then you need a Series.
Note I said 'maintain' -- this means more that just 'calculate'.
For ex, if you need the past values from past calculations to calculate the newest value.
See that part about "needing past values"? Well, that's how you know you need a Series.
The results of past calculations, one result per bar, can be easily maintained in a Series.
Once you see the elegance of it all, you can then realize that the whole point of the Series
concept is to maintain past values on a per bar basis.
On the other hand, some times all you care about is the current value of something,
such as the current Unrealized Profit, or the current total of all your losses during
the current session. You usually don't need these values saved on a per bar basis, the
current value is independent of the bars where the trades occurred, and this current
up to date value is always what you want to know. You don't care about the PnL 2 or
3 bars ago, like you might when accessing Close[2] or EMA(34)[3].
See the difference?
It boils down to needing 'past' values vs needing just the 'current' value.
Even if all you need is the 'current' value, but you need the 'past' values to get to
that 'current' value, well, guess what, you'll still need a Series for those 'past' values,
but only if those past values really mean: one past value per each bar.
Burn this into your brain: a Series means saving values on a per bar basis.
If you don't need to do that, you don't need a Series.Last edited by bltdavid; 09-12-2021, 10:56 PM.
-
bltdavid Thanks for the reply. So if someone was to sum it up the answer would simply be "to have access to a historical value at a future date?" I would assume this is why most indicators that use a rolling window of values require a series - because they would need the values stored through that entire rolling window?
On the opposite hand a double would simply be the value at that instant and nothing else?
I'm working up a strategy and I'd like to monitor the change in a variable over time and the variable is made up of several sub variables. If I was to plot my variable would I then need to make it a series (because the plot should be holding historical data) in which case all the variables making up the plotted variables would also need to be a series?
Comment
-
Yes, "past values" is exactly equal to "historical values".
The answer is "yes" on all counts.
I think you have it.
I might add this: when the word "plot" is used, then, by definition,
this involves "historical values" (Why? Because OnRender occasionally
must redraw the entire chart, and each individual indicator's OnRender
must redraw their own plots, so all plot data is stored in a Series. Why?
Because "past values on a per bar basis" is exactly what a Plot is.)
In other words,
"Every Plot, by definition, has a Series<double> associated with it".
Last edited by bltdavid; 09-15-2021, 01:06 AM.
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
147 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,282 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment