C# Code to reproduce the issue... Wanted to make a position size chage by code in every single optimization run but it turned out impossible with parallel optimization.
This code showes that backtester instances are different on each run having same instance of PositionSize.
CODE:
public override void BacktestBegin() { List<Backtester> lst; if (HasGlobal("Backtester")) lst = (List<Backtester>)GetGlobal("Backtester"); else lst = new List<Backtester>(); if (lst.Contains(Backtester)) WLHost.Instance.AddLogItem("TEST", "Same backtester instance", WLColor.Green); else lst.Add(Backtester); SetGlobal("Backtester", lst); List<PositionSize> lst1; if (HasGlobal("PositionSize")) lst1 = (List<PositionSize>)GetGlobal("PositionSize"); else lst1 = new List<PositionSize>(); if (lst1.Contains(Backtester.PositionSize)) WLHost.Instance.AddLogItem("TEST", "Same PositionSize instance", WLColor.Green); else lst1.Add(Backtester.PositionSize); SetGlobal("PositionSize", lst1); }
This code showes that backtester instances are different on each run having same instance of PositionSize.
Rename
This isn’t a bug. Where is it documented that each PositionSize instance should be different?
If you want to change the position size of each run, a way to do it is to set the Quantity properly of the Transaction instance that you get as a result of calling PlaceTrade.
QUOTE:
This isn’t a bug. Where is it documented that each PositionSize instance should be different?
Just thought that if Backtester has another instance each time and PositionSize is an instance variable and kind of specific to Backtest run it can have another instance for each run too... Sorry, misunderstood the logic
Your Response
Post
Edit Post
Login is required