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

Programmatic way to get number of bars and max and min prices shown in chart

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

    Programmatic way to get number of bars and max and min prices shown in chart

    I would like a custom strategy to be able to determine programmatically the maximum and minimum prices being shown on a chart.

    The number of bars shown on the chart is not in the strategy's control, but I'd like the strategy to be able to determine the maximum and minimum prices for however many bars are shown. I don't care about the maximum or minimum prices of any bars off the left or right edges of the chart. I only care about the bars actually visible. Obviously, this maximum or minimum would change if the chart is scrolled left or right.

    Does that make sense?

    Any suggestions as to how this can be done?

    Thanks.
    Last edited by AnotherTrader; 07-28-2020, 11:40 AM.

    #2
    Hello AnotherTrader,

    Thanks for your post.

    To only work with the bars on the chart, you would need to use OnRender() and loop through the bars.
    To loop you could access ChartBars.FromIndex and ChartBars.ToIndex, references:



    OnRender(): https://ninjatrader.com/support/help.../?onrender.htm

    To get the high of bar use: https://ninjatrader.com/support/help...8/?gethigh.htm
    To get the low of a bar use: https://ninjatrader.com/support/help...t8/?getlow.htm
    These both show a looping example
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Can I use say Draw.Line() in the usual way within OnRender()?
      Last edited by AnotherTrader; 07-29-2020, 09:15 AM.

      Comment


        #4
        Hmmm ... I think I am sorting this out .... looking at SharpDX documentation.

        Comment


          #5
          Hello AnotherTrader,

          Thanks for your reply.

          Technically yes, but definitely not recommended because of the unnecessary overhead and would be against what we recommend as best practices which in this case would be to use SharpDX for drawing.

          To draw in OnRender(), take a look at the example "Sample custom render" which is well documented in code.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            I am getting the index of the last bar using ChartBars.ToIndex.

            However, if I use my mouse to scroll father right (i.e. into the future), ChartBars.ToIndex doesn't seem to change. I need this to re-render my images correctly.

            How do I get the chart index of the new right-edge of the chart as I scroll further right?
            Last edited by AnotherTrader; 08-02-2020, 11:43 AM.

            Comment


              #7
              Hello AnotherTrader,

              Thanks for your reply.

              Are you trying to extend your line into the future and are looking for a coordinate? (ChatPanel.X + ChartPanel.W?)

              To answer your question you could use: int painted = chartControl.LastSlotPainted; Reference: https://ninjatrader.com/support/help...lotpainted.htm
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,266 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X