How to round to the higher, lower or nearest tick
Here are three simple functions to round a price to its higher, lower or nearest tick.
function RoundToHigherTick( price, tick ) { return ceil( price / tick ) * tick; } function RoundToLowerTick( price, tick ) { return floor( price / tick ) * tick; } function RoundToNearestTick( price, tick ) { rounded = RoundToHigherTick( price, tick ); return IIf( rounded - price > tick / 2, roundToLowerTick( price, tick ), rounded ); } |
Comments
Post a Comment