• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing tool: access value calculated by indicator

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

    Drawing tool: access value calculated by indicator

    Hi,

    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

    #2
    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:

    Code:
    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 - https://ninjatrader.com/support/help...indicators.htm

    GetAttachedToChartBars - https://ninjatrader.com/support/help...ochartbars.htm

    ChartBars.GetBarIdxByX - https://ninjatrader.com/support/help...tbaridxbyx.htm

    GetValueAt() - https://ninjatrader.com/support/help...getvalueat.htm

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

    Comment


      #3
      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()?

      Thanks,

      Gordon

      Comment


        #4
        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.

        https://ninjatrader.com/support/help...alues_that.htm

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          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?

          Regards,

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

          Comment


            #6
            Hello Gordon,

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

            Code:
            public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
            {
                // 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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by grayfrog, Today, 09:29 PM
            0 responses
            1 view
            0 likes
            Last Post grayfrog  
            Started by alcorr247, Today, 12:04 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by HiddenPhilosopher, Today, 11:08 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by HiddenPhilosopher, Today, 11:03 AM
            3 responses
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by HiddenPhilosopher, Today, 10:53 AM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X