public MACD(DataSeries source, string description) public static MACD Series(DataSeries source)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { /* This system buys a new position whenever MACD crosses the signal line from below 0. It sells all open positions when MACD crosses below the signal line from above 0. The trading loop starts at Bar 60 in order to give the 26-period EMA used in the MACD calculation time to stabilize. */ DataSeries macd = MACD.Series( Close ); DataSeries macdSignal = EMA.Series( macd, 9, EMACalculation.Modern ); DataSeries hist = macd - macdSignal; hist.Description = "MACD Histogram"; ChartPane MACDPane = CreatePane( 50, true, true ); PlotSeries( MACDPane, hist, Color.Brown, LineStyle.Histogram, 2 ); PlotSeries( MACDPane, macd, Color.Red, LineStyle.Solid, 1 ); PlotSeries( MACDPane, macdSignal, Color.Black, LineStyle.Solid, 1 ); for(int bar = 26 * 3; bar < Bars.Count; bar++) { if( CrossOver( bar, macd, macdSignal ) & ( macdbar < 0 ) ) BuyAtMarket( bar+1 ); if( CrossUnder( bar, macd, macdSignal ) & ( macdbar > 0 ) ) SellAtMarket( bar+1, Position.AllPositions, "MACD" ); } } } }