Portfolio Synchronization of AtLimit orders
Author: Frank1972
Creation Date: 12/19/2016 9:41 PM
profile picture

Frank1972

#1
Hi,

I have question about portfolio synchronization. What happens if:

1. Wealth-Lab thinks that positions wasn't filled using BuyAtLimit.
2. Fidelity Fills the position - Order triggers on bid and becomes a market order and fills
3. Exit comes in

When I go to place the exit using:
CODE:
Please log in to see this code.


Where should I get the position object? Should I use the one that was returned from the BuyAtLimit? Doing it this way is the way to resolve the portfolio being out of synchronization for this use case?

Thanks,

-Frank
profile picture

Eugene

#2
Hi,

If Position wasn't filled using BuyAt*, its Position object is null. You cannot sell what you don't own. Check out Orders > Portfolio Synch > AtLimit Entries in the Wealth-Lab User Guide.
profile picture

Cone

#3
"Wealth-Lab thinks that positions wasn't filled using BuyAtLimit" is an extremely unlikely scenario as long as the limit order slippage preference is not activated (F12 > Slippage and Round Lots.

What's far more likely (when limit order slippage is de-activated) is that WL Pro thinks a limit order executed, but actually did not. In this case, as Eugene pointed out, see the discussion in the User Guide.
profile picture

Frank1972

#4
Eugene and Cone,

Thanks for all your help on this issue. I have changed my code to process all bars and not just the last one. Things are now working better, but I am having an issue with understanding how portfolio synchronization works as it relates to the Order Window. Please see the attachment. In my script I can see from the logs that a BuyAtLimit order is placed for stock PERI. I can also see that it is filled in the Order window but my script doesn't see this in the ActivePositions array and thus places another BuyAtLimit order. This can be seen in the Order window as well.

If the Order Window shows an order status of Filled does that mean that in my script that I should see that in the ActivePositions array? Or am I not understanding something about how the Order Window works and relates to the scripts execution?

Thanks,

-Frank
profile picture

Cone

#5
First, there is no synchronization between a script and the Orders tool / live account whatsoever. Just remember that a script has no idea what's going on except in it's own code.

"Synchronization" per se is limited to the Orders tool and a live account. In this case, and when Synch is enabled:
1. The orders tool will limit the number of shares in an exit order to the shares in your account, and,
1b. if you use the "Exit All" preference, it will increase the shares of an exit order to the full quantity held in your account.
2. The orders tool will "eat" (reject) exit orders for a position that does not exist in your account.
3. The orders tool will reject duplicate order for the same Account/Symbol/Strategy/Scale/Order Type/Order Price, etc.

Without knowing the code in your strategy, I cannot tell you why the strategy would not think that the order was filled at 1.40.

Finally, you're using the Paper Trader! This makes a big difference because the Paper trader is not robust and does not get the streaming data. Instead, the paper trade polls for a single quote every 15 seconds or so. In this case, it will frequently occur that Wealth-Lab thinks a trade executed when one did not.
profile picture

Cone

#6
Update:
After reviewing the chart. I've got an explanation: It's the Paper Trader.

You see, the first Alert was generated at 1:50pm, and PERI closed at 1.40 on that bar. However, the bar ending 1:51pm traded a low of 1.41. So, probably what happened is that the Paper Trader polled for the last quote and filled the 1.40 limit price, but it's not possible for WLP (or anyone) do have generated an order at 1:50pm and have it filled at 1.40.. .only the non-robust paper trader can do that!

In short, it's another shortcoming of the paper trader and I can practically guarantee you that this could not occur in live trading.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).