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

getting max & min price of chart in OnRender

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

    getting max & min price of chart in OnRender

    I need a simple code that I can get max and min price of chart at each moment
    I have tried this but min price is showing as negative number,
    Code:
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                double maxPrice=ChartPanel.MaxValue;
                double minPrice=ChartPanel.MinValue;//chartScale.MinValue;
                Draw.TextFixed(this, "Test", minPrice.ToString()+", "+maxPrice.ToString(), TextPosition.TopLeft);
            }
    ​
    I also tried chartScale.MinValue but it is not getting what I need
    this should be quite simple, not sure what is wrong!
    ChartPanel.MaxValue shows correct number but ChartPanel.MinValue returns -0.015!

    Click image for larger version

Name:	image.png
Views:	33
Size:	2.2 KB
ID:	1296337

    #2
    Hello tidicofx,

    Thank you for your post.

    ChartPanel.MinValue indicates the minimum Y value of objects within the chart panel, based on the current y-axis scale. The scale of the y-axis is dependent upon the values of objects in the panel which have Auto Scale enabled.​



    So any objects on the chart which have auto scale enabled can be included.

    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.





    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

    Both Help Guide pages above show a code sample looping through the bars.

    Please let us know if you have any further questions. ​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hello
      thank you for your reply
      actually my goal is to achieve highest/lowest visible price on chart, I dont look for bars highest/lowest price or objects lowest/highest price, normally I expect this to be achievable easily
      based on your comments ChartPanel.MaxValue/MinValue is not what I am looking for even that they dont work correctly as you explained, I have no object on chart so why MinValue is a negative number, anyway I dont need them because they seems to have different usage
      there is also chartScale.MinValue, chartScale.MaxValue, they are also returning different numbers that I dont understand
      I attach a full screenshot of chart for both values ChartPanel, chartScale
      Click image for larger version

