using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class RSIwithRSI : WealthScript { private StrategyParameter paramLoser; private StrategyParameter paramExit; public RSIwithRSI() { paramLoser = CreateParameter("Exit loser?", 0, 0, 1, 1); paramExit = CreateParameter("Exit loser after", 20, 2, 50, 2); } protected override void Execute() { DataSeries rsiSlow = RSI.Series(Close, 17); DataSeries maSlow = SMA.Series(Close, 40); DataSeries maFast = SMA.Series(Close, 10); DataSeries rsiFast = RSI.Series(Close, 5); ChartPane paneRSI = CreatePane(35,true,true); PlotSeries(paneRSI, rsiSlow, Color.Blue, LineStyle.Solid, 2); PlotSeries(paneRSI, rsiFast, Color.Red, LineStyle.Solid, 2); DrawHorzLine(paneRSI, 60.00, Color.Green, LineStyle.Solid, 1); DrawHorzLine(paneRSI, 40.00, Color.Red, LineStyle.Solid, 1); PlotSeries(PricePane,maSlow,Color.Blue,LineStyle.Solid,2); PlotSeries(PricePane,maFast,Color.Red,LineStyle.Solid,2); for(int bar = GetTradingLoopStartBar(40); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if( paramLoser.ValueInt == 1 && p.NetProfitAsOfBarPercent(bar) <= 0 && bar > p.EntryBar + paramExit.ValueInt ) SellAtMarket( bar+1, p, "Exit loser" ); if (p.EntrySignal.Contains("correction")) { if( (Closebar < maFastbar) && CrossUnder(bar, rsiFast, 40) ) SellAtMarket(bar + 1, p, "Correction sell"); } else { if( (Closebar < maSlowbar) && CrossUnder(bar, rsiSlow, 40.00) ) SellAtMarket(bar + 1, p, "Trend sell"); } } else { if( ( rsiSlowbar < 40 ) && CrossOver(bar, rsiFast, 60.00) && (Closebar > maFastbar) ) if( BuyAtMarket(bar + 1, "correction") != null ) LastPosition.Priority = -Closebar; if (CrossOver(bar, rsiSlow, 60.00) && (Closebar > maSlowbar) ) if( BuyAtMarket(bar + 1, "trend") != null ) LastPosition.Priority = -Closebar; } } } } }