- ago
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.

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.
0
321
Solved
3 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.10% )
- ago
#1
This isn’t a bug. Where is it documented that each PositionSize instance should be different?
0
Glitch8
 ( 12.10% )
- ago
#2
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.
1
Best Answer
- ago
#3
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
0

Reply

Bookmark

Sort