I've been trying to recreate this relatively simple strategy with building blocks in WL7, but I can't seem to get anywhere near the same results. Using the S&P500 for the last 1 year, I get 86 trades on 5% allocation with WL6, but WL7 only generates 5 trades. The blocks in WL7 are the closest I could find to the Rules in WL6.... Any ideas?
https://www2.wealth-lab.com/wl5wiki/TASCOct2019.ashx
https://www2.wealth-lab.com/wl5wiki/TASCOct2019.ashx
Rename
The Bullish Engulfing Pattern for WL7 is a little different than the one specified in the WL6 code. The default pattern code is Bullish Engulfing=BL:S.BC:B,BC:W.ENG:1
As for the multi-condition revealed in the WL6 code (the properties aren't shown in the image) are:
Here's the closest I think you can come using the current blocks:
As for the multi-condition revealed in the WL6 code (the properties aren't shown in the image) are:
CODE:One problem I see here is that the WL6 "Crosses Over" condition doesn't appear to be correct because it looks for the Close to be above the BBL one bar ago AND for the Low to be below the BBL one bar ago. A crossover one bar ago would really be Close to be above the BBL one bar ago AND Close is below the BBL two bars ago. Consequently, the WL6 hybrid condition would have to be created by ANDing 2 rules inside a MC block, which I don't think is possible.
(Close[bar-1] > bbL[bar-1]) && ((Low[bar-1] < bbL[bar-1]) || (Low[bar-2] < bbL[bar-2]))
Here's the closest I think you can come using the current blocks:
Also worth noting is that Qualifiers in MultiCondition Groups are not applied correctly in B43. To implement the strategy in Blocks please wait for B44 with a fix. Hope the wait is not too long.
Thanks for the quick reply, Eugene & Cone...Unfortunately the changes suggested by Cone don't improve the WL7 backtest, so I will wait for B44 to retest and update again.
Stewart, how many NSF positions does the backtest have?
QUOTE:
Stewart, how many NSF positions does the backtest have?
zero NSF positions in the backtest for the last year against the S&P500
A backtest of Cone's Blocks strategy on a DataSet of 50 symbols produces 20 trades in 10 years for me. Made just one correction, replacing the Close in BBLower/BBUpper with Low/High (respectively). Consequently, on S&P 500 it's expected to produce an order of magnitude more trades - like 150-200.
I made the same change (replacing Close with Low/High in the BB calc), ran it against the S&P500 for 10 years with 5% allocation to each, and I get 148 trades with zero NSF.
When I run the Rules based strategy in WL6 against the S&P500 for the last 10 years with the same 5% allocation to each trade, I get 975 trades included in the backtest with 557 trades not included due to insufficient simulated capital.
Hopefully WL7 B44 will fix the issue of triggering only 10% of the trades in WL6
When I run the Rules based strategy in WL6 against the S&P500 for the last 10 years with the same 5% allocation to each trade, I get 975 trades included in the backtest with 557 trades not included due to insufficient simulated capital.
Hopefully WL7 B44 will fix the issue of triggering only 10% of the trades in WL6
Try to compare each Rule against its particular Block counterpart. That should help pinpoint the diverging piece of code faster.
The only way you can get the same results is to use the same code (and data - remember, WL7 WealthData DataSets give you an actual historic backtest of the index constituents).
As I suspected, the main difference is the detection of Bullish Engulfing, which I'll call "faulty" in the WL6 version, which is too liberal and not actually detecting an engulfing pattern in most cases.
Here's the WL6 code, converted to WL7. The WL6 "engulfing" patterns are highlighted with a light blue background - there are many. The WL7 "Bullish Engulfing" patters aren't used here, but they are plotted on the chart for reference.
As I suspected, the main difference is the detection of Bullish Engulfing, which I'll call "faulty" in the WL6 version, which is too liberal and not actually detecting an engulfing pattern in most cases.
Here's the WL6 code, converted to WL7. The WL6 "engulfing" patterns are highlighted with a light blue background - there are many. The WL7 "Bullish Engulfing" patters aren't used here, but they are plotted on the chart for reference.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using WealthLab.Candlesticks; namespace WealthScript123 { public class TASC201910 : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { StartIndex = 20; _bbL = BBLower.Series(bars.Close, 20, 2.0); _bbU = BBUpper.Series(bars.Close, 20, 2.0); PlotIndicatorLine(_bbL); PlotIndicatorLine(_bbU); try { _tickSize = bars.SymbolInfo.TickSize; } catch { _tickSize = 0.01; } _cp = CandleGeneDecoder.FindPattern("Bullish Engulfing"); for (int n = 0; n < bars.Count; n++) { if (CandleGeneDecoder.DetectPattern(bars, n, _cp)) { _cfi = new CandleEventItem(_cp, bars.DateTimes[n]); _cbg = new CandleBarGlyph(_cfi, _cp); DrawCustomBarGlyph(n, _cbg); } } } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int bar) { if (!HasOpenPosition(bars, PositionType.Long)) { //touches the lower band double C1 = bars.Close[bar - 1]; double C2 = bars.Close[bar - 2]; double O1 = bars.Open[bar - 1]; double O2 = bars.Open[bar - 2]; double L1 = bars.Low[bar - 1]; double L2 = bars.Low[bar - 2]; bool WL6engulfing = C2 < O2 && C1 > O1 && O1 < C2 && C1 > O2 && (C1 - O1 > 20 * _tickSize) && bars.Close[bar] > bars.High[bar - 1]; if (WL6engulfing) { SetBackgroundColor(bars, bar, Color.FromArgb(40, Color.Blue)); if ((C1 > _bbL[bar - 1]) && (L1 < _bbL[bar - 1] || L2 < _bbL[bar - 2])) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } } else { if (bars.High[bar] > _bbU[bar]) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } CandleGenePattern _cp; CandleEventItem _cfi; CandleBarGlyph _cbg; BBLower _bbL; BBUpper _bbU; double _tickSize; } }
Your Response
Post
Edit Post
Login is required