- ago
Is it possible to add a column for each backtest position and new signal to show the percent of equity utilized? I apologize if there is a way to do this already easily.

To me this would be very useful when using the advanced pos sizer.

Thanks!
1
1,180
Solved
1 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, it's possible. I'm not sure whether it's desirable to spread the proposed column on every Strategy backtest for every user but if it matters to you then it's easy to accomplish this in your Strategy code. Follow the code comments:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) { } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) {             if(idx == bars.Count - 1)             {                var _basisPrice = bars.Close[bars.Count - 1];                                //keep trade in a transaction object                var t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market);                                //calculate the resulting percent equity from transaction's Quantity and CurrentEquity                var _pctEquity = t.Quantity * _basisPrice / CurrentEquity * 100;                                //add this value to signal name                t.SignalName = $"% Equity: {_pctEquity.ToStringDecimals(0, 2)}";             }             } else { } } } }
1
Best Answer

Reply

Bookmark

Sort