See image below, Signal Ouput was generated as 35 and Value Ouput was 12855 in on On Bar Update. However after the backtest ended the UI did not update and still show 0.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Save Dynamic Variables In Template
Collapse
X
-
Save Dynamic Variables In Template
I have 2 integers that are randomly generated on State.Configure and OnBarUpdate each strategy analyzer backtest run, after they are generated how I can save them as part of the template or as NinjaScript Properties?
See image below, Signal Ouput was generated as 35 and Value Ouput was 12855 in on On Bar Update. However after the backtest ended the UI did not update and still show 0.
Tags: None
-
Hello JakeOfSpades,
Thanks for your post.
I wouldn't expect the UI to know it should update if values are changed within the script and not from the UI (or from an optimizer.)
You could consider adding your own functionality that you could enable "Write template after backtest" which writes the strategy's public properties to a file. You could have the file formatted like the template and also write it to the Documents\NinjaTrader 8\templates\Strategy\YOURSTRAEGY\ folder and NinjaTrader will see this as a regular strategy template.
We have an example that demonstrates using a StreamWriter, but you may find an XmlWriter to be more suitable.
SampleStreamWriter - https://ninjatrader.com/support/help...o_write_to.htm
XmlWriter (publicly available resource) - https://docs.microsoft.com/en-us/dot...r?view=net-4.8
You could try using State.Terminated (after State.DataLoaded has been reached, so you know you are working with the strategy instance that is being backtested) or checking if you are on the last bar of the data series (CurrentBar == Bars.Count-2) to trigger your behaviors to write your homemade template at the end of the backtest.
(For more information on NinjaScript states and the lifecycle of NinjaScript objects, please see below.)
OnStateChange - https://ninjatrader.com/support/help...tatechange.htm
NinjaScript LifeCycle - https://ninjatrader.com/support/help...fecycle_of.htm
We look forward to assisting.
-
The property grid is designed as input to your strategy class.Originally posted by JakeOfSpades View PostI have 2 integers that are randomly generated on State.Configure and OnBarUpdate each strategy analyzer backtest run, after they are generated how I can save them as part of the template or as NinjaScript Properties?
See image below, Signal Output was generated as 35 and Value Output was 12855 in on On Bar Update. However after the backtest ended the UI did not update and still show 0.
It is not designed as output.
property grid != Xml template
(Although they are closely related, and feed each
other at key moments)
Are these "Output" variable public properties?
(It looks like yes, since they're in the property grid)
Are you right clicking and saving a strategy template immediately
after you finish your backtest run?
Do you reset these variables to '0' in State.SetDefaults?
Frankly, regardless of your answers, I agree with support.
You're going about this wrong, you should stop what you're
doing and use a custom output file solution.
When the backtest completes, write the values to a file.
When a backtest starts, read the values from the file.
Don't fight The Man. Just go around him.
Comment
-
I will try this, what if I ran say a optimization or walk-forward instead of a backtest. It will generate every template per optimization result. How would I link which template is associated with each optimization result?Originally posted by NinjaTrader_Jim View PostHello JakeOfSpades,
Thanks for your post.
I wouldn't expect the UI to know it should update if values are changed within the script and not from the UI (or from an optimizer.)
You could consider adding your own functionality that you could enable "Write template after backtest" which writes the strategy's public properties to a file. You could have the file formatted like the template and also write it to the Documents\NinjaTrader 8\templates\Strategy\YOURSTRAEGY\ folder and NinjaTrader will see this as a regular strategy template.
We have an example that demonstrates using a StreamWriter, but you may find an XmlWriter to be more suitable.
SampleStreamWriter - https://ninjatrader.com/support/help...o_write_to.htm
XmlWriter (publicly available resource) - https://docs.microsoft.com/en-us/dot...r?view=net-4.8
You could try using State.Terminated (after State.DataLoaded has been reached, so you know you are working with the strategy instance that is being backtested) or checking if you are on the last bar of the data series (CurrentBar == Bars.Count-2) to trigger your behaviors to write your homemade template at the end of the backtest.
(For more information on NinjaScript states and the lifecycle of NinjaScript objects, please see below.)
OnStateChange - https://ninjatrader.com/support/help...tatechange.htm
NinjaScript LifeCycle - https://ninjatrader.com/support/help...fecycle_of.htm
We look forward to assisting.
Comment
-
Hello JakeOfSpades,
We would have to think outside the box since we would be getting into unsupported territory, but you may wish to consider using a custom Optimization Fitness Metric so when the strategy gets weighed against others, you can access the strategy from the Optimization Fitness Metric, get your public properties and create your homemade template in the same fashion. You could then name the templates by their performance value to quickly see which one was the best.
Optimization Fitness Metrics are rather simple, and are open source in the platform. Documentation on these NinjaScript objects can be found below.
We look forward to assisting.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
54 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
72 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment