Traders' Tip text
We’ve add the Vortex Indicators to our TASCIndicators library for easy reference and programmed a stop and reverse version of the suggested trading strategy using an ATR trailing stop. On the S&P e-mini, the strategy was effective in entering and remaining in large trends, garnering more than $33,000 in profits trading 2 contracts 24 times over the past two years (no slippage or commissions). As typically observed when using stops, tightening the stop by reducing the ATR factor reduced trading profit.
Figure 1. The strategy to reverse on a stop was effective in remaining in strong trends despite multiple Vortex crossings.
WealthScript Code (C#)
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using TASCIndicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
//Pushed indicator StrategyParameter statements
private StrategyParameter vmPeriod;
private StrategyParameter atrFactor;
public MyStrategy()
{
vmPeriod = CreateParameter("VM Period",14,5,100,10);
atrFactor = CreateParameter("ATR Factor",4,1,5,0.5);
}
protected override void Execute()
{
int period = vmPeriod.ValueInt;
int xBar = 0; // Crossing bar or stop bar
bool bull = false;
double triggerPrice = -1d;
double stopPrice = -1d;
DataSeries vmPlus = VMPlus.Series(Bars ,period);
DataSeries vmMinus = VMMinus.Series(Bars ,period);
DataSeries atr = atrFactor.Value * ATR.Series(Bars, 10);
ChartPane paneVM = CreatePane(40,true,true);
PlotSeries(paneVM, vmPlus, Color.Blue, LineStyle.Solid, 2);
PlotSeries(paneVM, vmMinus, Color.Red, LineStyle.Solid, 2);
PlotStops();
HideVolume();
for(int bar = period; bar < Bars.Count; bar++)
{
if (CrossOver(bar, vmPlus, vmMinus))
{
SetBackgroundColor(bar, Color.LightBlue);
bull = true;
xBar = bar;
}
else if (CrossUnder(bar, vmPlus, vmMinus))
{
SetBackgroundColor(bar, Color.LightPink);
bull = false;
xBar = bar;
}
if (IsLastPositionActive)
{
Position p = LastPosition;
if (p.PositionType == PositionType.Long)
{
if (!bull)
{
SellAtStop(bar + 1, p, LowxBar);
ShortAtStop(bar + 1, LowxBar);
}
else if (SellAtTrailingStop(bar + 1, p, Closebar - atrbar, "T-Stop"))
xBar = bar + 1;
}
else
{
if (bull)
{
CoverAtStop(bar + 1, p, HighxBar);
BuyAtStop(bar + 1, HighxBar);
}
else if (CoverAtTrailingStop(bar + 1, p, Closebar + atrbar, "T-Stop"))
xBar = bar + 1;
}
}
else if (xBar > period) // initial and re-entry
{
if (bull) BuyAtStop(bar + 1, HighxBar);
else ShortAtStop(bar + 1, LowxBar);
}
}
}
}
}