Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble getting the ATR to print on screen.

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

    Trouble getting the ATR to print on screen.

    Hello,
    I've been stabbing away at this for a while thinking I got it then I find the ATR is not correct. I would greatly appreciate any help with getting the correct ATR to print to the screen. Thank you for any time in advance. I know it is the holidays. Merry Christmas everyone.

    Below is the script that I have. Thanks again for any time invested.

    private double ScalpTarget;
    private double SwingTarget;
    private ATR ATR1;
    private Gui.Tools.SimpleFont textFont;
    private string scalptargetinfo;
    private string swingtargetinfo;




    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TOTtargets";
    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;

    BarPeriod = 20;
    textFont = new Gui.Tools.SimpleFont("Arial", 14);
    TextColor = Brushes.Red;
    TextBackColor = Brushes.Yellow;
    ShowScalpTarget = false;
    ShowSwingTarget = true;
    TextPosition = TextPosition.BottomRight;


    }
    else if (State == State.Configure)
    {

    }
    else if (State == State.DataLoaded)


    {
    ATR1 = ATR(Close,(BarPeriod));

    scalptargetinfo = ("Scalp Target: ") + Convert.ToInt32(ATR1[0]/2);
    swingtargetinfo = ("Swing Target: ") + Convert.ToInt32(ATR1[0]);
    }

    }


    protected override void OnBarUpdate()


    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;


    if ((ATR1[0] > 0)
    && (ShowScalpTarget == true))

    {



    Draw.TextFixed(this, @"ScalpTarget", scalptargetinfo, TextPosition, TextColor, TextFont, Brushes.Transparent, TextBackColor, 100 );

    }
    if ((ATR1[0] > 0)
    && (ShowSwingTarget == true))

    {



    Draw.TextFixed(this, @"SwingTarget", swingtargetinfo, TextPosition, TextColor, TextFont, Brushes.Transparent, TextBackColor, 100 );

    }
    }

    #2
    Hello laoshr,

    Are you suggesting the code in the ATR indicator is incorrect, or are you seeing that when adding the indicator with AddChartIndicator() that the values are not matching what is printed to the output window?

    Have you printed the ATR value to the output window?

    If not, below is a link to a forum post that demonstrates using prints to understand behavior.


    Print the time of the bar and the value of the ATR and let me know if this is not matching the chart.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,
      No, I'm not thinking the ATR indicator is incorrect. What I'm wanting to do is just print the ATR on the chart instead of it as a line in the indicator panel. I posted the code above and the value that is printed on the chart does not match the ATR value. I've tried quite a few things to try and correct it and was wondering if there is something I have out of place?
      Thank you for your time and Happy New Year.
      James

      Comment


        #4
        Hello James,

        AddChartIndicator adds the same instance of the indicator that is used in the code onto the chart. They are not different instances and would not have different values.

        Are you certain you have not manually added a different instance to the chart than the one added with AddChartIndicator()?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 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
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X