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

Prevent Plot Rounding to Two Decimal Digits

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

    Prevent Plot Rounding to Two Decimal Digits

    I have an indicator that I round to 4 decimal places. I can display the correct value with its 4 decimal digits by using DrawText, put I would rather read the correctly formatted value from the right hand scale of a subpanel.

    It seems that when the correctly formatted double is plotted, it always reads with two decimal places... so 1.4215 gets rounded to 1.42.

    Any way to override this behavior and male the right hand scale read all my relevanty decimal places?

    #2
    Hello Crassius,

    Unfortunately there's no control to change the # of decimals on the vertical axis. You can use FormatPriceMarker() to control # of decimal places for the last value.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Can this be remedied in a future release? With forex and many futures you really need to go beyond just 2 decimal places, and this limitation can really hamper you.

      Thanks!

      Comment


        #4
        Thank you for the feedback, Style. It would be good to see indicator axis match the underlying instrument so I'll be sure to add to our list for consideration in a future release.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          The problem with having no control over the decimal format of the y axis

          This screenshot shows the absurd result of the fact that the y axis of an indicator panel is limited to a precision of two decimal places, with no option of programmatic control.

          Since the scale values displayed are all the same, the scale might as well not be there at all.



          No, it would not be good for the scale to automatically match the underlying instrument, or to automatically match anything else.

          What's needed is a way for the indicator code to control the formatting of the axis, using custom strings as can be used in the FormatPriceMarker method. So that any number of decimal places, or a custom fractional string for Treasuries, can be specified.
          Attached Files
          Last edited by Ricam; 02-10-2015, 12:44 PM.

          Comment


            #6
            Hello Ricam,

            Thank you for your suggestion, I have forwarded this to our development team.

            Comment


              #7
              You can control the values displayed for your indicator by overriding FormatPriceMarker. If you add the following code in the end of your indicator class, it should display 4 digits.

              Code:
              public class ******* : Indicator
              {        
                            // your indicator code goes here       
              
                            #region Miscellaneous
              
                            public override string FormatPriceMarker(double price)
                            {
                                double trunc = Math.Truncate(price);
                                int fraction = Convert.ToInt32(Math.Abs(Math.Round(10000*(price - trunc)))); 
                                string priceMarker = "";
                                priceMarker = trunc.ToString() + "." + fraction.ToString();
                                return priceMarker;
                            }
                            #endregion
              }

              Comment


                #8
                Originally posted by Harry View Post
                You can control the values displayed for your indicator by overriding FormatPriceMarker. If you add the following code in the end of your indicator class, it should display 4 digits.

                Code:
                public class ******* : Indicator
                {
                // your indicator code goes here
                
                #region Miscellaneous
                
                public override string FormatPriceMarker(double price)
                {
                double trunc = Math.Truncate(price);
                int fraction = Convert.ToInt32(Math.Abs(Math.Round(10000*(price - trunc))));
                string priceMarker = "";
                priceMarker = trunc.ToString() + "." + fraction.ToString();
                return priceMarker;
                }
                #endregion
                }
                You are a God. Thank you!!

                Comment


                  #9
                  If you're dealing with Treasury Bonds, good reading here.

                  Comment


                    #10
                    There is a much simpler solution for displaying indicator values on the price panel in the correct format. Here is the code:

                    Code:
                    public override string FormatPriceMarker(double price)
                    {
                         return Instrument.MasterInstrument.FormatPrice(Instrument .MasterInstrument.RoundToTickSize(price));
                    }
                    In case that an indicator can be displayed on the price panel or the indicator panel, you may refine the code to:

                    Code:
                    public override string FormatPriceMarker(double price)
                    {
                         if(indicatorIsOnPricePanel)
                              return Instrument.MasterInstrument.FormatPrice(Instrument .MasterInstrument.RoundToTickSize(price));
                         else
                              return base.FormatPriceMarker(price);
                    }
                    You would need to set the boolean indicatorIsOnPricePanel in OnStateChange().
                    Last edited by Harry; 01-15-2022, 02:15 PM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jxs_xrj, 01-12-2020, 09:49 AM
                    6 responses
                    3,290 views
                    1 like
                    Last Post jgualdronc  
                    Started by Touch-Ups, Today, 10:36 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post Touch-Ups  
                    Started by geddyisodin, 04-25-2024, 05:20 AM
                    11 responses
                    62 views
                    0 likes
                    Last Post halgo_boulder  
                    Started by Option Whisperer, Today, 09:55 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post Option Whisperer  
                    Started by halgo_boulder, 04-20-2024, 08:44 AM
                    2 responses
                    25 views
                    0 likes
                    Last Post halgo_boulder  
                    Working...
                    X