Moving Averages Envelope

Moving Average Envelopes are percentage-based envelopes set above and below a moving average. The moving average, which forms the base for this indicator, can be a simple or exponential moving average. Each envelope is then set the same percentage above or below the moving average. This creates parallel bands that follow price action. With a moving average as the base, Moving Average Envelopes can be used as a trend following indicator. However, this indicator is not limited to just trend following. The envelopes can also be used to identify overbought and oversold levels when the trend is relatively flat.

Indicators based on channels, bands and envelopes are designed to encompass most price action. Therefore, moves above or below the envelopes warrant attention. Trends often start with strong moves in one direction or another. A surge above the upper envelope shows extraordinary strength, while a plunge below the lower envelope shows extraordinary weakness. Such strong moves can signal the end of one trend and the beginning of another.

With a moving average as its foundation, Moving Average Envelopes are a natural trend following indicator. As with moving averages, the envelopes will lag price action. The direction of the moving average dictates the direction of the channel. In general, a downtrend is present when the channel moves lower, while an uptrend exists when the channel moves higher. The trend is flat when the channel moves sideways.

Sometimes a strong trend does not take hold after an envelope break and prices move into a trading range. Such trading ranges are marked by a relatively flat moving average. The envelopes can then be used to identify overbought and oversold levels for trading purposes. A move above the upper envelope denotes an overbought situation, while a move below the lower envelope marks an oversold condition.

Calculation:

Upper Band = MA(Close, n * [1 + k]
Lower Band = MA(Close, n) * [1 - k]

Where:

  • MA— chosen Moving Average (Simple or Exponential);
  • n — averaging period;
  • k — the percentage value of shifting from the average.

Implementation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
 
namespace cAlgo.Indicators
{
  [Indicator(IsOverlay = true)] // Drawing on main chart area
  public class Envelopes : Indicator
  {
    [Parameter("Data Series")]
    public DataSeries SourceSeries { get; set; }
    [Parameter("MA Period";, DefaultValue = 14)
    public int MAPeriod { get; set; }
    [Parameter("MA Type";, DefaultValue = MovingAverageType.Simple)]
    public MovingAverageType MAType { get; set; }
    [Parameter("Shift (percentage)", DefaultValue = 0.1)]
    public double Deviation { get; set; }
 
    [Output("Upper Band", Color=Colors:Red)]
    public IndicatorDataSeries UpperBand { get; set; }
    [Output("Lower Band", Color=Colors:Blue)]
    public IndicatorDataSeries LowerBand { get; set; }
 
    private MovingAverage ma;
 
    protected override void Initialize()
    {
      ma = Indicators.MovingAverage(SourceSeries, MAPeriod, MAType);
    }
 
    public override void Calculate(int index)
    {
      UpperBand[index] = ma.Result[index] * (1 + Deviation/100);
      LowerBand[index] = ma.Result[index] * (1 - Deviation/100);
    }
  }
}

1 Comment

  1. Can I use this API fo commercial license?
    Great API

Leave a Reply to Berita Terbaru Cancel reply

Your email address will not be published. Required fields are marked *