Simple Moving Average (SMA)
Moving average indicator which measures the trend direction over a period of time.
Last updated
Moving average indicator which measures the trend direction over a period of time.
Last updated
// Prints the current value of a 20 period SMA using
// the daily bars close price value.
sma = indicators.SMA(20).OnSeries(dailyBars.Close);
Log(sma.Value.ToString());
// Prints the previous value of SMA.
sma = indicators.SMA(20).Keep(2).OnSeries(dailyBars.Close);
Log(sma.Values[1].ToString());using Signals.DataSeries.Bars;
using Signals.Framework;
using Signals.Indicators.SMA;
public class MyStrategy : SingleMarketStrategy
{
private Bars dailyBars;
private SMA sma;
public override void Setup(DataMarketplace data, IndicatorsMarketplace indicators)
{
dailyBars = data.Bars(BarPeriodType.Day, 1).WithOffset(50);
sma = indicators.SMA(20).Keep(2).OnSeries(dailyBars.Close);
}
public override void RegisterActions()
{
OnUpdateOf(dailyBars).Do(() =>
{
// Prints the current SMA value
Log("The current SMA value is " + sma.Value.ToString());
// Prints the previous SMA value
Log("The previous SMA value is " + sma.Values[1].ToString());
});
}
}