using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators;namespace WealthLab.Strategies { public class ReliableCrossovers : WealthScript { // Create slider parameter(s) private StrategyParameter emaPeriod; public ReliableCrossovers() { emaPeriod = CreateParameter("EMA Period", 55, 10, 120, 5); } public DataSeries ZLTEMASeries(DataSeries Source, int Period, EMACalculation calcType) { DataSeries tma1 = TEMA.Series(Source, Period, calcType); DataSeries tma2 = TEMA.Series(tma1, Period, calcType); return tma1 + (tma1 - tma2); } protected override void Execute() { /* Create a Heikin-Ashi chart above the main PricePane */ DataSeries HO = Open + 0; // intializations DataSeries HH = High + 0; DataSeries HL = Low + 0; DataSeries HC = (Open + High + Low + Close) / 4; DataSeries haC = HC + 0; haC.Description = "Heikin-Ashi Close"; for (int bar = 1; bar < Bars.Count; bar++) { double o1 = HObar - 1; double c1 = HCbar - 1; HObar = ( o1 + c1 ) / 2; HHbar = Math.Max( HObar, Highbar ); HLbar = Math.Min( HObar, Lowbar ); haCbar = ( HCbar + HObar + HHbar + HLbar ) / 4; } ChartPane haPane = CreatePane(40, true, true); PlotSyntheticSymbol(haPane, "Heikin-Ashi", HO, HH, HL, HC, Volume, Color.DodgerBlue, Color.Red); //Obtain SMA period from parameter int period = emaPeriod.ValueInt; double stop = 0d; double LL = 0d; DataSeries typPrice = ( High + Low + Close ) / 3; DataSeries zlTyp = ZLTEMASeries(typPrice, period, EMACalculation.Modern); zlTyp.Description = "ZeroLagTEMA(typPrice, " + period + ")"; PlotSeries(PricePane, zlTyp, Color.Blue, LineStyle.Solid, 2); DataSeries zlHa = ZLTEMASeries(haC, period, EMACalculation.Modern); zlHa.Description = "ZeroLagTEMA(HeikinAshiClose, " + period + ")"; PlotSeries(PricePane, zlHa, Color.Red, WealthLab.LineStyle.Dashed, 2); for(int bar = period; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; stop = Math.Min(LL, p.EntryPrice * 0.9); if( CrossUnder(bar, zlTyp, zlHa) && Closebar > p.EntryPrice ) SellAtMarket(bar + 1, p, "Profit"); else if( Closebar < stop ) SellAtMarket(bar + 1, p, "Stop Loss"); } else if( CrossOver(bar, zlTyp, zlHa) ) { LL = Lowest.Series(Low, 21)bar; BuyAtMarket(bar + 1); } } } } }