Name:	image.png
Views:	28
Size:	39.4 KB
ID:	1296468​left side is ChartPanel.MaxValue, MinValue
      right side is chartScale.MaxValue, MinValue

      Comment


        #4
        to explain more, for x scale that is time, i can easily get first (left) and last (right) visible time using code like this : DateTime dtEnd=chartControl.GetTimeByX(chartWidth);
        i think there should be similar function that give me values on Y scale

        Comment


          #5
          Hello tidicofx,

          You can loop through the ChartBars.FromIndex and ChartBars.ToIndex and find the lowest and highest visible price on the chart. Save the high price and low price to a variable that you can compare the .GetHigh() and .GetLow() of each bar to. For example,

          Code:
          double highPrice = 0;
          double lowPrice = 0;;
          
          for(int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
          { 
          if(Bars.GetHigh(barIndex) > highPrice)
          highPrice = Bars.GetHigh(barIndex);
          
          if(Bars.GetLow(barIndex) < lowPrice)
          lowPrice = Bars.GetLow(barIndex);
          
          }​
          Please let me know if this does not lead you in the right direction.
          Gaby V.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Gaby View Post
            Hello tidicofx,

            You can loop through the ChartBars.FromIndex and ChartBars.ToIndex and find the lowest and highest visible price on the chart. Save the high price and low price to a variable that you can compare the .GetHigh() and .GetLow() of each bar to. For example,

            Code:
            double highPrice = 0;
            double lowPrice = 0;;
            
            for(int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
            {
            if(Bars.GetHigh(barIndex) > highPrice)
            highPrice = Bars.GetHigh(barIndex);
            
            if(Bars.GetLow(barIndex) < lowPrice)
            lowPrice = Bars.GetLow(barIndex);
            
            }​
            Please let me know if this does not lead you in the right direction.
            Hello, thank you for your reply
            I think I clearly said I don't look for highest/lowest of candles visible on chart
            and if you look at screenshot I have sent, it clearly shows how much difference is between chart max/min price and candles highest/lowest prices
            thanks

            Comment


              #7
              Hello tidicofx,

              Your previous reply stated:

              my goal is to achieve highest/lowest visible price on chart
              Which is what the code snippet I shared will achieve. It will loop through all the visible bars on the chart, and save the highPrice and lowPrice to a variable. This variable is compared to the high and low price of every single bar, if the current bar being compared has a lower or higher price, it will be saved to the highPrice or lowPrice variable. After looping through all the visible bars on the chart, highPrice will have saved the highest price visible on the chart and lowPrice will have saved the lowest price visible on the chart.

              If this isn't what you are looking for, could you please explain with more detail what values on the chart you are actually looking for?
              Gaby V.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Gaby View Post
                Hello tidicofx,

                Your previous reply stated:



                Which is what the code snippet I shared will achieve. It will loop through all the visible bars on the chart, and save the highPrice and lowPrice to a variable. This variable is compared to the high and low price of every single bar, if the current bar being compared has a lower or higher price, it will be saved to the highPrice or lowPrice variable. After looping through all the visible bars on the chart, highPrice will have saved the highest price visible on the chart and lowPrice will have saved the lowest price visible on the chart.

                If this isn't what you are looking for, could you please explain with more detail what values on the chart you are actually looking for?
                I think you should read my post completely, you quote a part of it and ignore following hints

                Click image for larger version  Name:	image.png Views:	0 Size:	6.1 KB ID:	1296492

                I clearly stated​, I dont look for bars highest/lowest price or objects lowest/highest price
                I am talking about chart highest/lowest price not candles highest/lowest

                Comment


                  #9
                  image below shows chart price is from18430 to 18100, but visible candles highest/lowest is 18380 to 18150 (not accurately but estimated)
                  Click image for larger version

Name:	image.png
Views:	28
Size:	39.4 KB
ID:	1296494​i am looking for 18430, 18100 numbers

                  Comment


                    #10
                    Hello tidicofx,

                    Thank you for your clarification!

                    I understand now that you are looking for the highest and lowest values displayed in the chart scale.

                    To get this, you can use ChartScale.MinValue and ChartScale.MaxValue. However, these will return the absolute rendered MinValue and MaxValue on the chart scale - including pixels above or below the text.

                    The Help Guide pages below demonstrate with pictures:





                    You could round the numbers using C# methods like Math.Round or Math.Floor.

                    Rounds a value to the nearest integer or to the specified number of fractional digits.


                    Returns the largest integral value less than or equal to the specified number.


                    Please let me know if I can assist further.
                    Gaby V.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Gaby View Post
                      Hello tidicofx,

                      Thank you for your clarification!

                      I understand now that you are looking for the highest and lowest values displayed in the chart scale.

                      To get this, you can use ChartScale.MinValue and ChartScale.MaxValue. However, these will return the absolute rendered MinValue and MaxValue on the chart scale - including pixels above or below the text.

                      The Help Guide pages below demonstrate with pictures:





                      You could round the numbers using C# methods like Math.Round or Math.Floor.

                      Rounds a value to the nearest integer or to the specified number of fractional digits.


                      Returns the largest integral value less than or equal to the specified number.


                      Please let me know if I can assist further.
                      Thank you for follow up
                      as I stated earlier, I also tried chartScale.MinValue, MaxValue
                      and as you can see on screenshot those values are printed on chart top right
                      I am getting -0.015, 0.265
                      and this is code I have tried

                      Code:
                              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                              {
                      ​                Draw.TextFixed(this, "Test2", barsToCount.ToString()+", "+chartScale.MinValue.ToString()+", "+chartScale.MaxValue.ToString(), TextPosition.TopRight);
                              }
                      
                      ​
                      what I am doing wrong?
                      my indicator has IsOverLay property set to true

                      Comment


                        #12
                        Hello,

                        Please see the attached sample script which demonstrates. This will display the minValue and maxValue of the chart scale on the chart.

                        If you have any further questions, please let me know.
                        Attached Files
                        Gaby V.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Gaby View Post
                          Hello,

                          Please see the attached sample script which demonstrates. This will display the minValue and maxValue of the chart scale on the chart.

                          If you have any further questions, please let me know.
                          thank you for your time
                          I deleted old indicator, created new one and used same code I have tried before and it works, not sure what going wrong with old file
                          thank you

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Option Whisperer, Today, 09:55 AM
                          1 response
                          11 views
                          0 likes
                          Last Post bltdavid  
                          Started by port119, Today, 02:43 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post port119
                          by port119
                           
                          Started by Philippe56140, Today, 02:35 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post Philippe56140  
                          Started by 00nevest, Today, 02:27 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post 00nevest  
                          Started by Jonafare, 12-06-2012, 03:48 PM
                          5 responses
                          3,986 views
                          0 likes
                          Last Post rene69851  
                          Working...
                          X