Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 03:32:41 +0000



Position quantity with GetTradePosition is 0 on Teton Order Routing

View Count: 640

[2023-04-26 22:47:03]
glacialspring - Posts: 26
I have a working study that I have used without problems with my rithmic trading account. It stopped working when I switched to my Teton Stage5 with Advantage trading account. After debugging, I found that PositionQuantity member of s_SCPositionData always returns zero. GetTradePosition returned a 1 success, and I see that AveragePrice is still correct. Is this a bug or property of my broker?
[2023-04-27 10:22:17]
Sierra_Chart Engineering - Posts: 17190
It does not make sense that the position quantity would be 0 and the average price would be nonzero?

Also be aware of this:
When an ACSIL trading system study is using Trade Simulation Mode, Trade >> Trade Simulation Mode On, then the Trade Position data is for trades made in Trade Simulation mode only. The symbol of these Trade Positions begin with [Sim]. Otherwise, non-simulated Trade Position data is provided.

From:
Automated Trading From an Advanced Custom Study: sc.GetTradePosition
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
[2023-04-27 14:30:00]
glacialspring - Posts: 26
Right, it doesn't make sense that the position quantity is 0 and the average price is non-zero. I assure you this is what's being returned. The only other measure I've looked at is OpenProfitLoss, and that's also working correctly. Only the position quantity remains at 0. Everything is correct when I am using a rithmic trading account during live trading, but breaks as soon as I switch to the Teton Stage 5 account during live trading.
Date Time Of Last Edit: 2023-04-27 14:34:03
[2023-04-27 14:55:57]
Sierra_Chart Engineering - Posts: 17190
We do not see how this is related to Teton order routing.

Can you provide us, all of the values that you see in the position data structure returned.

When you go to Trade >> Trade Positions Window, do you see all the same values there?
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
[2023-04-27 15:12:12]
glacialspring - Posts: 26
The trade positions window shows the data correctly. I also tried the Trading: Position Quantity study and that is also working correctly. I tried writing a barebones test (below) of the GetTradePosition function and it was not working correctly for this account. I've attached a screenshot, sorry haven't had time to read your screenshot guidelines but I think it is clear enough.

I'll go ahead and check all of the values of the position data structure now.

#include "sierrachart.h"

SCDLLName("Test")

SCSFExport scsf_Test(SCStudyInterfaceRef sc)
{
SCSubgraphRef sgPositionQuantity = sc.Subgraph[0];

if(sc.SetDefaults)
{
sc.GraphName = "Test";
sc.AutoLoop = 0;
    
sgPositionQuantity.Name = "quantity";
sgPositionQuantity.LineStyle = LINESTYLE_SOLID;
sgPositionQuantity.PrimaryColor = RGB(0,255,0);

return;
}

s_SCPositionData pos;
if (sc.GetTradePosition(pos) == SCTRADING_ORDER_ERROR) {
sc.AddMessageToLog("error getting position", 1);
return;
}

for (int i = sc.UpdateStartIndex; i < sc.ArraySize-1; i++) {
sgPositionQuantity[i] = pos.PositionQuantity;
}
}

imagequantitytest.png / V - Attached On 2023-04-27 15:04:16 UTC - Size: 76.86 KB - 121 views
[2023-04-27 15:34:19]
glacialspring - Posts: 26
Here are the values

Symbol: MNQM23_FUT_CME
PositionQuantity: 0
AveragePrice: 13142.749706
OpenProfitLoss: 2.000588
CumulativeProfitLoss: -629.039989
DailyProfitLoss: 9.560000
MaximumOpenPositionLoss: -4.000000
MaximumOpenPositionProfit: 1.500000
LastTradeProfitLoss: 2.520000
PositionQuantityWithAllWorkingOrders: 0
PositionQuantityWithExitWorkingOrders: 0
WorkingOrdersExist: 1
LastFillDateTime: 1355288
LastEntryDateTime: 1355296
LastExitDateTime: 1355304
PriorPositionQuantity: 0
PositionQuantityWithExitMarketOrders: 0
TotalQuantityFilled: 0
LastTradeQuantity: 0
NonAttachedWorkingOrdersExist: 0

[2023-04-27 19:43:30]
Sierra_Chart Engineering - Posts: 17190
We cannot reproduce this and it does not make any sense why there is a problem. This position function, works in a very stable definite manner.

There is also something wrong with your code which we have corrected:
  
for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++)
{
  sgPositionQuantity[i] =static_cast <float >( pos.PositionQuantity);
}

Anytime you use this structure, before calling the sc.GetTradePosition function, reset it because you may be having left over values:

s_SCPositionData SCPositionData ;
SCPositionData = s_SCPositionData();//Reset

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
Date Time Of Last Edit: 2023-04-27 20:24:31
[2023-04-27 20:34:17]
glacialspring - Posts: 26
Ok I tried the code fix, but that didn't affect anything. Let me reiterate that this function works fine on my rithmic trading account but not on my Stage 5 account. Could it be that the broker is not reporting position data correctly?
[2023-04-27 20:47:37]
Sierra_Chart Engineering - Posts: 17190
The position is clearly reported correctly. You can see that in the Trade Positions Window and in the position display on the chart. ACSIL is just returning that same information.

This has nothing to do with Teton order routing at all. It is fully unrelated to that. We are not sure what the issue is in your particular case.
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
Date Time Of Last Edit: 2023-04-27 20:47:52
[2023-04-27 20:51:53]
glacialspring - Posts: 26
In a curious turn, I tried switching to AutoLoop and it started working. Thanks for your time in investigating this issue.
[2023-04-27 22:52:55]
glacialspring - Posts: 26
Actually I tried changing my actual study to AutoLoop and it didn't work... But I'm going to read in the values from the Trading: Position Quantity study as a workaround, so you can consider this resolved.
[2023-10-02 01:58:58]
glacialspring - Posts: 26
I think I figured this out finally thanks to GetOrderByIndex doesn't work when connected to Trade Evaluator Service
For anyone who happens to run into this issue,
s_SCPositionData::PositionQuantity was 0 and no orders were found with sc.GetOrderByIndex due to sc.SendOrdersToTradeService not being set to 1

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

Login

Login Page - Create Account