Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90


Drawing tool: access value calculated by indicator

  • Filter
  • Time
  • Show
Clear All
new posts

    Drawing tool: access value calculated by indicator


    I created a couple of indicators and a couple of drawing tools for NT8.
    I need to create a custom drawing tool that needs to read a value calculated by an indicator (the indicator also output the value in the Data Box). The indicator value would be used to create the shape of the drawing tool.
    How can I do that?
    I know how to read the data series values but after searching for many hours on this forum, reading the help guide and trying everything that came to my mind have yet to find how to read indicator output value from a custom drawing tool.

    Thank you

    Hello PriceSurfer,

    Thanks for your question.

    You'll have to loop through the chart's Indicators collection to find your target indicator, and then you can cast that base indicator as your target indicator class so you can reference the plot with GetValueAt(). You can get the barIndex by checking the coordinate and using ChartBars.GetBarIdxByX().

    You could try the following in your OnMouseDown method:

    ChartObjectCollection<NinjaTrader.Gui.NinjaScript.IndicatorRenderBase> indicatorCollection = chartControl.Indicators;
    Point point = dataPoint.GetPoint(chartControl, chartPanel, chartScale);
    int barIndex = GetAttachedToChartBars().GetBarIdxByX(chartControl, (int)point.X);
    foreach (NinjaTrader.Gui.NinjaScript.IndicatorRenderBase indicator in indicatorCollection)
        if (indicator.Name == "TargetIndi")
            Print((indicator as NinjaTrader.NinjaScript.Indicators.TargetIndi).IndiPlot.GetValueAt(barIndex));
    Publicly available documentation on these items is linked below:

    Indicators collection -

    GetAttachedToChartBars -

    ChartBars.GetBarIdxByX -

    GetValueAt() -

    Please let us know if we can be of further assistance.
    Attached Files
    JimNinjaTrader Customer Service


      Hi NinjaTrader_Jim,

      I found you post by searching for the answer to a different question, which was how to programmatically detect the color that another indicator is on a certain bar - how would one do that?

      As a side question, I read in the help that the ChartControl object should only be accessed after the state has become historical. Would it be safe to say that you can get a valid reference it it in OnBarUpdate()?




        Hello Gordon,

        In order to detect when an indicator has changed the bar color, you will want to incorporate the same check in your strategy or hosting indicator.

        As a rough example, if an indicator colors a bar if (Close[0] > Open[0]) then you would want to make the same logical check in the strategy.

        Alternatively, the indicator could expose a value when it changes bar colors, and then the strategy can read that indicator's public variable to see if it is plotting bars of X color.

        The same can be said for indicators that host another indicator, and this would not be limited to strategies hosting indicators.

        The example linked below demonstrates how public variables can be exposed in an indicator and how those exposed variables can be referenced in a hosting script.

        We look forward to assisting.
        JimNinjaTrader Customer Service


          Hi Jim,

          Thanks. Unfortunately I don't know the underlying logic behind why the indicator colors a line the way it does. Is there a way to detect the plot color of another indicator programmatically?

          Also, by the way, what does the variable dataPoint refer to in the code snippet above?


          Last edited by grose; 04-28-2020, 06:23 PM.


            Hello Gordon,

            This thread was originally about Drawing Tools. "dataPoint" comes from the OnMouseDown method of a Drawing Tool.

            public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, [B]ChartAnchor dataPoint[/B])
                // add any logic for when the mouse is left clicked here
            Knowing how the plot color changes would require understanding how the indicator sets that color. You would not be able to check the PlotBrushes property from an external script to determine the plot's color.

            If you have any additional questions that are different from the topic here, please don't hesitate to open a new thread.
            JimNinjaTrader Customer Service


            Latest Posts


            Topics Statistics Last Post
            Started by trader24211341, 03-09-2023, 12:30 PM
            2 responses
            Last Post trader24211341  
            Started by ct, Today, 04:56 PM
            0 responses
            1 view
            Last Post ct
            by ct
            Started by qewcool, 03-19-2023, 05:51 PM
            24 responses
            1 like
            Last Post jama12
            by jama12
            Started by GussJ, Today, 07:43 AM
            3 responses
            Last Post GussJ
            by GussJ
            Started by GussJ, Today, 09:30 AM
            10 responses
            Last Post GussJ
            by GussJ