I think I have the values calculating, but I can't verify and nothing shows on the charts.
What am I missing?
Here is my code:
================================================== =====
#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 MyATR : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyATR";
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;
ATRFactor = 1;
ATRBars = 14;
// AddPlot(Brushes.Red, NinjaTrader.NinjaScript.Indicators.MyATR.HighestBa r);
// AddLine(Brushes.Green, 1, NinjaTrader.NinjaScript.Indicators.MyATR.UpperBar) ;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 1);
}
}
protected override void OnBarUpdate()
{
{
double high0 = High[0];
double low0 = Low[0];
if (CurrentBar == 0)
Value[0] = high0 - low0;
else
{
double close1 = Close[1];
double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
Value[0] = ((Math.Min(CurrentBar + 1, ATRBars) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, ATRBars);
}
LowerBar[0] = Close[0] - (Value[0] * ATRFactor);
UpperBar[0] = Close[0] + (Value[0] * ATRFactor);
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="ATRFactor", Order=1, GroupName="Parameters")]
public double ATRFactor
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ATRBars", Order=2, GroupName="Parameters")]
public int ATRBars
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> LowerBar
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> UpperBar
{
get { return Values[1]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MyATR[] cacheMyATR;
public MyATR MyATR(double aTRFactor, int aTRBars)
{
return MyATR(Input, aTRFactor, aTRBars);
}
public MyATR MyATR(ISeries<double> input, double aTRFactor, int aTRBars)
{
if (cacheMyATR != null)
for (int idx = 0; idx < cacheMyATR.Length; idx++)
if (cacheMyATR[idx] != null && cacheMyATR[idx].ATRFactor == aTRFactor && cacheMyATR[idx].ATRBars == aTRBars && cacheMyATR[idx].EqualsInput(input))
return cacheMyATR[idx];
return CacheIndicator<MyATR>(new MyATR(){ ATRFactor = aTRFactor, ATRBars = aTRBars }, input, ref cacheMyATR);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MyATR MyATR(double aTRFactor, int aTRBars)
{
return indicator.MyATR(Input, aTRFactor, aTRBars);
}
public Indicators.MyATR MyATR(ISeries<double> input , double aTRFactor, int aTRBars)
{
return indicator.MyATR(input, aTRFactor, aTRBars);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MyATR MyATR(double aTRFactor, int aTRBars)
{
return indicator.MyATR(Input, aTRFactor, aTRBars);
}
public Indicators.MyATR MyATR(ISeries<double> input , double aTRFactor, int aTRBars)
{
return indicator.MyATR(input, aTRFactor, aTRBars);
}
}
}
#endregion
Comment