Syntax
public EMA(DataSeries source, int period, EMACalculation calcType, string description)
public static EMA Series(DataSeries source, int period, EMACalculation calcType)
Parameter Description
source |
Price series |
int |
Indicator calculation period |
calcType |
EMACalculation enum: (EMACalculation.Legacy, EMACalculation.Modern)
|
Description
EMA returns the Exponential Moving Average of the specified
period. EMA is similar to Simple Moving Average (
SMA), in that it averages the data over a period of time. However, whereas
SMA just calculates a straight average of the data, EMA applies more weight to the data that is more current. The most weight is placed on the most recent data point. Because of the way it's calculated, EMA will follow prices more closely than a corresponding
SMA.
Interpretation
- Use the same rules that we apply to SMA when interpreting EMA. Keep in mind, though, that EMA is generally more sensitive to price movement. This can be a double-edged sword. On the one hand, it can get you into trends a bit earlier than an SMA would. On the other hand, the EMA will probably experience more whipsaws than a corresponding SMA.
- Use the EMA to determine trend direction, and trade in that direction. When the EMA rises then buy when prices dip near or a bit below the EMA. When the EMA falls then sell when prices rally towards or a bit above the EMA.
- Moving averages can also indicate support and resistance areas. A rising EMA tends to support the price action and a falling EMA tends to provide resistance to price action. This reinforces the idea of buying when price is near the rising EMA or selling when price is near the falling EMA.
- All moving averages, including the EMA are not designed to get you into a trade near the bottom and out again at the top. They tend to ensure your trading in the general direction of the trend, but with a delay at the entry and exit. The EMA has a shorter delay than the SMA with the same period.
- As a rule-of-thumb, EMA requires approximately three times its period to stabilize (see the WealthScript Programming Guide, Indicators chapters, Stability of Indicators for details).
Calculation
You should notice how the EMA use the previous value of the EMA in its calculation, this means the EMA includes all the price data within its current value. The newest price data has the most impact on the average and the oldest prices data has only a minimal impact.
EMA = ( K x ( C - EMA
1 ) ) + EMA
1where,
C = Current Price
EMA
1 = Previous bar's EMA value (A
SMA is used for the first period's calculation)
K = Exponential smoothing constant
The smoothing constant K, applies appropriate weight to the most recent price. It uses the number of periods specified in the moving average. With Wealth-Lab you have a choice of two methods for calculating the smoothing constant.
Two similar but not equivalent formulas are available for calculating the exponent; Wealth-Lab's original method (from Pring's Technical Analysis Explained), which is selected by passing EMACalculation.Legacy as the
calcType parameter.
K = ( 1 / period ) * 2
and perhaps a more common method, which is referred to as the "Modern method", selected by passing EMACalculation.Modern as the
calcType parameter.
K = 2 / ( 1 + period )
Example
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
// Dual EMA CrossOver System }
DataSeries ema60 = EMA.Series( Close, 60, WealthLab.Indicators.EMACalculation.Modern );
DataSeries ema120 = EMA.Series( Close, 120, EMACalculation.Modern );
PlotSeries( PricePane, ema60, Color.Black, WealthLab.LineStyle.Solid, 3 );
PlotSeries( PricePane, ema120, Color.DarkGray, LineStyle.Solid, 1 );
// EMA is one of unstable indicators, initialize the loop accordingly
for(int bar = 120*3; bar < Bars.Count; bar++)
{
if (!IsLastPositionActive)
{
if( CrossOver( bar, ema60, ema120 ) )
BuyAtMarket( bar+1 );
}
else
{
if( CrossUnder( bar, ema60, ema120 ) )
SellAtMarket( bar+1, LastPosition );
}
}
}
}
}