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
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
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.JimNinjaTrader Customer Service
-
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
-
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.JimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
22 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by Davidtowleii, Today, 12:15 AM
|
0 responses
3 views
0 likes
|
Last Post
by Davidtowleii
Today, 12:15 AM
|
||
Started by guillembm, Yesterday, 11:25 AM
|
2 responses
9 views
0 likes
|
Last Post
by guillembm
Yesterday, 11:58 PM
|
||
Started by junkone, 04-21-2024, 07:17 AM
|
9 responses
70 views
0 likes
|
Last Post
by jeronymite
Yesterday, 11:51 PM
|
||
Started by mgco4you, Yesterday, 09:46 PM
|
1 response
14 views
0 likes
|
Last Post Yesterday, 09:56 PM |
Comment