Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get decimals (digits) of symbol easily

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

    Get decimals (digits) of symbol easily

    At this moment, afaik, there is no builtin method/property that will get (in NinjaScript) current symbols's digits amount after dot
    Would be nice if there was any (like it's in MetaTrader) so, i.e.

    on ES (i.e. which has price like: 2915.75 ) gave the amount of digits after dot

    Digits --->2

    on EURUSD (price like 1.23456 )

    Digits ---> 5

    so, that's simple.

    #2
    Hello TazoTodua,

    You are correct, there would be anything NinjaScript specific for that purpose. You can find many ways to do this in terms of general C# by searching online for "C# count decimal places". Here is a stack overflow post with many examples: https://stackoverflow.com/questions/...ess-of-culture


    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jess, yes, but we are talking about how to handle that simply with NinjaTrader. So, would be nice a feature to be a inherited method, like `Digits()`, or the property named `Digits`.
      i think it would be easy to add that method in NinjaScriptBase, it's so easy for NT devs to implement that.

      Comment


        #4
        Originally posted by TazoTodua View Post
        At this moment, afaik, there is no builtin method/property that will get (in NinjaScript) current symbols's digits amount after dot
        Would be nice if there was any (like it's in MetaTrader) so, i.e.

        on ES (i.e. which has price like: 2915.75 ) gave the amount of digits after dot

        Digits --->2

        on EURUSD (price like 1.23456 )

        Digits ---> 5

        so, that's simple.
        TickSize? If you know the TickSize, getting the number of digits after the decimal point is trivial c#. Just write your own method.

        Comment


          #5
          Originally posted by TazoTodua View Post
          At this moment, afaik, there is no builtin method/property that will get (in NinjaScript) current symbols's digits amount after dot
          Would be nice if there was any (like it's in MetaTrader) so, i.e.

          on ES (i.e. which has price like: 2915.75 ) gave the amount of digits after dot

          Digits --->2

          on EURUSD (price like 1.23456 )

          Digits ---> 5

          so, that's simple.
          Actually, many years ago, I needed something similar. I went searching for it in my methods library. Enjoy!
          Code:
                  /// <summary>
                  /// Return the number of decimal places in the argument.
                  /// </summary>
                  /// <param name="dblNumber">Value to process.</param>
                  /// <returns>Number of decimal places in dblNumber.</returns>
                  protected int GetNumberDecimalPlaces(double dblNumber)
                  {
                      string[] parts = dblNumber.ToString().Split(new Char[] { '.', ',' });
                      return parts[0] != dblNumber.ToString() ? parts[1].Length : 0;
                  }
          Of course, you can make it public access, and/or static.

          It is not very robust, and requires a well behaved input. As I almost only needed it for exactly the purpose of using it against TickSize, my data was guaranteed well-behaved. For robustness, you might want to throw an exception if the input has more than one period or comma, or is otherwise malformed (eg., contains a space, etc). Basically throw an exception if the input is not a double. Try typeof().
          Last edited by koganam; 08-28-2019, 01:11 PM.

          Comment


            #6
            thanks Koganam

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            7 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            4 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            12 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            13 views
            0 likes
            Last Post bltdavid  
            Working...
            X