The mathematical rule is, if the last decimal digit is a 5 or higher, round up, otherwise round down.
Be consistent with whatever rule you follow. From: [email protected] [mailto:[email protected]] On Behalf Of sanjiv Sent: Friday, June 25, 2010 8:12 AM To: [email protected] Subject: [amibroker] Rounding Trade Prices Up or Down : based on Tick Size Hello Friends, I need to ROUND UP or DOWN some values based on TickSize. Sometimes I need to round UP and sometimes round Down. Based upon some postings of the Group, I wrote following functions for the purpose. MOST of the time the results are on expected line. However on some RARE occasions RoundUp_TickSize is returning lower value. Sometimes RoundUp_TickSize as well as RoundDn_TickSize are modifying already round values. Further prec(ARRAY, precision ) function is giving errors if my functions are called inside a loop. It will be nice if you can please guide me my errors. With Regards Sanjiv Bansal =================== TickSize = 0.05; function Round2TickSize( aValue ) { TickInv = 1 / TickSize; return ( round( aValue * TickInv ) / TickInv ); } function RoundUp_TickSize( aValue ) { TickInv = 1 / TickSize; return( (ceil( Prec(aValue,2) * TickInv )) / TickInv); } function RoundDn_TickSize( aValue ) { TickInv = 1 / TickSize; return( (floor( Prec(aValue,2) * TickInv )) / TickInv); }
<<image001.jpg>>
<<image002.jpg>>
