Traders' Tip text
In this issue, author Johnny Dough shares a new tool with the readers: an indicator that anticipates the price when MACD crosses above or below its signal line one bar ahead. It complements the Reverse MACD indicator from the
January 2012 issue.
The Reversed MACD Signal indicator is included in the latest version of our
TASCIndicators library, allowing Wealth-Lab users to apply it to their charts and strategies, either coded in C# directly or built with the help of the GUI-based Strategy Wizard. In addition, author provides the formulas for reverse functions for MACD indicator based on simple moving averages (SMA) rather than the traditional exponential ones (EMA). They could be found too in the
TASCIndicators library. To start using it, please install the
TASC Magazine Indicators library from the Extensions section of our website if you haven't done so, or apply the update directly using Wealth-Lab's Extension Manager. In both cases, don't forget to restart Wealth-Lab.
The Strategy code below illustrates its application in Wealth-Lab, buying at stop at the reverse-engineered price when a bullish MACD is crossing above its signal line, and exiting if the opposite criteria has been met after the MACD has turned bearish. Applying the idea to the short side is equally easy: simply reverse the rules. Copy/paste the included Strategy's C# code or simply let Wealth-Lab do the job: in “Open Strategy” dialog, click “Download” to get this strategy's code, as well as many other strategies contributed by the Wealth-Lab community.
Figure 1. A Wealth-Lab 6 chart illustrating the application of the RevEngMACDSignal indicator. Crossovers and crossunders of MACD and its signal line are highlighted in greenish and reddish (respectively).
using System;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using TASCIndicators;
using Community.Indicators;
namespace WealthLab.Strategies
{
public class ReversingMACDSequel : WealthScript
{
protected override void Execute()
{
// Reversing MACD
HideVolume();
RevEngMACDSignal r = RevEngMACDSignal.Series( Close,12,26,9,false );
PlotSeries( PricePane, r, Color.Blue, LineStyle.Dashed, 2 );
// MACD and MACD signal
DataSeries macd = MACD.Series( Close );
DataSeries macdSignal = MACDEx_Signal3.Series( Close,12,26,9 );
DataSeries macdHist = MACDEx_Histogram.Series( Close,12,26 );
ChartPane MACDPane = CreatePane( 50, true, true );
PlotSeries( MACDPane, macd, Color.Blue, LineStyle.Solid, 2 );
PlotSeries( MACDPane, macdSignal, Color.Red, LineStyle.Solid, 2 );
PlotSeries( MACDPane, macdHist, Color.Teal, LineStyle.Histogram, 2 );
for(int bar = r.FirstValidValue; bar < Bars.Count; bar++)
{
if( CrossOver( bar, macdSignal, macd ) )
SetBackgroundColor( bar, Color.FromArgb( 30, Color.Green ) );
if( CrossUnder( bar, macdSignal, macd ) )
SetBackgroundColor( bar, Color.FromArgb( 30, Color.Red ) );
if (IsLastPositionActive)
{
if( macd[bar] > 0 )
SellAtStop( bar+1, LastPosition, r[bar] );
}
else
{
if( macd[bar] < 0 )
BuyAtStop( bar+1, r[bar] );
}
}
}
}
}
Eugene
Wealth-Lab team
www.wealth-lab.com