Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 16:53:54 +0000



round method in spreadsheet

View Count: 2179

[2014-09-18 22:47:31]
onnb - Posts: 662
the spreadsheets have a method called ROUND(number, digits)

is this rounding up/down or to the nearest?
is there an equivalent acsil method to this one?

is sc.RoundToTickSize(x, 0.001) the same as ROUND(x, 3)?

[2014-09-18 23:35:10]
Sawtooth - Posts: 4120
the ROUND function rounds to the nearest, either up or down.

To round to tick size, use the MROUND function:
=MROUND(n,$J$21)

If J21 has floating point errors, you can eliminate them with this in H21:
=1/ROUND(1/J21,0)
then use:
=MROUND(n,$H$21)

The MROUND function rounds to the nearest multiple, either up or down.
Date Time Of Last Edit: 2014-09-19 01:21:58
[2014-09-19 02:23:50]
onnb - Posts: 662
thanks, sorry for not being clear enough

converting a spreadsheet to acsil, the sheet uses rounding to compare #'s like so:

ROUND(x, 3) > ROUND(y, 3)

I am looking for the acsil equivalent of that
I hope this is more clear
[2014-09-19 13:20:38]
Sawtooth - Posts: 4120
http://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_Functions.html#scRoundToTickSize
From the documentation:
sc.RoundToTickSize() takes a float and rounds it to the nearest increment.
This would be the same as the spreadsheet MROUND function.

http://www.sierrachart.com/index.php?page=doc/doc_ACSIL_Members_Functions.html#scRound
From the documentation:
sc.Round() takes a float and rounds it to the nearest int.
This is different than the spreadsheet ROUND function. It appears there is no directly equal ACSIL member function.
Date Time Of Last Edit: 2014-09-19 13:22:58
[2014-09-19 18:31:27]
Sierra Chart Engineering - Posts: 104368
We will add the ACSIL equivalent.
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
[2014-09-19 19:15:29]
Sierra Chart Engineering - Posts: 104368
In the next release this function will be added:

double sc.RoundToIncrement(double Value, float TickSize)

However, it is equivalent to: sc.RoundToTickSize

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
[2014-09-20 01:36:45]
onnb - Posts: 662
from previous response

MROUND(E3, J$21) == sc.RoundToTickSize(sc.BaseData[SC_LAST][sc.Index], sc.TickSize)

I am seeing that for some values, this is not the case.

e.g., for 1.296649933

mround = 1.2966
roundtoticksize = 1.2967

Just want to confirm that this is expected.
[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

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account