I am just getting started with NinjaScript and I was trying to plot 3 moving averages but it doesn't seem to work it right. It is only showing 1 moving average with the below code. Kindly help me identify what is wrong with my coding and is there something missing to associate the value of plots from the moving averages variables. Thanks.
region Using declarations
using System;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
#endregion
// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.KezyIndicators
{
/// <summary>
/// The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
public class MyMA3 : Indicator
{
private EMA emaFast;
private SMA smaMedium;
private SMA smaSlow;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "My 3 moving Average, Fast EMA, Medium SMA, Slow SMA";
Name = "MyMA3";
IsOverlay = true;
FastEMA = 9;
MediumSMA = 50;
SlowSMA = 200;
AddPlot(Brushes.White, "Fast");
AddPlot(Brushes.Cyan, "Medium");
AddPlot(Brushes.Magenta, "Slow");
}
else if (State == State.DataLoaded)
{
emaFast = EMA(FastEMA);
smaMedium = SMA(MediumSMA);
smaSlow = SMA(SlowSMA);
}
}
protected override void OnBarUpdate()
{
Fast[0] = emaFast[0];
Medium[0] = smaMedium[0];
Slow[0] = smaSlow[0];
Plots[0].Brush = Brushes.White;
Plots[1].Brush = Brushes.Cyan;
Plots[2].Brush = Brushes.Magenta;
}
public Series<double> Fast
{
get { return Values[0]; }
}
public Series<double> Medium
{
get { return Values[1]; }
}
public Series<double> Slow
{
get { return Values[2]; }
}
region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "FastEMA", GroupName = "MA Parameters", Order = 0)]
public int FastEMA
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "MediumSMA", GroupName = "MA Parameters", Order = 0)]
public int MediumSMA
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "SlowSMA", GroupName = "MA Parameters", Order = 0)]
public int SlowSMA
{ get; set; }
#endregion

Comment