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 = HO[ bar - 1 ]; double c1 = HC[ bar - 1 ]; HO[bar] = ( o1 + c1 ) / 2; HH[bar] = Math.Max( HO[bar], High[bar] ); HL[bar] = Math.Min( HO[bar], Low[bar] ); haC[bar] = ( HC[bar] + HO[bar] + HH[bar] + HL[bar] ) / 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) && Close[bar] > p.EntryPrice ) SellAtMarket(bar + 1, p, "Profit"); else if( Close[bar] < stop ) SellAtMarket(bar + 1, p, "Stop Loss"); } else if( CrossOver(bar, zlTyp, zlHa) ) { LL = Lowest.Series(Low, 21)[bar]; BuyAtMarket(bar + 1); } } } } }