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

Decimal Rounding in Forex

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

    Decimal Rounding in Forex

    Hi,
    I have coded a very simple calculation, which is working fine for Forex pairs with only 2 decimal figures like USD/JPY, but for the ones that have 4 decimals like the EUR/USD, the final result is being rounded to 2 decimals only instead of 4.

    if (Open[2]<=Close[2] && Open[1]<=Close[1])
    Tak.Set(Low[0] -2* (Brange[2] + Brange[1] + Brange[0])); ---- This is the line where the result is being rounded to 2 decimals all the time.

    Brange is a previous parameter that looks like this;

    if (Close[0]>Open[0])
    Brange.Set(Close[0] - Open[0]);
    else
    Brange.Set(Open[0] - Close[0]);

    Will appreciate any help regarding this.

    Thanks.

    #2
    Hello BuhoTrader1,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Is the value consistently 2 decimal places? Or only when receiving a value that ends in two zeros such as 1.2200?

    I look forward to assisting you further.

    Comment


      #3
      The value consistently gives 2 decimal places only. If the value is supposed to be lets say. 1.5789, it shows 1.58, and rounds it up. I noticed that when there is TWO zeros at the end it doesn't show, but this value always gets rounded.

      Comment


        #4
        Hello BuhoTrader1,

        Thank you for your response.

        Can you provide an example that I may test on my end? Such as a 'toy' version of the script?
        'Toy' being simply the calculation logic that is needed to test this item and not the entirety of the script.

        If so, please attach to your response so I may investigate this matter further.

        I look forward to assisting you further.

        Comment


          #5
          Let me know if this is not enough coding to work with. I really appreciate you taking the time to look into this.

          if (Close[0]>Open[0])
          Brange.Set(Close[0] - Open[0]);
          else
          Brange.Set(Open[0] - Close[0]);

          if (Open[2]<Close[2] && Open[1]<Close[1])
          Kat.Set(High[0] + 3*(Brange[2] + Brange[1] + Brange[0])); /// This is the line that seems to not work well for forex pair with 4 decimal, since it always rounds up the result to 2 decimal.

          The Brange calculation works fine by the way. In that simple subtraction it does give the result with the 4 decimal figures. but It looks once I multiply by 3 it gets rounded to 2 decials.
          Last edited by BuhoTrader1; 10-08-2012, 03:16 PM.

          Comment


            #6
            I bumped into this other post, and it recommended writing the following line.

            public override string FormatPriceMarker(double price)
            {
            // Formats price values to 4 decimal places
            return price.ToString("N4");
            }
            And that did the trick to get the 4 decimals. But now it also adds 2 annoying Zeros to the currency pairs that only have 2 decimals. So, lets say the EURJPY instead of showing 78.57, it goes with 78.5700...I am wondering if I need to make 2 copies of this indicator, one with the line above for the use of 4 decimals and one without it.

            Hope there is a way to have the indicator work both ways.

            Thanks again for all the help Patrick.

            Comment


              #7
              Hello BuhoTrader1,
              Thanks for the code and I am replying for Patrick

              Unfortunately I cannot replicate the scenario and I use the code I am getting the correct values.

              If you round the ticksize values then are you getting the correct values.


              Also can you tell me what is the regional settings of your PC.


              If you want to override the FormatPriceMarker then to find the exact length of the decimal please refer to this post
              Attached Files
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                But I dont want to round the values. I want to see the 4 decimals.

                Comment


                  #9
                  Hello BuhoTrader1,

                  Thank you for your response.

                  Have you tried the example provided by Joydeep for the decimal places at the following link?



                  Please let me know if you are able to implement this into your code.

                  Comment


                    #10
                    thanks Patrick for all your help. I'll check that out. I think that will do it.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Barry Milan, Yesterday, 10:35 PM
                    5 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by DanielSanMartin, Yesterday, 02:37 PM
                    2 responses
                    13 views
                    0 likes
                    Last Post DanielSanMartin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    4 responses
                    12 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by terofs, Today, 04:18 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by nandhumca, Today, 03:41 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post nandhumca  
                    Working...
                    X