Login Page - Create Account

Support Board


Date/Time: Wed, 01 Jan 2025 13:48:19 +0000



Rounding floats in point and figure code

View Count: 1431

[2016-05-18 02:27:43]
@sstfrederik - Posts: 404
The code in studies8.cpp on PointAndFigureAddBoxes does not seem to be right.

if there is a float value of say: 1.13770 which in longer format can actually be 1.1376996223 This would mean it touched the 1.13770 value, but the below code will not round the float to that value since Epsilon is not correct. floor(1.13769996223 / 0.0001 + 0.5 * 0.00001) = 11376
We would like it to be adding 0.5 to the Value / Boxsize in order to round it properly.

I think epsilon should be 50000 * GetFormatStepValue(ValueFormat);

Did I miss anything?


double PointAndFigureAddBoxes(SCStudyInterfaceRef sc, double Value, double BoxSize, int Direction, unsigned long ValueFormat)
{
  double Epsilon = 0.5 * GetFormatStepValue(ValueFormat);

  if (Direction == 1) //up
  {
    int NumberOfBoxes = (int)floor(Value / BoxSize + Epsilon);
    return (NumberOfBoxes * BoxSize);
  }
  else if (Direction == 2) //down
  {
    int NumberOfBoxes = (int)ceil(Value / BoxSize - Epsilon);
    return (NumberOfBoxes * BoxSize);
  }
  else //unknown
    return sc.Round((float)(Value / BoxSize)) * BoxSize;

  return 0;
}

[2016-05-18 10:06:27]
Sierra Chart Engineering - Posts: 104368
We are working on improving this code now. That was written a long time ago.

It really should be using the Tick Size instead. Or it could use .5.
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
[2016-05-18 10:26:38]
@sstfrederik - Posts: 404
Thanks for looking into this. Running this adjustment on a pnf chart does give unintended issues with some places where an extra X or O is placed. Later today I will look into this further myself as well.
[2016-05-19 00:11:33]
@sstfrederik - Posts: 404
It would make more sense to do the following. Basicaly adding the full TickSize is too much as it might shift price to where it never was. We need one accuracy more than TickSize and than floor or ceil that value.

double PointAndFigureAddBoxes(SCStudyInterfaceRef sc, double Value, double BoxSize, int Direction, unsigned long ValueFormat)
{
  double Epsilon = 0.5 * GetFormatStepValue(ValueFormat); // is the same as sc.TickSize / 10
  double dResult(0.0);

  if (Direction == 1) //up
  {
    int NumberOfBoxes = (int)floor((Value + Epsilon) / BoxSize);
    dResult = (NumberOfBoxes)*BoxSize;
  }
  else if (Direction == 2) //down
  {
    int NumberOfBoxes = (int)ceil((Value - Epsilon) / BoxSize);
    dResult = (NumberOfBoxes) * BoxSize;
  }
  else //unknown
  {
    dResult = sc.Round((float)(Value / BoxSize)) * BoxSize;
  }

  return dResult;

Still testing this, but it looks promising no more rounding errors in box creation which sometimes occurred with price touches.

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

Login

Login Page - Create Account