Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

math round problme

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

    math round problme

    hello, sry for this noob qustion, but i cant get it to work.

    Code:
    count0 = GetCurrentBid();
    count0 = Math.Round(count0,5);
    countTTL = (count0 - count1);
    count1=count0;
    when im printing the "countTTL" im geting this:
    countTTL = 0
    countTTL = 9.99999999995449E-06
    countTTL = 0
    countTTL = 0
    countTTL = 9.99999999995449E-06
    countTTL = 0
    countTTL = 9.99999999995449E-06
    countTTL = 9.99999999995449E-06
    and so forth...

    why im geting so bid number, when the count0 is round to 0.00001 max, how that can be?

    #2
    Hello,

    It looks like by the output you are getting a number with a very large decimal value causing the E-06, its hard to say without the variable definitions on the types being used here to provide a better answer.

    for Print specifically you could use this as Print instead to display very large numbers:

    double someValue = 0.0000000000001;
    Print(someValue); // displays 1E-13
    Print(someValue.ToString("##.#############")); // displays .0000000000001

    Regarding why the round is not trimming the amount, what types are being used for these variables? This could be a cast issue but I would need to see the actual variable definitions etc.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      tnx for the fast answer, im useing double for all ver.
      i know that E-06 is for big number, but if i useing (math.round , 5) why the number is still so big?

      Comment


        #4
        Hello,

        That would depend on what values are being passed, what is the value of count1?

        Is the following assumption of your actual syntax correct?
        double count1 = ?
        double count0 = GetCurrentBid();
        count0 = Math.Round(count0,5);
        double countTTL = (count0 - count1);
        count1=count0;



        I could likely provide a better answer if I could test the code you provided with the values you are using, mainly I would need to have a value for .count1 as that is unknown.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          double count1 = 0;
          double count0 = GetCurrentBid();
          count0 = Math.Round(count0,5);
          double countTTL = (count0 - count1);
          count1=count0;

          u can see that count1 is = count0,

          what im trying to do is geting the last chang of the BID

          Comment


            #6
            Originally posted by tomas1983 View Post
            double count1 = 0;
            double count0 = GetCurrentBid();
            count0 = Math.Round(count0,5);
            double countTTL = (count0 - count1);
            count1=count0;

            u can see that count1 is = count0,

            what im trying to do is geting the last chang of the BID
            So then what you are seeing is the same reason we caution against comparing doubles with the == operator. Computers almost always store floating point numbers inexactly. In your code if it appears that the CurrentBid() has not changed, then you should have count0 - count1 be zero. Instead floating point storage issues would return a very small number, close to zero.

            How you would tackle it depends on the larger issue of what you want to code to do, beyond what is in effect a comparison of 2 doubles for equality.

            Comment


              #7
              very bizar...

              so how can i chack what is the last bid change?

              Comment


                #8
                Originally posted by tomas1983 View Post
                very bizar...

                so how can i chack what is the last bid change?
                You would do it as you are doing it. However, because the quantities are doubles and the difference could in practical trading terms be zero, you have to take care of floating point storage issues around such small numbers, that are close to zero.

                There are shorthand syntax available to do so, but the openest way to show what you want to do would be to determine a tolerance, below which a value should be zero. This would be generally, the largest value that you would choose to consider as "no difference". In your case, it would most likely be one decimal place or so beyond your smallest tick size, but it is still really up to you to decide.

                As I do not know your larger purpose, here is one arbitrary example:
                Code:
                double tolerance = 0.00000001; //anything less than this, I shall assign to be zero
                countTTL = (count1 - count0) < tolerance ? 0 : (count1 - count0);
                As I said, there are more elegant, shorthand, ways to write the same thing. Read the literature on how to compare doubles: that should be enlightening.
                Last edited by koganam; 12-23-2015, 07:56 AM.

                Comment


                  #9
                  Ok, il check it!
                  Is it a ninjatrader problem? Or a c#/pc problem?

                  I have another question please :
                  I like to export one of my ver from custom indicator to another custom indicator, and plot it on the chart, the reason i want to do so, is because i like to ploting on one window multy custom indicators.
                  Tnx

                  Comment


                    #10
                    Originally posted by tomas1983 View Post
                    Ok, il check it!
                    Is it a ninjatrader problem? Or a c#/pc problem?
                    Computer floating-point storage issues have nothing to do with NinjaTrader. Math is math. The issue is a problem with all programming languages that have to handle floating-point arithmetic.

                    I have another question please :
                    I like to export one of my ver from custom indicator to another custom indicator, and plot it on the chart, the reason i want to do so, is because i like to ploting on one window multy custom indicators.
                    Tnx
                    I am not sure what you are asking/saying here. If you want to show multiple indicators on a chart, just do so. Load all the indicators onto the same chart. I do not see how exports come into the matter.

                    Comment


                      #11
                      hi,
                      i have 2 custom indicator that calculate some value,
                      i like that 2 value from the 2 indicators will be ploting on 1 "plot windows"

                      Comment


                        #12
                        Originally posted by tomas1983 View Post
                        hi,
                        i have 2 custom indicator that calculate some value,
                        i like that 2 value from the 2 indicators will be ploting on 1 "plot windows"
                        So put both indicators on the same chart. You can put any number of indicators on the chart, within the resources available on the computer, of course.

                        Comment


                          #13
                          Tnx for the reply, i know that I can put multi indicators on one chart, but that is not what i want.
                          I like to display my 2 custom indicators on one "down indicator Windows" not on the big chart where the bars are display. Hoop that is more clear now

                          Comment


                            #14
                            Originally posted by tomas1983 View Post
                            Tnx for the reply, i know that I can put multi indicators on one chart, but that is not what i want.
                            I like to display my 2 custom indicators on one "down indicator Windows" not on the big chart where the bars are display. Hoop that is more clear now
                            So put them on the same chart panel. It is still called the chart, which is why I said: "Put them on the chart."

                            Comment


                              #15
                              hoooo, sry im so ninjatrader noob...

                              i have 2 more quistion and then i will leave u alone...

                              1) im trying to count the time that pass, the only count i found that not reset ever new bar is: DateTime.Now.Ticks
                              is there smaller time count then ticks that not reset evry new bar? something like "Millisecond"

                              2) i wanna comment on the chart, but the "ITextFixed" can only drawing in specific place, and canot be move...

                              how can i draw text in custom place?

                              tnx
                              tom

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Stanfillirenfro, Today, 07:23 AM
                              9 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by George21, Today, 10:07 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post George21  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by navyguy06, Today, 09:28 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              8 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X