using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class CombinedDMI_MA : WealthScript { StrategyParameter maPeriod; StrategyParameter dmPeriod; public CombinedDMI_MA() { maPeriod = CreateParameter("MA Period", 30, 10, 55, 5); dmPeriod = CreateParameter("DM Period", 14, 10, 21, 1); } protected override void Execute() { HideVolume(); int maPer = maPeriod.ValueInt; int dmPer = dmPeriod.ValueInt; bool dmiLong = false; bool dmiShort = false; bool maLong = false; bool maShort = false; DataSeries ma = SMA.Series(Close, maPer); DataSeries diplus = DIPlus.Series(Bars, dmPer); DataSeries diminus = DIMinus.Series(Bars, dmPer); ChartPane diPane = CreatePane(40, true, true); PlotSeries(diPane, diplus, Color.Green, LineStyle.Solid, 2); PlotSeries(diPane, diminus, Color.Red, LineStyle.Solid, 2); PlotSeries(PricePane, ma, Color.Blue, LineStyle.Solid, 2); for(int bar = Math.Max(maPer, dmPer); bar < Bars.Count; bar++) { if( CrossOver(bar, diplus, diminus) ) { dmiLong = true; dmiShort = false; } else if( CrossUnder(bar, diplus, diminus) ) { dmiLong = false; dmiShort = true; } if( CrossOver(bar, Close, ma) ) { maLong = true; maShort = false; } else if( CrossUnder(bar, Close, ma) ) { maLong = false; maShort = true; } if (IsLastPositionActive) { Position p = LastPosition; if( p.PositionType == PositionType.Long ) { if( dmiShort && maShort ) { SellAtClose(bar, p); ShortAtClose(bar); } } else if( dmiLong && maLong ) { CoverAtClose(bar, p); BuyAtClose(bar); } } else if( dmiLong && maLong ) BuyAtClose(bar); else if( dmiShort && maShort ) ShortAtClose(bar); } } } }