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:	170
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.

          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 argusthome, 03-08-2026, 10:06 AM
              0 responses
              106 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              54 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              36 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              38 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              74 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X