using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators;namespace WealthLab.Strategies { public class TASCMar2020 : WealthScript { private StrategyParameter slider1; private StrategyParameter slider2; private StrategyParameter slider3; private StrategyParameter slider4; public TASCMar2020() { slider1 = CreateParameter("RSMK Period",90,50,130,10); slider2 = CreateParameter("RSMK EMA Period",3,2,10,1); slider3 = CreateParameter("Exit: off peak",20,10,40,10); slider4 = CreateParameter("Exit: EMA period",20,10,50,10); } protected override void Execute() { string wlp = "WealthLabPro"; string app = System.Windows.Forms.Application.ProductName; string indexName = app == wlp ? ".SPX" : "^GSPC"; //autodetect Fidelity / Yahoo symbol var index = GetExternalSymbol(indexName, true).Close; var rsmk = RSMK.Series(Close, index, slider1.ValueInt, slider2.ValueInt); var rsmkEMA = EMAModern.Series(rsmk, slider4.ValueInt); var offRecentPeak = Highest.Series(rsmk, 20) - slider3.Value; string offPeak = string.Format("{0} pts off peak", slider3.Value); string ema = string.Format("{0}-period EMA of RSMK", slider4.Value); offRecentPeak.Description = offPeak; rsmkEMA.Description = ema; for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { if (IsLastPositionActive) { //sell when the indicator falls by a certain amount below its most recent peak if( rsmk[bar] < offRecentPeak[bar] ) SellAtMarket(bar + 1, LastPosition, offPeak ); else //sell when RSMK crosses below its moving average if (CrossUnder(bar, rsmk, rsmkEMA)) SellAtMarket(bar + 1, LastPosition, "XU (EMA)"); else //sell when RSMK crosses under zero if (CrossUnder(bar, rsmk, 0)) SellAtMarket(bar + 1, LastPosition, "XU (0)"); } else { //A buy signal is propagated when the indicator crosses over zero from below if(CrossOver(bar, rsmk, 0)) BuyAtMarket(bar + 1); } } ChartPane paneRSMK1 = CreatePane(30,true,true); PlotSeries(paneRSMK1,rsmkEMA,Color.Red,LineStyle.Solid,1); PlotSeries(paneRSMK1,offRecentPeak,Color.Blue,LineStyle.Dashed,2); PlotSeries(paneRSMK1,rsmk,Color.DarkGreen,LineStyle.Histogram,3); for (int bar = 1; bar < Bars.Count; bar++) { SetSeriesBarColor(bar, rsmk, rsmk[bar] > 0 ? Color.DarkGreen : Color.Red); SetBackgroundColor(bar, rsmk[bar] > 0 ? Color.FromArgb(30, Color.Gray) : Color.Transparent); } HideVolume(); } } }