Can someone help me?
I have created this indicator in Thinkorswim so now I am trying translate it to Ninjatrader but i cant seem to get it to compile in Ninjascript editor.
#region Using declarations
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;
#endregion
namespace NinjaTrader.NinjaScript.Indicators
{
public class ATRBasedPivots : Indicator
{
private ATR atr;
private Series sessionOpen;
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(Name = "ATR Period", Order = 0, GroupName = "Parameters")]
public int ATRPeriod { get; set; }
[Range(0, int.MaxValue), NinjaScriptProperty]
[Display(Name = "ATR Bars Ago (0 = current, 1 = prior)", Order = 1, GroupName = "Parameters")]
public int ATRBarsAgo { get; set; }
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "ATRBasedPivots";
Description = "Plots ATR-based pivot levels centered on the session open";
IsOverlay = true;
IsChartOnly = true;
DisplayInDataBox = false;
IsSuspendedWhileInactive = true;
ATRPeriod = 14;
ATRBarsAgo = 1;
AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 1), PlotStyle.HLine, "S2");
AddPlot(new Stroke(Brushes.Orange, DashStyleHelper.Solid, 1), PlotStyle.HLine, "S1");
AddPlot(new Stroke(Brushes.Green, DashStyleHelper.Solid, 1), PlotStyle.HLine, "R1");
AddPlot(new Stroke(Brushes.DarkGreen, DashStyleHelper.Solid, 1), PlotStyle.HLine, "R2");
}
else if (State == State.Configure)
{
AddDataSeries(Bars.Instrument.FullName, BarsPeriodType.Day, 1); // Daily series for ATR
}
else if (State == State.DataLoaded)
{
atr = ATR(BarsArray[1], ATRPeriod);
sessionOpen = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (BarsArray[1].Count <= ATRBarsAgo + ATRPeriod || CurrentBar < 1)
return;
if (Bars.IsFirstBarOfSession)
sessionOpen[0] = Open[0];
double open = sessionOpen[0];
double atrValue = atr[ATRBarsAgo];
// Calculate pivot lines
double s2 = open - atrValue;
double s1 = open - atrValue / 2.0;
double r1 = open + atrValue / 2.0;
double r2 = open + atrValue;
// Set values for plotting
Values[0][0] = s2;
Values[1][0] = s1;
Values[2][0] = r1;
Values[3][0] = r2;
}
}
}