using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators;namespace WealthLab.Strategies { public class SVEStochRSIDivergence : WealthScript { StrategyParameter rsiPeriod; StrategyParameter stoPeriod; StrategyParameter smaPeriod; public SVEStochRSIDivergence() { rsiPeriod = CreateParameter("SVEStochRSI Period", 21, 2, 200, 20); stoPeriod = CreateParameter("Stochastic Period", 8, 2, 200, 20); smaPeriod = CreateParameter("SVEStochRSI Period", 5, 2, 200, 20); } protected override void Execute() { HideVolume(); DataSeries srsi = SVEStochRSI.Series(Close, rsiPeriod.ValueInt, stoPeriod.ValueInt, smaPeriod.ValueInt); ChartPane rsiPane = CreatePane(40, true, true); PlotSeries(rsiPane, srsi, Color.Red, LineStyle.Solid, 2); for (int bar = 3 * GetTradingLoopStartBar(srsi.FirstValidValue) ; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if (bar + 1 - p.EntryBar > 6) ExitAtMarket(bar + 1, p, "Time-based"); } else if (CrossUnder(bar, srsi, 70)) { // check the last two SVEStochRSI peaks for negative divergence with price int pb1 = (int)PeakBar.Value(bar, srsi, 20, PeakTroughMode.Value); if (pb1 == -1) continue; int pb2 = (int)PeakBar.Value(pb1, srsi, 20, PeakTroughMode.Value); if (pb2 == -1) continue; if ( Math.Sign(srsipb1 - srsipb2) == -1 && Math.Sign(Highpb1 - Highpb2) == 1) { SetBackgroundColor(bar, Color.FromArgb(50, Color.Green)); DrawLine(rsiPane, pb2, srsipb2, pb1, srsipb1, Color.Blue, LineStyle.Solid, 2); DrawLine(PricePane, pb2, Highpb2, pb1, Highpb1, Color.Blue, LineStyle.Solid, 2); ShortAtMarket(bar + 1); } } } } } }