Syntax
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)
Parameter Description
ds |
Data series to be smoothed with a moving average |
period |
Length used to calculate the moving average (center line) |
pct |
Envelope percentage |
ma |
Select between the moving average types: SMA, EMA or WMA |
Description
Moving average envelopes are lines plotted a certain percentage (default is 5%) above and below a moving average of price. They are also known as trading bands, moving average bands, price envelopes and percentage envelopes.
Interpretation
The logic behind envelopes is that overzealous buyers and sellers push the price to the extremes (i.e., the upper and lower bands), at which point the prices often stabilize by moving to more realistic levels. This is similar to the interpretation of Bollinger Bands.
When the security's price touches the upper band and turns down, the security might be at an overbought level. Conversely, when the security's price touches the lower band and turns up, the security might be at an oversold level.
Example
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 );
}
}
}
}
}