using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Indicators;namespace WealthLab.Strategies { public class TASCJune2015 : WealthScript { private StrategyParameter paramRSI; private StrategyParameter paramMult; private StrategyParameter paramUseTF; private StrategyParameter paramUseRisingRSI; private StrategyParameter paramCloseOnReverse; public TASCJune2015() { paramRSI = CreateParameter("RSI Period", 14, 2, 30, 2); paramMult = CreateParameter("% Reversal", 20, 5, 50, 5); paramUseTF = CreateParameter("Trend filter?", 0, 0, 1, 1); paramUseRisingRSI = CreateParameter("Rising RSI?", 0, 0, 1, 1); paramCloseOnReverse = CreateParameter("Close on reverse?", 0, 0, 1, 1); } protected override void Execute() { double Mult = paramMult.Value; bool trendFilter = paramUseTF.ValueInt == 1 ? true : false; // Entering when the RSI is moving up and crossing above 50. bool risingRSI = paramUseRisingRSI.ValueInt == 1 ? true : false; // Closing positions when uptrend reverses, that is, prices move down by more than 20% from the high of prior uptrend. bool closeOnTrendReverse = paramCloseOnReverse.ValueInt == 1 ? true : false; double ob = 70, os = risingRSI ? 50 : 30; NRTR_Percent trendLine = NRTR_Percent.Series( Bars, Mult ); //PlotSeries( PricePane, trendLine, Color.Blue, LineStyle.Solid, 2 ); int rsiPeriod = paramRSI.ValueInt; RSI rsi = RSI.Series( Close, rsiPeriod ); ChartPane rsiPane = CreatePane( 30,true,true ); PlotSeries( rsiPane, rsi, Color.Violet, LineStyle.Solid, 2 ); DrawHorzLine( rsiPane, ob, Color.Blue, LineStyle.Dashed, 1 ); DrawHorzLine( rsiPane, os, Color.Blue, LineStyle.Dashed, 1 ); for(int bar = GetTradingLoopStartBar(20); bar < Bars.Count; bar++) { // Entering trades only during uptrends, that is, when prices move up by more than 20% from low of prior uptrend. bool uptrend = Close[bar] > trendLine[bar]; SetBackgroundColor( bar, Color.FromArgb( 30, uptrend ? Color.Green : Color.Red ) ); if (IsLastPositionActive) { if( closeOnTrendReverse ) { if( !uptrend ) SellAtMarket(bar+1, LastPosition, "Uptrend reversed" ); } if( CrossOver( bar, rsi, ob ) ) { SellAtMarket(bar+1, LastPosition, "RSI" ); } } else { if( CrossUnder( bar, rsi, os ) ) { if( ( trendFilter && uptrend ) || !trendFilter ) BuyAtMarket(bar+1, Bars.FormatValue(rsi[bar]) ); } } } } } }