Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

comparing decimal value

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

    comparing decimal value

    the tick size for eur.usd is set to 5 digits. how can i make sure that any comparision that has >= or <= does not use the 5th decimal ?

    #2
    Hello junkone,
    You can use as below:
    Code:
    ticksize1 = Math.Truncate(ticksize * 10000) / 10000;
    Now you get ticksize upto 4 digits only so you can work on your calcs.
    Hope it helps!

    Comment


      #3
      HOW can i applly to compare the indicator values that have 5 decimal points? Click image for larger version

Name:	4FVxXnA.png
Views:	117
Size:	56.4 KB
ID:	1127704

      Comment


        #4
        Hello,
        Can you give your comparison for indicator values you need so I can give you an example relevant to your requirement.

        Comment


          #5
          Hello junkone, thanks for writing in.

          The Truncate method will remove the decimal portion of the number. You would need to use Math.Round to ensure the values you get are always 5 decimal places long. See this publicly available link :
          Rounds a value to the nearest integer or to the specified number of fractional digits.


          Try Printing the values you get from rounding the Price and EMA values to see how the comparison will be evaluated.

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by s.kinra View Post
            Hello,
            Can you give your comparison for indicator values you need so I can give you an example relevant to your requirement.
            in the example below, i find many instances when it did not trigger true because of the 5th decimal point.

            if (IsFirstTickOfBar)
            {
            if ((CountIf(() => EMA(Close, 9)[1] > EMA(Close, 20)[1], 20) >= 20) && (CountIf(() => EMA(Close, 20)[1] > SMA(Close, 50)[1], 20) >= 20))
            {


            }

            Comment


              #7
              Hello,
              Try this:
              Code:
              if (IsFirstTickOfBar)
              {
              if ((CountIf(() => ( Math.Truncate(EMA(Close, 9)[1] * 10000) / 10000 ) > ( Math.Truncate(EMA(Close, 20)[1]* 10000) / 10000 ), 20) >= 20) && (CountIf(() => ( Math.Truncate(EMA(Close, 20)[1]* 10000) / 10000 ) > ( Math.Truncate(SMA(Close, 50)[1]* 10000) / 10000 ), 20) >= 20))
              {
              
              
              }
              You can also store the truncated values to double series & do your calculation on them (alternate method to keep calculation simple).

              You should Print the values of EMA, SMA etc. to confirm if its truncated to 4 digits & be sure your condition is evaluated as expected. Test this & see if you get the desired results. This will eliminate the 5th or higher decimal place from calculation, so take informed call if you need Truncate or Round.
              Last edited by s.kinra; 11-16-2020, 09:56 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by techgetgame, Today, 11:42 PM
              0 responses
              5 views
              0 likes
              Last Post techgetgame  
              Started by sephichapdson, Today, 11:36 PM
              0 responses
              1 view
              0 likes
              Last Post sephichapdson  
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,612 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              9 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              19 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Working...
              X