I have a custom indicator I wrote that gets the 7 day ATR from the Daily bars (AddDataSeries...). When I compare the return value of the ATR function with the 7 day ATR in the Market Analyzer, they are close, but don't match exactly. I am trying to figure out what the difference is. Does the ATR function indicator include current days data and the ATR in the Market Analyzer not include intraday data?
Thanks
Steve
Here is my source code
namespace NinjaTrader.NinjaScript.Indicators
{
public class scShowDebugMessage1 : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"";
Name = "scShowDebugMessage1";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = false;
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;
}
else if (State == State.Configure)
{
AddDataSeries(Instrument.FullName, new BarsPeriod() { BarsPeriodType = (BarsPeriodType)5, Value = 1}, 30,"", null);
}
}
protected override void OnBarUpdate()
{
string msg1 = "", range1 = "", volatility1 = "";
double atr1 = 0.0, val1 = 0.0, high1 = 0.0, low1 = 0.0;
if (CurrentBars[0] < 0)
return;
if (Bars == null)
return;
if (CurrentBar <= BarsRequiredToPlot)
return;
if (BarsInProgress == 0)
{
high1 = CurrentDayOHL().CurrentHigh[0];
low1 = CurrentDayOHL().CurrentLow[0];
}
range1 = (high1 - low1).ToString();
atr1 = ATR(BarsArray[1], 7)[0];
atr1 = Math.Round(atr1,1);
val1 = ((high1 - low1) / atr1) * 100.0;
volatility1 = Math.Round(val1,1).ToString() + "%";
msg1 = "atr = " + atr1.ToString() + ", range = " + range1 + ", volatility = " + volatility1.ToString();
NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 1) { Size = 18, Bold = true };
Draw.TextFixed(this, "MyObject", msg1, TextPosition.TopRight, Brushes.Cyan, myFont, null, null, 100);
}
}
}

Comment