DataSeries SMI (Bars bars, int period1, int period2, int period3, string description) public static SMI Series(Bars bars, int period1, int period2, int period3)
M = (HighMAX + LowMIN) / 2
D = CPTODAY – M
DS1 = EMA(3)(D) DS2 = EMA(3)(DS1)
DHL = EMA(3)(HighMAX - LowMIN) DHL2 = EMA(3)(DHL) / 2
SMITODAY = 100 * (DS2 / DHL2)
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 SMIDemo : WealthScript { private StrategyParameter paramPeriod1; private StrategyParameter paramPeriod2; private StrategyParameter paramPeriod3; public SMIDemo() { paramPeriod1 = CreateParameter("Period 1", 10, 2, 20, 1); paramPeriod2 = CreateParameter("Period 2", 3, 2, 10, 1); paramPeriod3 = CreateParameter("Period 3", 3, 2, 20, 1); } protected override void Execute() { int per1 = paramPeriod1.ValueInt; int per2 = paramPeriod2.ValueInt; int per3 = paramPeriod3.ValueInt; SMI smi = SMI.Series( Bars,per1,per2,per3 ); for(int bar = GetTradingLoopStartBar(smi.FirstValidValue * 3); bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( CrossUnder( bar, smi, -40 ) ) SellAtMarket( bar+1, LastPosition ); } else { if( CrossOver( bar, smi, 40 ) ) BuyAtMarket( bar+1 ); } } ChartPane sPane = CreatePane( 40,true,true ); PlotSeries( sPane, smi, Color.Fuchsia, LineStyle.Solid, 2 ); DrawHorzLine( sPane, 40, Color.Green, LineStyle.Dashed, 1 ); DrawHorzLine( sPane, -40, Color.Red, LineStyle.Dashed, 1 ); HideVolume(); } } }