public EnvelopeUpper(DataSeries ds, int period, double pct, ChoiceOfMA ma, string description) public static EnvelopeUpper Series(DataSeries ds, int period, double pct, ChoiceOfMA ma)public EnvelopeLower(DataSeries ds, int period, double pct, ChoiceOfMA ma, string description) public static EnvelopeLower Series(DataSeries ds, int period, double pct, ChoiceOfMA ma)
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 MAEnvelopeDemo : WealthScript { private StrategyParameter paramPeriod; private StrategyParameter paramMult; public MAEnvelopeDemo() { paramPeriod = CreateParameter("MA Period", 20, 5, 50, 1); paramMult = CreateParameter("Percent", 10, 1, 10, 0.5); } protected override void Execute() { int period = paramPeriod.ValueInt; double pct = paramMult.Value; SMA sma = SMA.Series( Close,period ); EnvelopeUpper eu = EnvelopeUpper.Series( Close,period,pct,ChoiceOfMA.SMA ); EnvelopeLower el = EnvelopeLower.Series( Close,period,pct,ChoiceOfMA.SMA ); PlotSeries( PricePane, sma, Color.Red, LineStyle.Solid, 1 ); PlotSeriesFillBand( PricePane, eu, el, Color.FromArgb( 30, Color.Blue ), Color.FromArgb( 30, Color.Blue ), LineStyle.Solid, 1 ); bool Trade = false; for(int bar = period; bar < Bars.Count; bar++) { Trade = false; if (IsLastPositionActive) { Position p = LastPosition; if( p.PositionType != PositionType.Long ) { if( CrossUnder( bar, Close, sma ) ) CoverAtMarket( bar+1, p ); } else { if( CrossOver( bar, Close, sma ) ) SellAtMarket( bar+1, p ); } } else { if( CrossOver( bar, Close, eu ) ) Trade = ( ShortAtMarket( bar+1 ) != null ); if( !Trade ) if( CrossUnder( bar, Close, el ) ) Trade = ( BuyAtMarket( bar+1 ) != null ); } } } } }