Login Page - Create Account

Support Board


Date/Time: Fri, 26 Apr 2024 18:48:59 +0000



[Locked] - GetTradePosition returns 0 while it should return -4

View Count: 883

[2020-09-03 08:31:00]
User888583 - Posts: 19
I have an issue with using current exposure which reports 0 after recalculation despite using error checking.

First of all, I use autoloop study `sc.AutoLoop = 1;`

Few guards are in place, that force my code to be executed only last bar only (most recent ticks), except full recalculation/download history/and previous bars.

if (sc.IsFullRecalculation || sc.DownloadingHistoricalData || (sc.Index != sc.ArraySize -1))
return;

After that I run following code to get PositionData and from there I can get Quantity and Avg price.

s_SCPositionData PositionData;
int Result = sc.GetTradePosition(PositionData);
if (Result == SCTRADING_ORDER_ERROR)
{
// error with getting pos data
return;
}

int Quantity = PositionData.PositionQuantity;
// I am using Quantity in my Study

The thing is, it works well until I hit INSERT, which force study to recalculate. Above code should protect me from falling into errors with getting Orders.
But in reality, it passes first check (IsFullRecalculation/scIndex!=ArraySize-1 etc...) and another check when its not possible to get PositionData.
Function reports 0, while in reality its for example -4, or +4 or whatever the amount is.

Please see screenshot for reference. We have -4 everywhere, except after recalculation in logs we see PositionQuantity reports "0" which is false.

What I am looking for is
1. How to get open position quantity in reliable way, or how to guard my code to execute when PositionData is "ready to use"
2. Where I can see sources of "Trading: Position Quantity" study, which seems to report data properly and I could use this for reference.

Thanks,
Lukasz
imageUntitled.png / V - Attached On 2020-09-03 08:25:18 UTC - Size: 97.65 KB - 297 views
Attachment Deleted.
[2020-11-04 02:43:58]
Bedhog - Posts: 167
I am also having an issue with "Trading: Position Quantity" not being updated on every bar.

The study is hidden and the draw style is = "Value of Subgraph". Then I use Text Display for Study to keep the Position Quantity on the primary chart.

This is interfering with the "Trading System Based On Alert Condition" Exits because the alert condition makes reference to the "Trading: Position Quantity" which is inaccurate.

If I press Insert, the value refreshes.

Thank you.
[2020-11-05 03:15:05]
Sierra Chart Engineering - Posts: 104368
We will check on this.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2020-11-05 19:44:30]
Sierra Chart Engineering - Posts: 104368
We do not see any obvious problem with this study:
"Trading: Position Quantity"

It is completely stable and works perfectly even during a chart replay and even with variable timeframe bars.

First thing we want you to do is to update Sierra Chart to the current version and see if you can reproduce the problem.

If so, we need to get your chart by following these instructions:
Support Board Posting Information: Providing Chartbook with Only a Single Chart

And then we need instructions on how to reproduce.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2020-11-05 19:45:06
[2020-11-05 20:14:36]
User888583 - Posts: 19
Problem is not with the study "Trading: Position Quantity" actually this study reports position quantity properly.

What we are looking for is how to get reliable Position Quantity in ASCIL.
I used following code - but do not work always when you hit Insert.

For example, open 1 contract long, it will return +1, but when you hit Insert everything recalculate and this code will return 0 while in reality you have exposure "1". After some time it start reporting quantity properly.

s_SCPositionData PositionData;
int Result = sc.GetTradePosition(PositionData);
if (Result == SCTRADING_ORDER_ERROR)
{
// error with getting pos data
return;
}
int Quantity = PositionData.PositionQuantity;
// I am using Quantity in my Study

How can we get Position Quantity in ascil in reliable way?

Thanks,
Lukasz
[2020-11-10 12:23:56]
Bedhog - Posts: 167
I am finding that it works reliably on replay. It is not reliable connected to Denali in LIVE or SIM.
[2021-07-19 19:57:27]
algo221 - Posts: 3
I have the same concerns, impossible to have information on open positions. All information returns null values.
I tried all the possible solutions but nothing ....
[2021-07-19 21:32:21]
Sierra Chart Engineering - Posts: 104368
Regarding post #7, it is impossible for us to help because we do not know what function you are using, and how you come to the conclusion that you do.

We are locking this thread, start a new thread.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2021-07-19 21:32:30

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account