TASC 2012-01 | Reversing MACD (Dough)

Modified on 2011/12/14 11:10 by Eugene — Categorized as: TASC Traders Tips

Traders' Tip text

Wouldn't it be cool to anticipate the price when MACD crosses above or below zero and act upon that - one bar ahead? The Strategy code below, based on Johnny Dough's article in this issue, allows Wealth-Lab users to backtest the concept.

The idea is to buy at stop at the reverse-engineered price when the MACD is crossing zero from below and to exit if the opposite criteria has been met. Although we're putting long trades in focus, it's equally easy to apply the idea to the short side as well: simply reverse the rules.

Image

Figure 1.A Wealth-Lab Developer 6.2 chart showing the price equivalent to the Reversed MACD crossing the zero line using Daily data of AAPL (Apple Inc.) The bluish line showing the reversed MACD is constructed using its traditional settings (Close price, periods: 12 and 26).


We've saved you from the trouble of creating the Reversed MACD DataSeries by including it in the TASCIndicators library. Before you can start charting the data series or utilizing it in your strategies, be they coded in C# or built with the help of the GUI-based Strategy Wizard, 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.

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.

WealthScript Code (C#)

using System; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators;

namespace WealthLab.Strategies { public class ReversingMACD : WealthScript { protected override void Execute() { DataSeries macd = MACD.Series( Close ); ChartPane MACDPane = CreatePane( 30, true, true ); PlotSeries( MACDPane, macd, Color.Red, LineStyle.Solid, 1 ); DrawHorzLine( MACDPane, 0, Color.Blue, LineStyle.Dashed, 1 ); // Reversing MACD RevEngMACD r = RevEngMACD.Series( Close,12,26 ); PlotSeries( PricePane, r, Color.Blue, LineStyle.Dashed, 2 );

for(int bar = r.FirstValidValue; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( macdbar > 0 ) SellAtStop( bar+1, LastPosition, rbar ); } else { if( macdbar < 0 ) BuyAtStop( bar+1, rbar ); } } } } }