- ago
The "Equity" function does not work on WL8.

WL7:



WL8:

0
379
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
Just to make it clear, there's been no "Equity function". It's called the CurrentEquity property (topic title corrected). It happens because you do the plotting in Execute(). Move it to BacktestComplete() for the equity plot to appear. This method is called for the last symbol (in alphabetical order) after the backtest processing completes for all symbols.



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 {       TimeSeries equity;       TimeSeries equitySMA;       public override void Initialize(BarHistory bars)       {          equity = new TimeSeries(bars.DateTimes);          equitySMA = new TimeSeries(bars.DateTimes);       }       public override void Execute(BarHistory bars, int idx)       {          equity[idx] = CurrentEquity;          equitySMA[idx] = SMA.Value(idx, equity, 10);       } //declare private variables below public override void BacktestComplete() { base.BacktestComplete();          PlotTimeSeries(equity, "Equity", "Equity", WLColor.Green, PlotStyle.ThickHistogram);          PlotTimeSeries(equitySMA, "SMA(Equity)", "Equity", WLColor.Black, PlotStyle.Line);       } } }
1
Best Answer
- ago
#2
The above solution doesn't trade, so one wouldn't expect to see any equity changes as shown. I'm not sure how you got that equity plot.

You could declare equitySMA as a local variable in BacktestComplete (see below) to save on garbage collection time.

CODE:
      public override void Execute(BarHistory bars, int idx)       {          ... //Do some trading here          equity[idx] = CurrentEquity;       }       //declare private variables below       public override void BacktestComplete()       {          base.BacktestComplete();          PlotTimeSeries(equity, "Equity", "Equity", WLColor.Green, PlotStyle.ThickHistogram);          IndicatorBase equitySMA = new SMA(equity, 10);          PlotIndicator(equitySMA, paneTag: "Equity");       }
I didn't realize you could employ BacktestComplete as a test bed for a Performance Visualizer (like for equity). That's a neat trick. That approach should be suggested in the Performance Visualizer API docs.
0
- ago
#3
Yes, in this case equity is drawn. Thank you.
1

Reply

Bookmark

Sort