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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    50 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    69 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    36 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    97 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    60 views
    0 likes
    Last Post PaulMohn  
    Working...
    X