Syntax
public static SMA Series(WealthLab.DataSeries ds, int period)
public SMA(DataSeries ds, int period, string description)
public static double Value(int bar, DataSeries ds, int period)
Parameter Description
ds |
The source DataSeries |
period |
Indicator calculation period |
Description
SMA returns the Simple Moving Average indicator. Moving averages are some of the core indicators in technical analysis, and there are a variety of different versions (
EMA,
WMA,
WilderMA, etc. SMA is the easiest moving average to construct. It is simply the average price over the specified
period. The average is called "moving" because it is plotted on the chart bar by bar, forming a line that moves along the chart as the average value changes over the most-recent period.
Interpretation
- SMAs are often used to determine Trend Direction. If the SMA is moving up, the trend is up, moving down and the trend is down. A 200 bar SMA is common proxy for the long term trend. 60 bar SMAs are typically used to gauge the intermediate trend. Shorter period SMAs can be used to determine shorter term trends.
- SMAs are commonly used to smooth price data and technical indicators. Applying an SMA smoothes out choppy data. The longer the period of the SMA, the smoother the result, but the more lag that is introduced between the SMA and the source.
- SMA Crossing Price is often used to trigger trading signals. When prices cross above the SMA go long, when they cross below the SMA go short.
- SMA Crossing SMA is another common trading signal. When a short period SMA crosses above a long period SMA, go long. Go short when the short term SMA crosses back below the long term.
Calculation
SMA is simply the mean, or average, of the values in a
DataSeries over the specified
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()
{
// An SMA Crossover system
int FastPer = 40;
int SlowPer = 100;
DataSeries hFast = SMA.Series( Close, FastPer );
DataSeries hSlow = SMA.Series( Close, SlowPer );
PlotSeries( PricePane, hFast, Color.Red, WealthLab.LineStyle.Solid, 1 );
PlotSeries( PricePane, hSlow, Color.Blue, WealthLab.LineStyle.Solid, 1 );
for(int bar = SlowPer; bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
if( CrossUnder( bar, hFast, hSlow ) )
SellAtMarket( bar+1, LastPosition );
}
else
{
if( CrossOver( bar, hFast, hSlow ) )
BuyAtMarket( bar+1 );
}
}
}
}
}