- ago
After double clicking on a position in the Positions tab of Backtest results, Wealthlab is hanging. I want to look at the individual chart for any trade.

I am showing the Strategy Settings screen:



Here is the positions screen after I ran the backtest:



I think this is related to code that I added reflecting "trading the equity curve"

Here is the code:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using WealthLab.AdvancedSmoothers; namespace WealthScript8 {    public class LSBollingerBands : UserStrategyBase    {       public LSBollingerBands()       {          AddParameter("Rate of Change Period", ParameterType.Int32, 100, 50, 500, 50);          AddParameter("Benchmark SMA Period", ParameterType.Int32, 50, 10, 500, 10);          AddParameter("Number of Buy Candidates", ParameterType.Int32, 8, 1, 10, 1);          //AddParameter("Trailing Stop Pct", ParameterType.Int32, 10, 2, 20, 2);          AddParameter("Stop Loss Pct", ParameterType.Double, 10, 2, 20, 2);          AddParameter("SMAShort", ParameterType.Int32, 4, 1, 8, 1);          AddParameter("SMAMiddle", ParameterType.Int32, 9, 9, 17, 1);          AddParameter("SMALong", ParameterType.Int32, 18, 18, 30, 1);          AddParameter("OBV SMA", ParameterType.Int32, 0, 0, 50, 2);                    AddParameter("SMA of Equity", ParameterType.Int32, 5, 0, 200, 1);                 }              TimeSeries barClose;       IndicatorBase obv, obvSma;              public override void Initialize(BarHistory bars)       {          //For Equity Curve begin          eq = new TimeSeries(bars.DateTimes);       //   t3Eq = new TimeSeries(bars.DateTimes);          smaEq = new TimeSeries(bars.DateTimes);          PlotTimeSeries(eq, "Equity", "Equity", WLColor.DarkGreen, PlotStyle.ThickHistogram);       //   PlotTimeSeries(t3Eq, "T3", "Equity", WLColor.Blue);          PlotTimeSeries(smaEq, "SMA EQ", "Equity", WLColor.Black);          //For Equity Curve end          //load the parameters          rocPeriod = Parameters[0].AsInt;          benchmarkPeriod = Parameters[1].AsInt;          numParticipants = Parameters[2].AsInt;          stopLossPct = Parameters[3].AsInt;          // create and plot Triple SMA          SMA_short = new SMA(bars.Close, Parameters[4].AsInt);          SMA_middle = new SMA(bars.Close, Parameters[5].AsInt);          SMA_long = new SMA(bars.Close, Parameters[6].AsInt);          PlotIndicator(SMA_short, WLColor.Green, PlotStyle.DashedLine);          PlotIndicator(SMA_middle, WLColor.Blue, PlotStyle.DashedLine);          PlotIndicator(SMA_long, WLColor.Red, PlotStyle.DashedLine);                          // create and plot OBV with SMA          barClose = bars.Close;          obv = new OBV(bars); //obv's PaneTag name established by OBV indicator       //   PlotIndicator(obv, WLColor.Black); //plotted on the obv.PaneTag pane by default          obvSma = new SMA(obv, Parameters[7].AsInt);          //   PlotIndicator(obvSma, WLColor.Salmon, paneTag: obv.PaneTag); //assigning obv's PaneTag name for obvSma plot          //create other working indicators          roc = ROC.Series(bars.Close, rocPeriod);          //cache ROC value with each bar          bars.Cache["ROC"] = roc;          //benchmark creation          benchmarkBar = GetHistory(bars, "SPY");          benchmarkSMA = SMA.Series(benchmarkBar.Close, benchmarkPeriod);          //plot the benchmark price bars and the SMA in a new plane       //   PlotBarHistory(benchmarkBar, "Benchmark", WLColor.Green, true);       //   PlotIndicator(benchmarkSMA, WLColor.WhiteSmoke, PlotStyle.Line, false, "Benchmark");          trailing = true;          PlotStopsAndLimits(3);       }       //this is called prior to the Execute loop, determine which symbols have the lowest RSI       public override void PreExecute(DateTime dt, List<BarHistory> participants)       {          //store the symbols ROC value in their BarHistory instances          foreach (BarHistory bh in participants)          {             ROC symbolROC = (ROC)bh.Cache["ROC"];             int idx = GetCurrentIndex(bh); //this returns the index of the BarHistory for the bar currently being processed             double rocVal = symbolROC[idx];             //save the current value along with the BarHistory instance             bh.UserData = rocVal;          }          //sort the participants by ROC value (lowest to highest)          participants.Sort((a, b) => a.UserDataAsDouble.CompareTo(b.UserDataAsDouble));          participants.Reverse(); //flip the list so the highest ROC are on top          //keep the top symbols based on numParticipants - all open positions          buys.Clear();          for (int n = 0; n < numParticipants - OpenPositionsAllSymbols.Count; n++)          {             if (n >= participants.Count - OpenPositionsAllSymbols.Count)                break;             buys.Add(participants[n]);          }       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {          //For Equity Curve begin          eq[idx] = CurrentEquity;       //   TimeSeries t3 = new T3(eq, Parameters[8].AsInt, 0.7); //T3 does not have a static Value method so we need to do it this way       //   t3Eq[idx] = t3[idx];          smaEq[idx] = SMA.Value(idx, eq, Parameters[8].AsInt);          //For Equity Curve End          bool condition0;          //check to be sure the longest period indictor contains valid values          if (double.IsNaN(benchmarkSMA[idx]))             return;          Position foundPosition0 = FindOpenPosition(0);          if (!HasOpenPosition(bars, PositionType.Long))          {             //set up abool for testing if n buy lisr             bool inBuyList = buys.Contains(bars);             //create the transation for use wiht same say stops             Transaction trans = null;             //no entry if benchmark close is inder benchmark SMA             if (benchmarkBar.Close[idx] < benchmarkSMA[idx])                return;             //no entry if obv is less than obv(sma)             if (obv[idx] <= obvSma[idx])                return;             // no entry if Equity < SMA(eq)             if (eq[idx] < smaEq[idx])                return;             //no entry if not in the buy list             if (!inBuyList)                return;             condition0 = false;             if (idx - 0 >= 0 && SMA_short[idx] > SMA_middle[idx - 0])             {                if (idx - 0 >= 0 && SMA_middle[idx] > SMA_long[idx - 0])                {                   trans = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy Triple SMA");                   condition0 = true;                }             }             //transaction weighted for backtestng by ROC             if (trans != null)             {                trans.Weight = roc[idx];             }          }          else          {             // If SMA_short < SMA_middle < SMA_long             if (idx - 0 >= 0 && SMA_short[idx] < SMA_middle[idx - 0])             {                Backtester.CancelationCode = 284;                PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, 0, "Sell Triple SMA");                condition0 = true;             }             else                //stop loss exit                PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, StopLoss(bars, idx), 0, "Stop Loss Triple SMA");                //Backtester.CancelationCode = 178;                //CloseAtTrailingStop(foundPosition0, TrailingStopType.PercentHL, Parameters[3].AsDouble, "Sell Trail Stop Loss Triple SMA");          }              }                     //same bar exits: profit or loss from execution price       public override void AssignAutoStopTargetPrices(Transaction trans, double basisPrice, double executionPrice)       {          trans.AutoStopLossPrice = Math.Round(executionPrice * (1 - (stopLossPct / 100)), 2);       }       //calcualte the stoploss price and return it       private double StopLoss(BarHistory bars, int idx)       {          return Math.Round(LastOpenPosition.EntryPrice * (1 - (stopLossPct / 100)), 2);       }       //the list of symbols that we should buy each bar       private static List<BarHistory> buys = new List<BarHistory>();       //private variables       //int bbPeriod, rocPeriod, benchmarkPeriod, exitBand, numParticipants;       //Double bbUpperStdDev, bbLowerStdDev, stopLossPct;       int rocPeriod, benchmarkPeriod, numParticipants;       Double stopLossPct;       //indicators       IndicatorBase benchmarkSMA, roc;       //bar history for benchmark       BarHistory benchmarkBar;       public override void NewWFOInterval(BarHistory bars)       {          SMA_short = new SMA(bars.Close, Parameters[8].AsInt);          SMA_middle = new SMA(bars.Close, Parameters[9].AsInt);          SMA_long = new SMA(bars.Close, Parameters[10].AsInt);              }       private IndicatorBase SMA_short;       private IndicatorBase SMA_middle;       private IndicatorBase SMA_long;       private bool trailing;       //For Equity Curve begin       private TimeSeries eq;    //   private TimeSeries t3Eq;       private TimeSeries smaEq;       //For Equity Curve end    } }


0
375
5 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.55% )
- ago
#1
It runs very fast for me and returns the chart instantaneously.

Try deselecting Event Providers (you can leave Wealth-Data Events checked, that one is fast).
0
- ago
#2
Cone,
This was already selected:


My machine is still hanging.

Can you please run when Strategy settings matches my screen above. Where SMA of Equity = 5 or any number other than 0.

Thank you,
Larry
0
Cone8
 ( 4.55% )
- ago
#3
It was 5 before, changed it, makes no difference. For me the backtest is fast and the chart appears immediately after clicking a symbol in the Positions view.

Anything in your Log Viewer? (Ctrl+L)
0
- ago
#4
1. Close the strategy window
2. Choose "Offline mode" from File menu.
3. Reopen and tick "Obtain data from selected DataSet only" (Strategy settings > Backtest data > Portfolio backtest).

Any difference?
0
- ago
#5
Here is the log view after running strategy, but not double clicking on Position to open the chart.




I followed these instructions:



No difference.

However, I did try to comment out the Advanced Smoothers and references to T3. That seemed to work.

I then made sure to update WL and Advanced Smoother and other plugins and that did not fix the problem.

Seems like something with Advanced Smoother....

We can close this issue.

Thank you,

Larry
0

Reply

Bookmark

Sort