Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

simple arithmetic

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

    simple arithmetic

    OK, I wanted to check an entry to exit, so saved the Close[0] at the input trigger, and at exit, printed this RG = exit - entry - comm:
    Test RG: Entry Price = 98.61, Exit Price = 98.87, Comm = 0.1, RG = -0.360000000000005

    I admit being surprised at the difficulty in arithmetic accuracy.

    Given the inputs, why is the output off? The result should have the same number of significant digits as the inputs.

    Also, is there a way to round this inaccurate result back to the correct # decimal places to match the underlying instrument?

    #2
    LostTrader, for floating point arithmetic considerations you would want to check into this tip here:



    For tick size related rounding, please see this method:

    Comment


      #3
      Thank you, Bertrand. Somehow I did not expect that to happen with addition.

      What if, in this case, I don't actually want to round to tick size? I really want to use the ToString("+#.00;-#.00;zero") formatting to reduce the output to the correct number of digits. How can this be programmatically set?

      Comment


        #4
        LostTrader, would the tip shared on this blog help you out?

        Comment


          #5
          Rounding a number to Price (not Tick)

          No, Bertrand, it doesn't.

          I want to format (e.g. when printing) a calculation result to the exact same number of significant digits as the PRICE of the current instrument, which as you know varies.
          I do NOT want to round to the TickSize.

          So how can I programmatically detect the number of sig digits on Price?

          Comment


            #6
            Lost Trader,

            Off the top of my head I would say something like:

            Code:
             
            int dec; 
            string str = Close[0].ToString();
            dec = (str.Length - [COLOR=purple]1[/COLOR]) - str.IndexOf([COLOR=#a31515]"."[/COLOR]);
            Would that do what you want?

            VT

            Comment


              #7
              Originally posted by Lost Trader View Post
              No, Bertrand, it doesn't.

              I want to format (e.g. when printing) a calculation result to the exact same number of significant digits as the PRICE of the current instrument, which as you know varies.
              I do NOT want to round to the TickSize.

              So how can I programmatically detect the number of sig digits on Price?
              So only Round2TickSize for the Print() statement itself, without rounding the actual quantity in the code proper.

              Otherwise, just use custom or standard string formatting per C#.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              580 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              336 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X