using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators;namespace WealthLab.Strategies { public class SZOStrategy : WealthScript { private StrategyParameter paramPeriod; private StrategyParameter paramLongPeriod; private StrategyParameter paramBuy1; private StrategyParameter paramBuy2; private StrategyParameter paramBuy3; public SZOStrategy() { paramPeriod = CreateParameter("SZO Period", 14, 2, 300, 1); paramLongPeriod = CreateParameter("Long Period", 30, 20, 300, 1); paramBuy1 = CreateParameter("Buy1 On/Off", 1, 0, 1, 1); paramBuy2 = CreateParameter("Buy2 On/Off", 1, 0, 1, 1); paramBuy3 = CreateParameter("Buy3 On/Off", 1, 0, 1, 1); } protected override void Execute() { int period = paramPeriod.ValueInt; int LongPeriod = paramLongPeriod.ValueInt; double Percent=95; LineStyle ls = LineStyle.Solid; bool buy1 = paramBuy1.ValueInt > 0; bool buy2 = paramBuy2.ValueInt > 0; bool buy3 = paramBuy1.ValueInt > 0; SZO szo = SZO.Series( Close,period ); SMA ma = SMA.Series( szo,LongPeriod ); Highest HLP = Highest.Series(szo, LongPeriod); Lowest LLP = Lowest.Series(szo, LongPeriod); DataSeries Range = HLP - LLP; DataSeries Prange = Range *(Percent/100d); DataSeries OB = LLP + Prange; OB.Description = "O/B"; DataSeries OS = HLP - Prange; OS.Description = "O/S"; EMA ema = EMA.Series( Close,60,EMACalculation.Modern ); ChartPane szoPane = CreatePane( 30,true,true ); PlotSeriesOscillator( szoPane, szo, 7, -7, Color.Red, Color.Green, Color.Black, ls, 2 ); PlotSeries( szoPane, OB, Color.Red, ls, 1 ); PlotSeries( szoPane, OS, Color.Green, ls, 1 ); DrawHorzLine( szoPane, 7, Color.Red, LineStyle.Dashed, 2 ); DrawHorzLine( szoPane, -7, Color.Green, LineStyle.Dashed, 2 ); HideVolume(); for(int bar = GetTradingLoopStartBar(LongPeriod); bar < Bars.Count; bar++) { bool buyRule1 = CrossOver( bar, szo, 0 ) && (Close[bar] > ema[bar]) && buy1; bool buyRule2 = (Close[bar] > ema[bar]) && (szo[bar] < OS[bar]) && (ma[bar] > ma[bar - 1]) && buy2; bool buyRule3 = ( ma[bar] > 0 ) && CrossOver( bar, szo, -7 ) && (ema[bar] > ema[bar - 1]) && buy3; bool sellRule = CrossUnder( bar, szo, 0 ) || (CrossUnder( bar, szo, 7 ) && (ma[bar] < ma[bar - 1])); if (IsLastPositionActive) { Position p = LastPosition; if( sellRule ) SellAtMarket( bar+1,p ); } else { if( buyRule1 || buyRule2 || buyRule3 ) BuyAtMarket( bar+1 ); } } } } }