Simple Moving Average
Tools exist for creating simple moving average (SMA) curves and displaying them next to finanial data.
ScottPlot.Plot myPlot = new();
// generate and plot time series price data
var prices = Generate.RandomOHLCs(75);
myPlot.Add.Candlestick(prices);
myPlot.Axes.DateTimeTicksBottom();
// calculate SMA and display it as a scatter plot
int[] windowSizes = { 3, 8, 20 };
foreach (int windowSize in windowSizes)
{
ScottPlot.Finance.SimpleMovingAverage sma = new(prices, windowSize);
var sp = myPlot.Add.Scatter(sma.Dates, sma.Means);
sp.LegendText = $"SMA {windowSize}";
sp.MarkerSize = 0;
sp.LineWidth = 3;
sp.Color = Colors.Navy.WithAlpha(1 - windowSize / 30.0);
}
myPlot.ShowLegend();
myPlot.SavePng("demo.png", 400, 300);
This recipe is one of many in the Financial Plot category
