Support Board
Date/Time: Sun, 24 Nov 2024 14:59:35 +0000
Potential Bug With sc.GetTradePosition?
View Count: 260
[2024-05-20 01:56:01] |
PS - Posts: 40 |
I am writing a trading strategy using ASCIL and am not getting the expected functionality from sc.GetTradePosition. I'm unsure if its a bug, or a mistake I'm making. Please see below: First, I do the following: s_SCPositionData PositionData; sc.GetTradePosition(PositionData); int current_position = PositionData.PositionQuantity; Then, the first trade is taken. I know a position has been entered as I can see the drawing on a 1m chart after conducting a Bar-Based Backtest. int current_position is then printed to the logs via: SCString logMessage; logMessage.Format("Current Position = %s", current_position); sc.AddMessageToLog(logMessage, 0); However, for the entire duration of the backtest, current_position = 0 (according to the logs), despite a trade being taken during the backtest. Am I doing something wrong here, or is this a bug? Thank you in advance for your help. |
[2024-05-20 08:58:45] |
User431178 - Posts: 541 |
logMessage.Format("Current Position = %s", current_position); What is the data type of current_position? %s is not correct, should be %i or %d, as it is an integer. |
[2024-05-20 10:31:06] |
Sierra_Chart Engineering - Posts: 17156 |
Yes use %i.
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 |
[2024-05-20 12:37:21] |
emmanuel - Posts: 57 |
Also note that current_position is not going to automatically update after taking a position. You'll need to re-fill the PositionData structure with sc.GetTradePosition(PositionData) and extract the current position again. |
[2024-05-20 15:59:33] |
PS - Posts: 40 |
I've made some edits, but still running into the same issues. Towards the beginning of my code (after all variables have been initialized, first bar in backtest handled, etc.), I run the following code: s_SCPositionData PositionData; sc.GetTradePosition(PositionData); int current_position = PositionData.PositionQuantity; SCString log_position; log_position.Format("Current Position = %i", PositionData.PositionQuantity); sc.AddMessageToLog(log_position, 0); Despite several trades showing up in the backtest trade log, current position = 0 in every single log message print. Am I still implementing this incorrectly? |
[2024-05-20 16:06:46] |
User431178 - Posts: 541 |
log_position.Format("Current Position = %i", PositionData.PositionQuantity); This won't work... You have now moved the goalpost by changing from int to double, but are still using specifier for integer in format. Look in SCStructures.h, see that PositionData.PositionQuantity is double. log_position.Format("Current Position = %f", PositionData.PositionQuantity); This might help - https://cplusplus.com/reference/cstdio/printf/ - as format uses same specifiers. Date Time Of Last Edit: 2024-05-20 16:08:33
|
[2024-05-20 17:23:29] |
PS - Posts: 40 |
Current position is now working. Thanks for all your help.
|
To post a message in this thread, you need to log in with your Sierra Chart account: