Support Board
Date/Time: Mon, 16 Jun 2025 08:38:58 +0000
Issue with Price Accuracy when Logging Orders in CSV
View Count: 250
[2025-05-12 06:13:05] |
User299099 - Posts: 11 |
Hello, I am facing an issue when logging orders and trades in a CSV file. The prices recorded in the file show a difference of between 0.5 and 2.5 points compared to the prices displayed directly in Sierra Chart. Currently, I am using the following method to capture the prices: ```cpp double rPrice1 = (order.Price1 != DBL_MAX && order.Price1 != -DBL_MAX) ? sc.RoundToTickSize(order.Price1, sc.TickSize) : 0.0; double rPrice2 = (order.Price2 != DBL_MAX && order.Price2 != -DBL_MAX) ? sc.RoundToTickSize(order.Price2, sc.TickSize) : 0.0; double rAvgPrice = 0.0; if (fabs(currentPos) > FLOAT_EPSILON && posData.AveragePrice != DBL_MAX && posData.AveragePrice != -DBL_MAX) { if (order.OrderStatusCode == SCT_OSC_FILLED && ((currentPos > FLOAT_EPSILON && order.BuySell == BSE_SELL) || (currentPos < -FLOAT_EPSILON && order.BuySell == BSE_BUY))) { rAvgPrice = sc.RoundToTickSize(order.Price1, sc.TickSize); } else { rAvgPrice = sc.RoundToTickSize(posData.AveragePrice, sc.TickSize); } } ``` The prices are formatted using this function: ```cpp static SCString MyFormatPrice(SCStudyInterfaceRef sc, double price, int decimals, double tickSize) { if (tickSize <= 0.0) tickSize = 1e-10; if (decimals < 0) decimals = 0; if (decimals > 20) decimals = 20; double roundedPrice = sc.RoundToTickSize(price, tickSize); int tickDecimals = DetermineActualDecimals(tickSize); int formatDecimals = std::max(decimals, tickDecimals); SCString formatted; SCString fmt; fmt.Format("%%.%df", formatDecimals); formatted.Format(fmt, roundedPrice); const char* str = formatted.GetChars(); int len = static_cast<int>(strlen(str)); const char* decimalPoint = strchr(str, '.'); if (decimalPoint != nullptr) { int decimalPos = static_cast<int>(decimalPoint - str); int minRequiredDecimals = std::max(decimals, tickDecimals); int minEndPos = decimalPos + minRequiredDecimals; int lastNonZero = len - 1; while (lastNonZero > minEndPos && str[lastNonZero] == '0') { lastNonZero--; } if (lastNonZero == decimalPos) { lastNonZero--; } return formatted.Left(lastNonZero + 1); } return formatted; } ``` It seems that the functions related to `floor` and `fabs` in this logic might be causing the difference between the captured prices and the actual prices displayed on the chart. My goal is to capture the entry and exit prices of orders exactly as they appear in Sierra Chart, without the current difference. Could you please guide me on how to adjust this method to achieve this? Thank you in advance for your help. |
[2025-05-12 09:42:19] |
Sierra_Chart Engineering - Posts: 19924 |
Give us an example of the price that you see, and the symbol.
Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: