Support Board
Date/Time: Sat, 08 Feb 2025 13:44:56 +0000
[Programming Help] - Rounding issue
View Count: 795
[2020-07-06 10:03:10] |
gfx2trade - Posts: 48 |
Hi team, I don't really get why the rounding to tick size doesn't work with the following code... why does the only hard coded value provide a correct rounding number ? avgPrice = sc.RoundToTickSize(PositionData.AveragePrice, 0.01); ServiceLogStr.Format(" Average Price : %f ", avgPrice ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); avgPrice = sc.RoundToTickSize(PositionData.AveragePrice, sc.TickSize); ServiceLogStr.Format(" Average Price : %f ", avgPrice ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); avgPrice = sc.RoundToTickSize(PositionData.AveragePrice, myTickSize); ServiceLogStr.Format(" Average Price : %f ", avgPrice ); sc.AddMessageToTradeServiceLog(ServiceLogStr, 0); with SCInputRef Input_TickSize = sc.Input[19]; float myTickSize = 0.00; Input_TickSize.Name = "Asset Tick Size"; Input_TickSize.SetFloat(0.01); Input_TickSize.SetDescription("Underlying asset tick size."); myTickSize = Input_TickSize.GetFloat(); |
[2020-07-06 10:04:27] |
gfx2trade - Posts: 48 |
result in log... Average Price : 176.020000 | 2020-07-06 12:03:36.022 Average Price : 176.019996 | 2020-07-06 12:03:36.022 Average Price : 176.019996 |
[2020-07-06 15:28:48] |
User907968 - Posts: 826 |
see https://en.wikipedia.org/wiki/Floating-point_arithmetic 0.01 -> double precision floating point sc.TickSize -> single precision floating point Date Time Of Last Edit: 2020-07-06 15:29:41
|
[2020-07-14 16:02:03] |
gfx2trade - Posts: 48 |
thks but it does help. A few lines of codes to highligth the differences would be appreciated |
To post a message in this thread, you need to log in with your Sierra Chart account: