Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Slight difference in ATR value compared with Market Analyzer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Slight difference in ATR value compared with Market Analyzer

    Hello.

    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);

    }

    }
    }​
    Attached Files

    #2
    Hello stevec1824,

    That may be due to differences in the bars between the analyzer and the chart. I would suggest to try and make a copy of the original ATR by opening it in the editor -> right click -> save as. Then in the scripts OnBarUpdate put a print to output the bar times and prices:

    Print(Time[0] + " " + Close[0]);

    You can then add the same print to your indicator and then compare the prints to check that the underlying bars were identical and that the same data was processed.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    556 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X