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

Help : Draw indicator last bar viewed on chart value

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

    Help : Draw indicator last bar viewed on chart value

    Hi I try plot ATR(10) value on top right corner, But it is not the ATR(10)[0] , it is last bar render on chart. What is wrong for below code. Please help. Thanks.

    if ( CurrentBar>15)
    { Draw.TextFixed(this,"atr","(" + ( ATR(10).GetValueAt(ChartBars.ToIndex) ).ToString("N2")+")",TextPosition.TopRight);
    }

    #2
    Hello joysync,

    This code is pretty specific to non-data-driven methods. In what method is this being called?
    (Calling drawing methods in non-data driven methods is very advanced and absolutely should not be done in OnRender())

    The last bar on the chart would be ATR(10)[0] in a data driven method.

    What are you comparing?
    Are you comparing the values on a chart?
    Do you have prints from debugging that we can use to analyze the values produced?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      My code will be using in OnBarUpdate() .
      Let's say it is 10:00 am. On 1 min chart last bar is 10:00(CurrentBar). When I use mouse drag the bars to the right , the last bar(most far right bar) render on the chart is 09:50(moved right 10 bars). Now I want to show 09:50's ATR(10) on the top right corner. I am thinking use ChartBars.ToIndex to get absolute index number for most far right bar's ATR(10) value and using GetValueAt () to get 09:50's ATR(10) value.Is this possible? If not is there any way to do that? Please help. thanks.

      Joysync

      Comment


        #4
        Hello joysync,

        This is going to need advanced logic.

        I think the approach most direct is to custom render the text in OnRender() with RenderTarget.DrawText() or RenderTarget.DrawTextLayout().



        Calling a Draw method on every update of OnRender() would not be recommended.

        You could detect when the ChartBars.ToIndex changes (by saving it to a variable and comparing the variable to the current value and triggering an action when they do not match) from OnMarketData on each tick.. This would be much more efficient than checking on every pass of OnRender(), but would require a market update before the text changes.

        If it needs to be instant, possibly with custom logic you could only trigger the drawing object once (using a bool) after the ChartBars.ToIndex changes in OnRender(). But the logic would need to ensure that the Draw method is only called once after the ChartBars.ToIndex changes to avoid high CPU / GPU usage.


        But yes, ATR(10).GetValueAt(index barNumber) with the bar number should work fine.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea. I will try later.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          55 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          35 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          19 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          7 views
          0 likes
          Last Post cre8able  
          Working...
          X