Login Page - Create Account

Support Board


Date/Time: Fri, 27 Dec 2024 00:45:46 +0000



*Technical Issue* sc.GetTradePosition(PositionData) NOT updating PositionQuantity

View Count: 1238

[2016-03-30 03:37:53]
User972044 - Posts: 154
Somehow after I exited the trade via the sc.FlattenPosition(); statement, and then when I call s_SCPositionData PositionData and sc.GetTradePosition(PositionData); the two statements again, and then when I check the PositionData.PositionQuantity, the PositionQuantity does NOT get updated at all. I actually check it in a log, and the log still shows PositionQuantity reflecting the outstanding trade quantity when in fact the position has already been flattened via the sc.FlattenPosition(); statement. I actually designed my trading system to immediately enter into a trade in the opposite direction as soon as the previous position is closed on the same bar as long as the entry condition is met and I have set sc.SupportReversals = true; and sc.AllowOnlyOneTradePerBar = false; but in order to prevent overtrading, I actually check the PositionData.PositionQuantity before I enter a new trade. Now with PositionQuantity not being updated after the position is flattened, I have to create a position counter manually updating and keeping track of my trade amount.

Can you look into this to find out this sc.GetTradePosition(PositionData) does not reflect the correct PositionQuantity when it's called? According to your documentation, the copy of the PositionData is supposed to be updated each time when sc.GetTradePosition(PositionData) is called. So after a trade is closed, it should be already reflected in the database and when sc.GetTradePosition(PositionData) is called it's supposed to report the new quantity.

Thanks for your help in advance
Date Time Of Last Edit: 2016-03-30 03:38:14
[2016-03-30 03:41:52]
User972044 - Posts: 154
Oh and btw, I call the s_SCPositionData PositionData and sc.GetTradePosition(PositionData); the two statements in the beginning of the program right after the (sc.SetDefaults) block but before the if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED){} block wherein I close and open trades and then within the if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED){} block, I call the two s_SCPositionData PositionData and sc.GetTradePosition(PositionData); the two statements again after exiting the trades. I don't know if this new information helps you.

Thanks.
[2016-03-30 04:01:09]
Sierra Chart Engineering - Posts: 104368
Regarding post #1 how do you have Trade >> Trade Simulation Mode On set?
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
[2016-03-30 05:08:09]
User972044 - Posts: 154
No I did NOT have "Trade Simulation Mode On" set. I was trading live and none of the entry trades that met all the entry requirements got executed and on the log it showed that PositionData.PositionQuantity did NOT reflect the updated position after I flattened the previous position AND called sc.GetTradePosition(PositionData) again.

Thanks
[2016-03-30 10:04:25]
Sierra Chart Engineering - Posts: 104368
Refer to the documentation here about this:
https://www.sierrachart.com/index.php?page=doc/doc_AutoTradeManagment.php#DifferencesLiveSimulationAutoTrading
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
[2016-03-30 10:24:19]
User972044 - Posts: 154
I already read this article several times before. What are you implying as the cause of this problem? This article just mentioned the possible difference that I can encounter when live trading vs. simulated trading so what does this mean about this PositionData.PositionQuantity not being updated? I did NOT call s_SCPositionData PositionData and sc.GetTradePosition(PositionData); statements after checking whether the trade has been executed successfully or not so the delay that could be encountered in live trading is NOT relevant here if that's what you are referring to. As soon as I executed a sc.BuyEntry() or a sc.SellEntry(), I call the s_SCPositionData PositionData and sc.GetTradePosition(PositionData); right away, so you are telling me by that time Sierra Charts still has not updated the trading position information database where sc.GetTradePosition(PositionData) statement gets the copy of trading position from?

Is that what you are referring to? If yes, why so slow? When does the trading information actually get updated? It would be more helpful if you can explain what is the cause of the problem instead of directing your user to just some documentations without any explanations. And once you clarified, can you provide some suggestions as what should I do? Can I never rely on this PositionData.PositionQuantity information as it will always be slow and instead should just keep track of trading position information manually like what I am doing now? Or should I set sc.UpdateAlways to true if I really want to use PositionData.PositionQuantity and if yes, how would I help? Please advise.

Thank you.
Date Time Of Last Edit: 2016-03-30 10:26:05
[2016-03-30 10:29:00]
Sierra Chart Engineering - Posts: 104368
As soon as I executed a sc.BuyEntry() or a sc.SellEntry(), I call the s_SCPositionData PositionData and sc.GetTradePosition(PositionData); right away,
This is the problem. The Position will not have updated at that moment in time.

When does the trading information actually get updated?
The Position Quantity only updates when an order fill is received. That can be sometime later. Should be very fast but it is not going to be when processing is still in the study function.

When the Position Quantity changes, the study function will be called. So there is no need to use sc.UpdateAlways.
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: 2016-03-30 10:29:27
[2016-03-30 11:11:06]
User972044 - Posts: 154
Thanks for the explanation. This is much more helpful. So how would I know when the position is updated or rather when the order is actually filled? Am I supposed to check for the position quantity when checking the order status block like the following?

s_SCTradeOrder TradeOrderData;

int OrderStatusCode = TradeOrderData.OrderStatusCode;

if (OrderStatusCode == SCT_OSC_FILLED)
{
// The order has completely filled
}

What if when I am checking the order status it still hasn't shown as filled what then? I will never get the position quantity by the time when I need to get the accurate position information when I need to trade? Because I cannot keep checking it every x seconds. And this is what seems to be happening. When I need to enter a new trade in the opposite direction and when I use the PositionQuantity information, it's not updated and I was prevented from entering the trade.

Again my question: Why so slow if indeed the order fill is the problem? So do I just keep track of the trading information manually? Then if that's the case, what's the point of sc.GetTradePosition() when it's not going to be real-time?

Thanks
Date Time Of Last Edit: 2016-03-30 11:12:26

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

Login

Login Page - Create Account