I am trying to use the record structure in C# version 9 and running into some problems. Is WL8 up to that version?
Rename
C# 9 was released with .NET 5 in 2020. Of course WL8 supports it.
I ran a simple test for C# 9.0 support. I created a C# strategy, not externally linked. I added a few lines in Execute(...) that are for C# 8.0 and above. The code follows...
When you compile the code, the following errors occur:

Maybe something is wrong in my environment. But, if not then this seems like it may be a WL 8 problem. I'm using build 37 with the latest extensions.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript2 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { var td = bars.DateTimes[idx].TimeOfDay; if (td is { Hours: 10, Minutes: <= 7 }) { return; } if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }
When you compile the code, the following errors occur:
Maybe something is wrong in my environment. But, if not then this seems like it may be a WL 8 problem. I'm using build 37 with the latest extensions.
Hi @Eugene. Thanks for confirming. Here is the code that is throwing an error
CODE:
public class IntradayOptionDemo : UserStrategyBase { public record OptionContracts(string optSymbol, double optStrike, double price, double delta) { }
QUOTE:
Compiled at 6/21/2023 11:26:13
14: The type or namespace name 'record' could not be found (are you missing a using directive or an assembly reference?)
14: 'IntradayOptionDemo.OptionContracts(string, double, double, double)' must declare a body because it is not marked abstract, extern, or partial
119: The type or namespace name 'OptionContracts' could not be found (are you missing a using directive or an assembly reference?)
137: The type or namespace name 'OptionContracts' could not be found (are you missing a using directive or an assembly reference?)
147: The name 'OptionContractsList' does not exist in the current context
244: The field 'IntradayOptionDemo.contractQty' is never used
251: The field 'IntradayOptionDemo._broker' is never used
Clearly the WealthLab compiler is 7.3 - it says it in the error message. I
If you want to persist with this, for now you'll have to use the C# 9 / 10 compiler that comes with VS 2022 and use a compiled strategy library.
Alternatively, stop using unnecessary features!
If you want to persist with this, for now you'll have to use the C# 9 / 10 compiler that comes with VS 2022 and use a compiled strategy library.
Alternatively, stop using unnecessary features!
Your Response
Post
Edit Post
Login is required