Login Page - Create Account

Support Board


Date/Time: Tue, 07 May 2024 19:17:59 +0000



Post From: GetTradePosition returns 0 while it should return -4

[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 - 299 views
Attachment Deleted.