- ago
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.
1
380
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
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);       }
0
Best Answer
Glitch8
 ( 12.10% )
- ago
#2
Good thinking, throwing an exception does effectively cancel the strategy!
0
- ago
#3
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.
0

Reply

Bookmark

Sort