// Copyright OptimusFLOW LLC. © 2017-2018. All rights reserved.
using TradingPlatform.BusinessLayer;
public class SMA : Indicator
[InputParameter("Period of Simple Moving Average", 0, 1, 999, 1, 1)]
// Second input parameter
[InputParameter("Sources prices for MA", 1, variants: new object[]{
"Close", PriceType.Close,
"Typical", PriceType.Typical,
"Median", PriceType.Median,
"Weighted", PriceType.Weighted
public PriceType SourcePrice = PriceType.Close;
/// Indicator's constructor. Contains general information: name, description, LineSeries etc.
// Here we set an indicator's name and description
Name = "Simple Moving Average Example";
Description = "Average price for the last N periods";
ShortName = "SMA (" + Period + ":" + SourcePrice.ToString() + ")";
// Our indicator has only one line
AddLineSeries("SMA", Color.Red, 1, LineStyle.Solid);
//Indicator will be drawn directly on chart
/// This function will be called after creating an indicator as well as after its input params reset or chart (symbol or timeframe) updates.
protected override void OnInit()
/// Calculation entry point. This function is called when a price data updates.
/// Will be runing under the HistoricalBar mode during history loading.
/// Under NewTick during realtime.
/// Under NewBar if start of the new bar is required.
/// <param name="args">Provides data of updating reason and incoming price.</param>
protected override void OnUpdate(UpdateArgs args)
// Checking, if current amount of bars
// more, than period of moving average. If it is
// then the calculation is possible
double sum = 0.0; // Sum of prices
for (int i = 0; i < Period; i++)
// Adding bar's price to the sum
sum += GetPrice(SourcePrice, i);
// Set value to the "SMA" line buffer.