Log in to see Cloud of Tags

Wealth-Lab Wiki

TASC 2009-07 | Tr&nd Stop (Vervoort)

RSS

Traders' Tip text

We programmed the long-only Tr&nd stop strategy for Wealth-Lab 5 in C#. You can use the sliders to adjust the Period and atrFactor Strategy Parameters to eyeball an optimization, or using WLP 5.4 you can now run full Exhaustive and Monte Carlo optimizations. A portfolio simulation ($5000 size, $8 1-way commissions) on the Dow 30 symbols over the last 6 years yielded the 2-Parameter optimization curve in Figure 1.


Image

Figure 1. While the optimization didn’t inspire confidence in the strategy’s stability over a wide range of parameters, ATR Factors around 2 helped improve the overall profit, while the Period did not affect the results significantly.


WealthScript Code (C#)

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;

namespace WealthLab.Strategies { public class SVETrendsStopStrategy : WealthScript { StrategyParameter atrFactor; StrategyParameter period; public SVETrendsStopStrategy() { atrFactor = CreateParameter("ATR Factor", 2.8, 1, 10, 0.2); period = CreateParameter("Period", 10, 2, 100, 2); } public DataSeries TrndsStop(Bars b, int period, double factor ) { DataSeries loss = factor * TASCIndicators.ATRModified.Series(b, period); DataSeries resistance = b.Close + loss; DataSeries support = new DataSeries(b, "Support(" + period + "," + factor + ")"); DataSeries trends = new DataSeries(b, "TrendsStop(" + period + "," + factor + ")"); for (int bar = 0; bar < period; bar++) supportbar = b.Lowbar; for (int bar = period; bar < b.Count; bar++) { double b2 = b.Lowbar-2; double prev = trendsbar-1; if( (b.Lowbar >= b2) && (b.Lowbar-1 >= b2) && (b.Lowbar-3 >= b2) && (b.Lowbar-4 >= b2) ) supportbar = b2; else if ( b.Lowbar > b.Highbar-1 * 1.0013 ) supportbar = b.Highbar-1 * 0.9945; else if ( b.Lowbar > supportbar-1 * 1.1 ) supportbar = supportbar-1 * 1.05; else supportbar = supportbar-1; if( (b.Highbar > prev) && (b.Highbar-1 > prev) ) trendsbar = Math.Max(prev, supportbar); else if( (b.Highbar < prev) && (b.Highbar-1 < prev) ) trendsbar = Math.Min(prev, resistancebar); else if( (b.Highbar >= prev) ) trendsbar = supportbar; else trendsbar = resistancebar; } return trends; } protected override void Execute() { DataSeries stop = TrndsStop(Bars, period.ValueInt, atrFactor.Value); PlotSeries(PricePane, stop, Color.Blue, LineStyle.Solid, 2); for(int bar = 20; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( CrossUnder(bar, High, stop) ) SellAtMarket(bar + 1, LastPosition); } else if( CrossOver(bar, Close, stop) ) BuyAtMarket(bar + 1); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.