- ago
I would like to enforce the type of Position Size to 'Percent of Equity' in my compiled strategy. Is it possible to do this?
0
604
Solved
7 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, you can click 'Save' button and the compiled strategy's settings should get saved
0
- ago
#2
I’m trying to enforce this from code and throw an error prevent backtest from running if this is not set.
0
- ago
#3
You should try to save it the way it's implemented.🤷‍♂️
0
Glitch8
 ( 10.62% )
- ago
#4
You can examine Backtester.PositionSize to see what position size has been selected.
0
Cone8
 ( 4.98% )
- ago
#5
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!"); }
1
Best Answer
- ago
#6
Thank you Cone, exactly what I was looking for.
0
- ago
#7
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.
0

Reply

Bookmark

Sort