Login Page - Create Account

Support Board


Date/Time: Sat, 04 Jan 2025 08:00:13 +0000



Post From: Rounding floats in point and figure code

[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.