I would like to enforce the type of Position Size to 'Percent of Equity' in my compiled strategy. Is it possible to do this?
Rename
Yes, you can click 'Save' button and the compiled strategy's settings should get saved
I’m trying to enforce this from code and throw an error prevent backtest from running if this is not set.
You should try to save it the way it's implemented.🤷♂️
You can examine Backtester.PositionSize to see what position size has been selected.
This should do it -
CODE:
public override void Initialize(BarHistory bars) { PositionSize ps = Backtester.PositionSize; WriteToDebugLog("Sizer Type: " + ps.PositionSizeType); WriteToDebugLog("Amount: " + ps.Amount); WriteToDebugLog("Margin Factor: " + ps.MarginFactor); if (ps.PositionSizeType.ToString() != "PctOfEquity") throw new Exception("Wrong Sizer Selected!"); }
Thank you Cone, exactly what I was looking for.
QUOTE:
I’m trying to enforce this from code and throw an error prevent backtest from running if this is not set.
Sorry @pix, I misread your reply as if your code was applying the position sizing on-the-fly and throwing an error.
Your Response
Post
Edit Post
Login is required