Say you have a random number, and any time you run a backtest via the strategy analyzer you want that number to randomly generate but save for the next backtest. How would you accomplish this?
I have a NinjaScriptProperty of string and by default it's empty "". When I run a backtest it populates and when I print it the NinjaTrader output shows it but the UI doesn't update nor does it save for the next backtest / optimization. I want to be able to run backtest and optimization where the initial iteration the number is randomly generated but any subsequent backtests I want that randomly generated number to save and persist so I can save it as a template or run it out of sample.
Below is a simple example :
#region Using declarations using System; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies {[INDENT]public class RandomPropertyExample : Strategy {[/INDENT][INDENT=2]private System.Random rnd = new Random();[/INDENT][INDENT]protected override void OnStateChange() {[/INDENT][INDENT=2]if (State == State.SetDefaults) {[/INDENT][INDENT=3]randomOutput = "";[/INDENT][INDENT=2]} else if (State == State.Configure) { if (randomOutput == "")[/INDENT][INDENT=3]randomOutput = rnd.Next(1, 7).ToString();[/INDENT][INDENT=2][SIZE=12px][B]Print(randomOutput); //Will print first time but will not save with any subsequent backtests and UI will not update[/B][/SIZE][/INDENT][INDENT]}[/INDENT][INDENT] protected override void OnBarUpdate() {} [NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Signal Output", GroupName = "Time Series", Order = 0)] public string randomOutput { get; set; } }[/INDENT] }
Comment