I try to use XmlSerializer in a C# coded strategy.
This requires a
Strategy code compiles fine.:
After "Start Backtest" I get:
"A non-collectible assembly may not reference a collectible assembly"
WHAT THE HELL IS THIS?
I've never seen such a message before.
The explanation here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/7.0/collectible-assemblies
does not help anyway.
Any suggestions?
This requires a
CODE:statement and System.Private.Xml checked in Tools->Assembly References.
using System.Xml.Serialization;
Strategy code compiles fine.:
CODE:
public class TradeInfo2 { public string Symbol; } ... XmlSerializer serializer = new XmlSerializer(typeof(List<TradeInfo2>));
After "Start Backtest" I get:
"A non-collectible assembly may not reference a collectible assembly"
WHAT THE HELL IS THIS?
I've never seen such a message before.
The explanation here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/7.0/collectible-assemblies
does not help anyway.
Any suggestions?
Rename
It happens only, if the serialized class (here TradeInfo2) comes from the coded strategy.
I was able to get this variation to run, don't know exactly why .NET is complaining about using the List directly.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using System.Xml.Serialization; using Steema.TeeChart; using System.Windows.Documents; namespace WealthScript1 { 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) { XmlSerializer serializer = new XmlSerializer(typeof(TradeInfoList)); } //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 (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } public class TradeInfo2 { public string Symbol { get; set; } } public class TradeInfoList { public List<TradeInfo2> TheList { get; set; } = new List<TradeInfo2>(); } }
That worked, thanks!
@DrKoch - In case you don't want to wrap the List<T> you could try the solution here involving DataContractSerializer: https://github.com/dotnet/runtime/issues/85142
I didn't try it. I don't know the implications, either.
I didn't try it. I don't know the implications, either.
Thanks, Paul!
Your Response
Post
Edit Post
Login is required