Login Page - Create Account

Support Board


Date/Time: Tue, 14 May 2024 10:44:42 +0000



Rounding issues with sc.FormattedEvaluate

View Count: 787

[2017-02-19 20:17:32]
@sstfrederik - Posts: 403
I have some unexpected rounding issues while using sc.FormattedEvaluate.


int Match = sc.FormattedEvaluate(StudyArray[sc.Index], sc.BaseGraphValueFormat, EQUAL_OPERATOR, StudyArray[sc.Index-1], sc.BaseGraphValueFormat) ? 1 : 0;

I am comparing current index float values from a SubGraph Array with values of the same Array one index back. sc.BaseGraphValueFormat in my ChartSettings is 0.01. When I check the output of the above code there are matches when it should not match and vice versa.

Some example output:

//did match but shouldn't
StudyArray = 2343.473633, PastStudyArray = 2343.475342, Match = 1 | 2017-02-19 14:50:55 *

//should match but didn't
StudyArray = 2342.526855, PastStudyArray = 2342.534180, Match = 0 | 2017-02-19 14:45:43 *
StudyArray = 2343.485840, PastStudyArray = 2343.492188, Match = 0 | 2017-02-19 14:56:30 *

//these should all match, only the first does
StudyArray = 2343.488525, PastStudyArray = 2343.492188, Match = 1 | 2017-02-19 14:57:14 *
StudyArray = 2343.486328, PastStudyArray = 2343.492188, Match = 0 | 2017-02-19 14:57:14 *
StudyArray = 2343.485596, PastStudyArray = 2343.492188, Match = 0 | 2017-02-19 14:57:14 *
[2017-02-20 03:38:12]
Sierra Chart Engineering - Posts: 104368
The way that this works is if the two values are within each other half of 0.01 which is .005, then they are considered equal.

We will make sure the documentation makes this clear.

If you want to accomplish what you want you would have to round the values first to the nearest .01 with sc.RoundToIncrement.
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