Login Page - Create Account

Support Board


Date/Time: Sun, 11 May 2025 23:18:39 +0000



Flattening position without orders - PT doesnt reset LastFillDateTime nor LastExitDateTime

View Count: 1322

[2016-05-04 11:47:14]
wat - Posts: 67
I am trying to flatten position when there is not PT or stop loss. During simulation or replay there is no problem but when connected to IB, hitting stoploss works fine but hitting PT (which is limit order) causes:

strategy sees no PT and LastFillDateTime and LastExitDateTime are old, flattens position
LastFill 51.594000 s ago, LastEntry 51.594000 s ago, LastExit 1490.935000 s ago | 2016-05-03 16:59:52
position gets canceled and flattened into negative
LastFill 1.835000 s ago, LastEntry 1.835000 s ago, LastExit 2.240000 s ago | 2016-05-03 16:59:55
position gets flattened again because no orders and gets to 0.

My problem is that PT dissapears but neither LastFillDateTime nor LastExitDateTime is set hence it looks like the position is without orders.

if(PositionData.PositionQuantity != 0) {
if((sc.GetNearestStopOrder(Order) == 0 || sc.GetNearestTargetOrder(Order) == 0) && (sc.LatestDateTimeForLastBar - PositionData.LastFillDateTime)/SECONDS > 1) {
sc.FlattenAndCancelAllOrders();
}
}

Is there a way to make it work? Thank you.
[2016-05-04 15:19:34]
Sierra Chart Engineering - Posts: 104368
We are not fully understanding this. The way this is presented is far too complicated.

If s_SCPositionData::LastFillDateTime and s_SCPositionData::LastExitDateTime are not being updated, then there must be some problem with the order fill from TWS.

Look for the order fill in the Trade Activity Log for the Symbol and Trade Account:
https://www.sierrachart.com/index.php?page=doc/doc_TradeActivityLog.php
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-05-04 16:16:46]
Sierra Chart Engineering - Posts: 104368
For example, some things that could be wrong about the fill, are the Date-Time, Symbol, the Trade Account, the Open/Close field.
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-05-09 14:14:00]
wat - Posts: 67
I am attaching screens of logs and chart. This doesn't happen every time. Sometimes the PT order is filled correctly. This seems to happen when PT order dissapears without resetting fill time and while being filled.

Strategy then sees the situation as in market but without orders and flattens forcing position into negative. Do you have an idea where the problem is? Thank you.
imagepripad_SC5m.png / V - Attached On 2016-05-09 14:10:14 UTC - Size: 36.47 KB - 275 views
imagepripad_SCTrade Activity Log.png / V - Attached On 2016-05-09 14:10:18 UTC - Size: 213.89 KB - 300 views
imagepripad_SCTrade Activity Log příkazy leva.png / V - Attached On 2016-05-09 14:10:21 UTC - Size: 672.71 KB - 339 views
imagepripad_SCTrade Activity Log příkazy prava.png / V - Attached On 2016-05-09 14:10:23 UTC - Size: 478.82 KB - 323 views
imagepripad_TWS.png / V - Attached On 2016-05-09 14:10:25 UTC - Size: 77.67 KB - 312 views
Attachment Deleted.
[2016-05-09 17:30:32]
Sierra Chart Engineering - Posts: 104368
Not sure what you are trying to tell us in this last post.

Also, what is meant by "PT"?
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-05-10 09:29:38]
wat - Posts: 67
PT - Target order.

My problem is that in some cases, when connected to IB on realtime, the condition for checking that there is position without orders doesnt work, because:

Target order dissapears and is being filled
LastFillDateTime is not reset so I have no idea that its being filled
Position gets flattened and then filled getting from Long position to Short one (or other way around).

So I am trying to find out whenever this is problem in sierra, ib or there is other working way to check for situation when there is position without target or stop order.
[2016-05-10 09:48:57]
Sierra Chart Engineering - Posts: 104368
What exactly do you mean by this:
LastFillDateTime is not reset


Position gets flattened and then filled getting from Long position to Short one (or other way around).
We do not know what is meant by this. Do you mean the position quantity goes to zero and then to a nonzero number? OK but we do not understand the context of this.

We really are quite lost as to what you are describing. This is not being presented in a way which we can understand and help with.

You should also take note of the information here:
Interactive Brokers Trading Service: Trade Position Line or Quantity Disappearing or Displaying Zero


If there is improper Position reporting from TWS, that is going to affect the Open/Close variable of fills which can cause all kinds of problems with calculations involving fills.
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-05-10 09:50:45
[2016-05-10 09:51:15]
Sierra Chart Engineering - Posts: 104368
And if you can avoid Interactive Brokers and switch to another trading service, that is going to be much better. The Interactive Brokers API is sub standard. And really we are at a point, where we do not really want to get involved in this. It is not worth it for us. These problems with Interactive Brokers are enormous and take far too much of our time and your time as well.

