Most of the methods in Backtest do loops of symbols or bars. This makes the use of a simple "return;" command unusable programmatically as a way to exit the strategy on a certain condition because it will simply continue the current loop.
A C# programmatic way to do what the Cancel button does in the SW while a strategy is running would be helpful.
A C# programmatic way to do what the Cancel button does in the SW while a strategy is running would be helpful.
Rename
CODE:
//execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if(idx > 5) throw new Exception("Canceled"); WriteToDebugLog(idx); }
Good thinking, throwing an exception does effectively cancel the strategy!
Thanks @Eugene. The problem with this approach is that it exits the loop for the current bar / symbol, but then starts loop again with the next symbol, repeating this error checking until all symbols are processed. I was looking for a function that would exit the strategy, not just the loop element and "Cancel" the current strategy like I presume the Cancel button does.
This has the same practical effect as using "return;", which does the same thing.
In my particular case I am interested in the time span / count of *global* total bars (synchronized bars.Count) for all symbols, not for individual symbols.
This has the same practical effect as using "return;", which does the same thing.
In my particular case I am interested in the time span / count of *global* total bars (synchronized bars.Count) for all symbols, not for individual symbols.
Your Response
Post
Edit Post
Login is required