There is the State.SetDefaults for inputs and State.Configure for globals for basic use, I understand.
But I am wondering about data persistence; particularly if I have to restart NT8 for any reason, including a where State.Terminated was not called (e.g. computer crash).
Easiest to use an example:
Suppose I have a strategy that has an input "MinDailyProfit". If set to zero, it is disabled, but suppose it is set to $500.
In OnExecutionUpdate() I can check how much the Strategy has made today, using:
SystemPerformance.AllTrades.TradesPerformance.NetP rofit
So...first question is, what net profit does that return? Is it only trades place by THIS strategy, and for today (and is it by session actually, not day)?
In State.SetDefaults, I have a variable, pDaily, set that way:
pDaily = SystemPerformance.AllTrades.TradesPerformance.NetP rofit;
Then in OnExecutionUpdate, I can do this:
if (Position.Quantity == 0)
{
if (DailyMinTarget > 0 && SystemPerformance.AllTrades.TradesPerformance.NetProfit - pDaily > DailyMinTarget)
{
// These are "just in case", like if there's a reversal -to make sure I'm flat. But may not be needed
ExitLong("Daily Target", "Long");
ExitShort("Daily Target", "Short");
Print($"\n\nNetProfit (${SystemPerformance.AllTrades.TradesPerformance.NetProfit}) - pDaily (${pDaily}) > DailyMinTarget (${DailyMinTarget}");
Print($"Daily Profit Hit! Set dailyLimitHit = true\n");
dailyLimitHit = true;
}
}
It is my understanding that if I have to restart, that even w/o my pDaily starting amount, NT runs through historical data and would end up setting dailyLimitHit back to true based on that(?)
If so... what about if my strategy uses a proprietary signal which cannot work on history?
That being the case, in OnBarUpdate() I may as well have this at the top:
if (State != State.Historical)
return?
Correct? And in that case, my use of pDaily should handle this case and re-set dailyLimitHit = true(?)
Is there some tutorial somewhere that teaches exactly how NT calls the strategy with each different state change, like what order they are called?
And perhaps how to deal with data persistence (saving and reading back in variable values)?

Comment