Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Visible Chart Price

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

    Visible Chart Price

    Hi guys,

    Is there a way I can call the lowest and highest price that's visible on my chart? To be clear it's the current high and low of prices that's visible in the panel.

    Thanks!

    #2
    Hello Bluebeep,

    For the visible bars only, likely the best way to accomplish this would be to use similar code to what OnRender or OnCalculateMinMax uses.




    The loop over the visible range of bars would essentially be the same in both cases, this could also be used from other areas like OnBarUpdate if necessary. The fundamental is the loop over the range of visible bars by using ChartBars.FromIndex and ChartBars.ToIndex.

    I look forward to being of further assistance.

    Comment


      #3
      Thank you!

      Comment


        #4
        Sorry.... I'm trying to get this to work as well... I'm struggling with the Loop coding.. if anyone has any code they could paste in or another indicator example they can think of the cycle thru the bars that would be great.

        Comment


          #5
          Hello MattD888,

          Thank you for your post.

          From OnCalculateMinMax():

          Code:
          // For performance optimization, only loop through what is viewable on the chart
          for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
          {
          // since using Close[0] is not guaranteed to be in sync
          // retrieve "Close" value at the current viewable range index
          double plotValue = Close.GetValueAt(index);
          
          // return min/max of close value
          tmpMin = Math.Min(tmpMin, plotValue);
          tmpMax = Math.Max(tmpMax, plotValue);
          }
          OnCalculateMinMax() and OnRender() both have code on their Help Guide pages demonstrating looping through the visible bars on the chart.

          It looks like the links from Jesse's initial post are broken so I'll repost them here.​

          https://ninjatrader.com/support/helpGuides/nt8/oncalculateminmax.htm​



          Please let us know if you have any further questions.

          Comment


            #6
            Does anyone have any ideas why I can't get the Low value using the same code proposed above. I have changed the variable names a bit but the code logic is copied from the original post above. The tmp.Min value always prints as 0. Not sure why.... my only guess is somehow that is the lowest value picked up in the looping logic, so naturally the Min value will be 0.

            The Code I have been trying to use to pickup the Low and High...

            Actually I see there is one significant change in the original code... instead of the Close value, I am trying to get High and Low...

            I assumed since the High value worked when replacing the Close value, so would the Low



            My Code Changes...

            // For performance optimization, only loop through what is viewable on the chart
            for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
            {
            // since using Close[0] is not guaranteed to be in sync
            // retrieve "Close" value at the current viewable range index
            double plotValueHigh = High.GetValueAt(index);
            //double plotValueLow = Low.GetValueAt(index);

            // return min/max of close value
            //tmpMin = Math.Min(tmpMin, plotValueLow);
            tmpMax = Math.Max(tmpMax, plotValueHigh);
            }​​

            Comment


              #7
              Hello MattD888,

              You have the code commented out, you need to uncomment the code so it can be used.

              Code:
              for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
              {
                  double plotValueHigh = High.GetValueAt(index);
                  double plotValueLow = Low.GetValueAt(index);
              
                  tmpMin = Math.Min(tmpMin, plotValueLow);
                  tmpMax = Math.Max(tmpMax, plotValueHigh);
              }​​
              Outside of making that change you would have to use a print to make sure tmpMin starts at a higher value, generally that would start a Double.MaxValue so the next lower price is stored to the variable each time the loop iterates. ​

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              627 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              359 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              562 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              567 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X