Traders' Tip text
In the current issue, author Edgar Kraut presents a super simple system that consists of two rules for taking long positions. Formally it does not share traits of classic swing trading systems (as advertised) except for its sensitive 1% trailing stop, so with its trend condition rule and a volume confirmation rule seeking to identify and hold a rising stock for a short period of time, we would rather classify it as pure momentum trading.
Figure 1. A Wealth-Lab Developer 6.2 chart showing the Color-Based System applied to a Daily chart of the SPDR S&P500 (
SPY).
Our C# version of the system allows Wealth-Lab 6 users to easily change the lookback and exit parameters by dragging the parameter sliders in the lower left corner of Wealth-Lab's main workspace. We replaced the default trailing exit with a combination of a profit target and a stop loss, and made the system exit on Red and Orange bars. For traders willing to tweak the rules further, here's a uber simple trend identification idea of the same kind to go along with the volume confirmation rule:
- Bullish trend starts after X consecutive closes above the trailing close from Y days ago,
- Bearish trend starts after X consecutive closes below the trailing close from Y days ago.
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 ColorBased : WealthScript
{
private StrategyParameter paramLookback;
private StrategyParameter paramSL;
private StrategyParameter paramPT;
public ColorBased()
{
paramLookback = CreateParameter("Lookback", 20, 2, 100, 1);
paramSL = CreateParameter("Stop %", 4, 1, 10, 1);
paramPT = CreateParameter("Target %", 4, 1, 20, 1);
}
private Color color( int bar, int lookback )
{
Color c = Color.Transparent;
if( Bars.Count > lookback )
{
int b = bar-lookback;
bool green = (Close[bar] > Close[b]) && (Volume[bar] > Volume[b]);
bool blue = (Close[bar] > Close[b]) && (Volume[bar] <= Volume[b]);
bool orange = (Close[bar] < Close[b]) && (Volume[bar] < Volume[b]);
bool red = (Close[bar] < Close[b]) && (Volume[bar] >= Volume[b]);
if( green ) c = Color.Green;
if( blue ) c = Color.Blue;
if( orange ) c = Color.Orange;
if( red ) c = Color.Red;
}
return c;
}
protected override void Execute()
{
int lookback = paramLookback.ValueInt;
double SL = paramSL.Value;
double PT = paramPT.Value;
for(int bar = lookback; bar < Bars.Count; bar++)
{
Color c = color(bar,lookback);
SetSeriesBarColor( bar, Volume, c );
SetBarColor( bar, c );
if (IsLastPositionActive)
{
Position p = LastPosition;
double Stop = p.EntryPrice * (1 - SL / 100.0d);
double Target = p.EntryPrice * (1 + PT / 100.0d);
if( c == Color.Red || c == Color.Orange )
SellAtMarket(bar+1, p, c.ToString() );
else
if( !SellAtStop(bar + 1, p, Stop, "SL") )
SellAtLimit(bar + 1, p, Target, "TP");
}
else
{
if( c == Color.Green || c == Color.Blue )
BuyAtMarket( bar+1, c.ToString() );
}
}
}
}
}