'20HrlySMAonTick' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load NQ MAR25 Globex: 60 Minute
Here is the Indicator:
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class 20HrlySMAonTick : Indicator
{
private SMA SMA1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "20HrlySMAonTick";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(Brushes.LightCoral, "SMAPlot");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 60); //add our secondary 60 minute data series for calculating the SMA
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(BarsArray[1], 20); //set SMA here so we make sure it's calculated on the secondary data series
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1 || CurrentBars[1] < 20)
return;
if(BarsInProgress == 0) // if OnBarUpdate was called from the primary bar series, then set the current value to the latest SMA1 value
Value[0] = SMA1[0];
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> SMAPlot
{
get { return Values[0]; }
}
#endregion
}
}​

Comment