Announcement

Collapse

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

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.



        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, [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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cre8able, Today, 03:20 PM
            0 responses
            5 views
            0 likes
            Last Post cre8able  
            Started by Fran888, 02-16-2024, 10:48 AM
            3 responses
            47 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Started by martin70, 03-24-2023, 04:58 AM
            15 responses
            114 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by The_Sec, Today, 02:29 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by jeronymite, 04-12-2024, 04:26 PM
            2 responses
            31 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X