It is improper that they cannot provide proper position reporting or have a well-designed interface.

Or consider using the Order Fill Calculated Position for stability:
https://www.sierrachart.com/index.php?page=doc/doc_TradeStatusWindows.html#OrderFillCalculatedPosition
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-05-10 10:41:41
[2016-05-10 10:41:04]
Sierra Chart Engineering - Posts: 104368
We do recommend using the Order Fill calculated position at least for the purpose of determining if that resolves the problem:

https://www.sierrachart.com/index.php?page=doc/doc_TradeStatusWindows.html#OrderFillCalculatedPosition
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-05-10 15:57:16]
wat - Posts: 67
Sadly OrderFillCalculatedPosition didnt help us.


Seems like the problem is caused by sierra not getting update on position and portfolio (namely Portfolio Update and Execution Callback) and hence acting on incorrect data (chat with TWS support):

Siteng J: I have been digging in to the log file and here is what I have found:
Siteng J: You originally submitted a buy order at 4311.25 and it was filled, so you entered +5 position, this is correctly sent in the portfolio entry
Siteng J: After around 5 minutes of the execution of the parent, your profit taker was also filled at 4316.25
Siteng J: The corresponding execution report has been triggered
Siteng J: However, before the next portfolio update has been sent out by TWS, I see that Sierra placed another market order to sell 5 NQ, and it was executed immediately
Siteng J: Afterwards, the portfolio entry of -5 was sent back automatically
me: So the problem was caused by the Sierra being quicker than the portfolio update by TWS? How long delay would fix that?
Siteng J: I am not sure what was the strategy used by Sierra Chart and why the market order was sent
Siteng J: It is possible that their strategy rely on the portfolio update call back
Siteng J: But note we are not able to guarantee the there will be a portfolio update for each execution
Siteng J: For example, when several executions take place close to each other, it is possible that only one portfolio update is sent to reflect all changes
Siteng J: But it is guaranteed that there will be an execution details call back sent for each execution
me: I see. This isnt happening every time. So I wonder how long wait time for check "position without orders" would mitigate this issue.
me: In order to reflect the time between order and portfolio update... for example in this case
me: Would, for example, one second be enough to move the flattening order after portfolio update?
Siteng J: Actually I would not suggest you base your strategy on the portfolio update
Siteng J: This is not guaranteed to be sent for each execution or immediately after an execution
Siteng J: I would suggest you monitor the execution call back function directly
me: Thank you. Sadly I am not able to override Sierra behavior so at the moment so I have no direct access to TWS API. Is there any possible way for me to solve this issue beside waiting for any portfolio update?
Siteng J: Unfortunately you would need to contact Sierra Charts and see if they can adjust this for you

We are not able to switch Broker. Since we are unable to monitor API data flow ourselves would some wait time fix the issue with late data update? Or is there any other way to reliably check if we are in position without orders?

Thank you
[2016-05-10 18:19:50]
Sierra Chart Engineering - Posts: 104368
The Sierra Chart Trade Position Quantity which your trading system can request is updated by order fills/executions. It is not directly updated by Trade Position data updates from the external trading service.

However, if the calculated Position Quantity from the order fills is out of sync with the reported Trade Position Quantity from the external trading service, then after about 8 seconds the order fill calculated Position Quantity will be synchronized to the Trade Service Position Quantity after there has been an unsolicited update of the Trade Service Position Quantity, but that is not relevant in this case.

If there is a solicited Trade Position update, the synchronization happens immediately.

So it does not matter if there is a delay with the Position updates or some are missed. It is totally irrelevant.

There is nothing to fix other than with your automated trading system. Possibly reducing the Chart Update Interval might help but only you would know best:
https://www.sierrachart.com/index.php?page=doc/doc_ChartSettings.html#ChartUpdateInterval

Siteng J: However, before the next portfolio update has been sent out by TWS, I see that Sierra placed another market order to sell 5 NQ, and it was executed immediately
Siteng J: Afterwards, the portfolio entry of -5 was sent back automatically
me: So the problem was caused by the Sierra being quicker than the portfolio update by TWS? How long delay would fix that?
Siteng J: I am not sure what was the strategy used by Sierra Chart and why the market order was sent
Siteng J: It is possible that their strategy rely on the portfolio update call back

Also these comments are speaking as if somehow Sierra Chart is creating and performing the automated trading but that is your own system.
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-05-10 18:26:07
[2016-05-11 06:46:42]
Sierra Chart Engineering - Posts: 104368
So to be clear, when your automated trading system gets the current Position data, this data is current as of the last execution/fill received from TWS.

The issue described by IB about the Position Quantity update, is not relevant and never has been in Sierra Chart.
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-05-11 06:47:08

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

Login

Login Page - Create Account