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 traderqz, Today, 12:06 AM
            10 responses
            18 views
            0 likes
            Last Post traderqz  
            Started by algospoke, 04-17-2024, 06:40 PM
            5 responses
            46 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by arvidvanstaey, Today, 02:19 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by mmckinnm, Today, 01:34 PM
            3 responses
            5 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by f.saeidi, Today, 01:32 PM
            2 responses
            8 views
            0 likes
            Last Post f.saeidi  
            Working...
            X