Announcement

Collapse
No announcement yet.

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

    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 zacharydw00, Today, 05:14 PM
              0 responses
              5 views
              0 likes
              Last Post zacharydw00  
              Started by shahabjet1, Today, 04:47 PM
              0 responses
              11 views
              0 likes
              Last Post shahabjet1  
              Started by aligator, Today, 04:32 PM
              0 responses
              10 views
              0 likes
              Last Post aligator  
              Started by timko, Today, 04:02 PM
              0 responses
              9 views
              0 likes
              Last Post timko
              by timko
               
              Started by asmmbillah, Today, 03:37 PM
              2 responses
              18 views
              0 likes
              Last Post asmmbillah  
              Working...
              X