Login Page - Create Account

Support Board


Date/Time: Sun, 05 May 2024 14:25:35 +0000



Post From: round method in spreadsheet

[2014-09-22 04:04:58]
Sierra Chart Engineering - Posts: 104368
Yes because sc.RoundToTickSize has a more practical implementation that makes adjustments for floating-point error:

double RoundToTickSize(double Value, double TickSize)
  {
    if (TickSize == 0)
      return Value; // cannot round
    
    double ClosestMult = (int)(Value / TickSize) * TickSize;
    double Diff = Value - ClosestMult;
    
    double DifferenceFromIncrement = TickSize*0.5 - Diff;
    
    double Result;
    if (Value > 0.0 && DifferenceFromIncrement <= TickSize * 0.001)
      Result = ClosestMult + TickSize;
    else if (Value < 0.0 && DifferenceFromIncrement <= TickSize * 0.001)
      Result = ClosestMult - TickSize;
    else
      Result = ClosestMult;
    
    return Result;
  }

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing