- ago
I would like to duplicate the standard Equity Curve with moving average that is on the Equity tab onto my current chart with C# code. How can I do this?

I have taken a Building Block strategy and converted it o C# and just added the basic Trading the Equity Curve Code. I am looking to validate that both code is the same and want to visually see both equity charts on my main chart.

The reason is that visually, trading the equity curve looks great on the Equity Pane but give me not good results when I actually code it in C# for back testing.

I am including my code here.

Thank you,

Larry

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript8 { public class MyStrategy : UserStrategyBase {     public MyStrategy() : base() {          AddParameter("SMA of Equity", ParameterType.Int32, 50, 0, 200, 1); StartIndex = 20; } public override void Initialize(BarHistory bars) {          //For Equity Curve begin          eq = new TimeSeries(bars.DateTimes);          smaEq = new TimeSeries(bars.DateTimes);          PlotTimeSeries(eq, "Equity", "Equity", WLColor.DarkGreen, PlotStyle.ThickHistogram);          PlotTimeSeries(smaEq, "SMA EQ", "Equity", WLColor.Black);          //For Equity Curve end          indicator1 = bars.Close;          indicator2 = new SMA(bars.Close,20);          PlotIndicator(indicator2,new WLColor(0,0,0));          _startIndexList.Add(indicator2);          indicator12 = bars.Close;          indicator22 = new SMA(bars.Close,20);          _startIndexList.Add(indicator22); foreach(IndicatorBase ib in _startIndexList) if (ib.FirstValidIndex > StartIndex) StartIndex = ib.FirstValidIndex; } public override void Execute(BarHistory bars, int idx) {          //For Equity Curve begin          eq[idx] = CurrentEquity;          smaEq[idx] = SMA.Value(idx, eq, Parameters[0].AsInt);          //For Equity Curve End              int index = idx;          Position foundPosition0 = FindOpenPosition(0);          bool condition0;          // no entry if Equity < SMA(eq)          if (eq[idx] < smaEq[idx])             return;              if (foundPosition0 == null)          {             condition0 = false;             {                if (index - 0 >= 0 && indicator1[index] > indicator2[index - 0])                {                   condition0 = true;                }             }             if (condition0)             {                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)");             }          }          else          {             condition0 = false;             {                if (index - 0 >= 0 && indicator12[index] < indicator22[index - 0])                {                   condition0 = true;                }             }             if (condition0)             {                Backtester.CancelationCode = 104;                ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)");             }          } } public override void NewWFOInterval(BarHistory bars) {          indicator1 = bars.Close;          indicator2 = new SMA(bars.Close,20);          indicator12 = bars.Close;          indicator22 = new SMA(bars.Close,20); }       private TimeSeries indicator1;       private IndicatorBase indicator2;       private TimeSeries indicator12;       private IndicatorBase indicator22;       private Transaction _transaction; private List<IndicatorBase> _startIndexList = new List<IndicatorBase>();       //For Equity Curve begin       private TimeSeries eq;       private TimeSeries smaEq;       //For Equity Curve end        } }




0
244
0 Replies

Reply

Bookmark

Sort
Currently there are no replies yet. Please check back later.