using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class SimplifyIt : WealthScript { private StrategyParameter paramTrendRule; public SimplifyIt() { paramTrendRule = CreateParameter("SPY for trend", 1, 0, 1, 1); } protected override void Execute() { bool useSpyForTrend = paramTrendRule.ValueInt == 1; Bars spy = GetExternalSymbol("SPY",true); SMA spySma = SMA.Series(spy.Close,50); SMA sma20 = SMA.Series(Close,20); SMA sma50 = SMA.Series(Close,50); SMA sma200 = SMA.Series(Close,200); SMA smaHi = SMA.Series(High,8); SMA smaLo = SMA.Series(Low,8); //PlotSeries(PricePane,sma20,Color.Orange,WealthLab.LineStyle.Solid,1); PlotSeries(PricePane,sma50,Color.Red,WealthLab.LineStyle.Solid,1); //PlotSeries(PricePane,sma200,Color.Blue,WealthLab.LineStyle.Solid,1); PlotSeriesFillBand(PricePane, smaHi, smaLo, Color.Green, Color.Transparent, LineStyle.Solid, 1); if( useSpyForTrend ) { ChartPane spyPane = CreatePane(30,true,true); PlotSymbol(spyPane,spy,Color.Blue,Color.Red); PlotSeries(spyPane,spySma,Color.Blue,WealthLab.LineStyle.Solid,1); } for(int bar = GetTradingLoopStartBar(200); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if( p.PositionType == PositionType.Long ) { if( Closebar < smaLobar - Bars.SymbolInfo.Tick ) SellAtMarket(bar+1, p ); } else { if( Closebar > smaHibar + Bars.SymbolInfo.Tick ) CoverAtMarket(bar+1, p ); } } else { bool uptrend = // John's / James' method ( useSpyForTrend && (spy.Closebar > spySmabar && spySmabar > spySmabar-1 && Closebar > sma50bar)) || ( sma20bar > sma50bar&& sma50bar > sma200bar); bool downtrend = // John's / James' method ( useSpyForTrend && (spy.Closebar < spySmabar && spySmabar < spySmabar-1 && Closebar < sma50bar)) || ( sma20bar < sma50bar && sma50bar < sma200bar); if( uptrend ) // market trend is up { if( SMA.Series(Volume,50)bar > 1000000 ) // the volume criterion if( Closebar > smaHibar ) // the second step BuyAtMarket(bar + 1); } else if( downtrend ) // market trend is down { if( SMA.Series(Volume,50)bar > 1000000 ) // the volume criterion if( Closebar < smaLobar ) // the second step ShortAtMarket(bar + 1); } } } } } }