persistable srecord noeq PriceDigitizer2(PriceCells cells) { settable int cellNumber = Int.MIN_VALUE; settable int lastCellNumber = Int.MIN_VALUE; settable bool verbose; settable new UpDownSequence upDownSequence; // returns new digitized price double digitize(double price) { double cn = cells.toCellNumber(price); if (cellNumber == Int.MIN_VALUE) { cellNumber = lastCellNumber = iround(cn); } else { lastCellNumber = cellNumber; cellNumber = iroundTowardsWithOutwardEpsilon(cn, cellNumber, epsilon()); // TODO: assuming there are only 1-steps if (cellNumber > lastCellNumber) upDownSequence?.addUp(); else if (cellNumber < lastCellNumber) upDownSequence?.addDown(); } ret digitizedPrice(); } double epsilon() { ret 1e-4; } double digitizedPrice() { ret cells.fromCellNumber(cellNumber); } double lastDigitizedPrice() { ret cells.fromCellNumber(lastCellNumber); } // digitize price without looking at history double digitizeIndividually(double price) { double cn = cells.toCellNumber(price); ret cells.fromCellNumber(round(cn)); } PriceCells priceCells() { ret cells; } // brave void swapPriceCells(PriceCells newPriceCells) { cells = newPriceCells; } }