- ago
When running live strategies using the Alpaca extension, I frequently encounter Buy/Sell signals that are never actually executed.

For example, consider the following 4 signals shown here:

The expected result is to Cover, Buy, Sell, and Buy.

But then when I go and look at the resulting transactions in Alpaca, the third signal (the Sell) was never executed:


It's not clear to me why the fourth signal, the Buy, was executed by the strategy, because the block is only supposed to execute if there are 0 open positions:


What could be going on here? There's no error or warning in the Wealth Lab debug log. I am running WL build 22, and Alpaca build 7. I have the following Portfolio Sync settings:


The impression I get, after having frequently encountered this situation when running different strategies using the Alpaca extension, is that sometimes WealthLab sends a Buy or Sell signal to Alpaca and thinks that everything completed successfully, when in actuality, Alpaca either never received the command, or failed to process it for some unknown reason.
0
406
Solved
19 Replies

Reply

Bookmark

Sort
Cone8
 ( 25.44% )
- ago
#1
We'll have to look into it. If the live positions actually created positions in your account, possibly something is failing in the Portfolio Sync exit logic. Did you say you noticed missing trades for market order entries too?

Aside:
I noticed that you have both "Reduce size" and "Always set" Portfolio Sync options selected. Perhaps this was a mistake to allow those to be selected simultaneously. In my mind only one of those options should be selected.
1
Glitch8
 ( 11.81% )
- ago
#2
I think you might be confusing the historical BACKTEST trades that WL7 is showing on the chart with actual Signals that get submitted to Alpaca.

The chart is just showing you your theoretical backtest results, not any actual trades. How to put the Strategy into practice would be either run it every day (if daily) or maybe in the Strategy Monitor (if intrday) and either place the resulting signals manually of condigure the SM to auto-place them.
1
- ago
#3
Thank you both for the response.

Cone: I've been encountering this issue since before the implementation of Portfolio Sync, so I don't believe it to be directly related to that. However, I will make sure to only check one of the two settings you mentioned. And to confirm, yes, I've noticed this problem occurring for both market entries and market exits.

Glitch: What I've started doing is running a Streaming backtest (simply as a troubleshooting tool) at the same time I run the strategy in the Strategy Monitor. Only the Strategy Monitor has the "Auto-Place" setting enabled. I've been testing exclusively with intraday 1-minute strategies.

Most of the time, everything works quite nicely, and I can see the signals on the chart matching up perfectly with the actions the Strategy Monitor performs. But then every once in a while, I see situations like I displayed in the OP, where the Strategy Monitor fails to enter or exit a position that shows up on the chart.

Now, if this was just some simple divergence because of minor differences in timing or something, that would be fine. But the problem is that the Strategy Monitor continues executing as if the position had been successfully opened or closed, which means that the next Signal executed by the Strategy Monitor will be incorrect, either Buying when there's already an open position, or selling when there is no open position, causing a Short position to unexpectedly be created.
0
Cone8
 ( 25.44% )
- ago
#4
QUOTE:
the problem is that the Strategy Monitor continues executing as if the position had been successfully opened or closed

This statement is a sort of admission of guilt to what Glitch explained. All strategies, no matter what tool, will "[continue] executing as if the position had been successfully opened or closed" by design.

Example:
Assume your account has no buying power and a strategy places a buy order. The order fails and the broker returns an error. Nonetheless, the strategy entered a Position, hypothetically, therefore the the exit logic kicks in... When the strategy places an exit signal, several things can take place based on the Portfolio Sync options.

No options selected -
The exit signal is placed, and, depending on the broker, will result in either a rejected order for no corresponding position, OR, a broker like IB may create a SHORT position for the sell signal if sufficient buying power exists.

"Reduce size" or "Always set" is selected -
Wealth-Lab will attempt to match the signal with a Position in the destination account. Since a Position doesn't exist, the check will fail and the exit signal will be suppressed.

Your OP doesn't really have any specific evidence for symbols, account positions, etc. And that level of detail is required to determine if what occurred is correct or not. Now that you're aware of the hypothetical nature of how strategies execute, you can take that into account.
1
- ago
#5
QUOTE:
All strategies, no matter what tool, will "[continue] executing as if the position had been successfully opened or closed" by design.

I guess the real problem is that there is no indication that a position failed to open or close. Shouldn't Wealth Lab receive some sort of response from Alpaca when an order fails, and display that in the debug log?

I will try and create a simple reproduction case for you guys to examine.
0
Glitch8
 ( 11.81% )
- ago
#6
This is visible in the Order Manager.
1
- ago
#7
Thank you. It's possible there were errors there that I missed, since I was looking in the Strategy Monitor log pane, and the Wealth Lab "Log Viewer".

While typing this message, I had an error appear in the Order Manager, but it has now been overwritten by a later signal that was processed successfully. Is this the intended behavior? I don't have any of the "Auto-Remove" settings enabled. It will be difficult to troubleshoot if I don't have a preserved record of past order failures.

Here is a simple test-case strategy: https://www.dropbox.com/s/7snx0ekocujd9d2/Alpaca%20Test%20Case.WL7Strategy?dl=0

All it does is buy at market open, hold for 1 bar, then sell at market open. I am using a freshly created Alpaca Paper trading account, and running the strategy on symbol "GME" using the Strategy monitor, with "Auto-Place" enabled. I've been running it for the past 45 minutes, and it's only opened 2 positions. Here is an overview of what I'm looking at:
https://www.dropbox.com/s/wqcaoop3fzmgim4/desktop.png?dl=0

Here are the contents of the various logs:
Strategy Monitor: https://www.dropbox.com/s/vzuzspros29u2fw/strategy_monitor_log_pane.txt?dl=0
Order Manager: https://www.dropbox.com/s/mgf3hf87pfwefjs/order_manager_log_pane.txt?dl=0
Log Viewer: https://www.dropbox.com/s/nb42iassmbd2l3z/wealth_lab_log_viewer.txt?dl=0

My Wealth Lab Preferences for Portfolio Sync:


My position configuration settings:


0
- ago
#8
I restarted everything and managed to reproduce the error that I mentioned in the previous post:


It's not clear to me why the strategy was attempting to execute a "Sell", when it never executed a "Buy" beforehand, and my Alpaca Paper Trading account had no open positions when I started running the strategy (and it still has none).
0
Cone8
 ( 25.44% )
- ago
#9
Open Tools > Accounts (Ctrl+T)
What does the Alpaca account have for positions, cash, and buying power?

I can see that 27 shares of GME was filled and showing on the Alpaca site, but let's see what Wealth-Lab is aware of in the Accounts tool..
0
Glitch8
 ( 11.81% )
- ago
#10
Remember, the Strategy is not per se linked to your Alpaca account. It must have had an open long position in order to generate a sell, regardless of whether your alpaca account had one or not. The error you’re seeing is from the Portfolio Sync feature correctly intercepting that sell and causing it to not get placed to alpaca. in other words, it’s doing it’s proper job.
1
- ago
#11
I've continued running the strategy throughout the past hour, this is what I see in "Accounts" at the moment:
0
Cone8
 ( 25.44% )
- ago
#12
Glitch, the strategy monitor did place and fill the 27 shares - proof in the dropbox link image of the S. Monitor + Order Mgr. I'll take a look at the strategy.
0
Glitch8
 ( 11.81% )
- ago
#13

QUOTE:
It's not clear to me why the strategy was attempting to execute a "Sell", when it never executed a "Buy" beforehand, and my Alpaca Paper Trading account had no open positions when I started running the strategy
0
- ago
#14
To clarify: The situation Cone is describing happened when I first ran my Alpaca Test Case strategy. The quote from Glitch is describing what happened later, after I restarted everything and started running the strategy again, in an attempt to catch the error message that I couldn't see the first time.
0
- ago
#15
I just fully reset my Alpaca Paper trading account, and generated a new API key. Then I closed Wealth Lab and reopened it, to run the Alpaca Test Case strategy.

The first Signal generated is a "Sell", when my account has no existing position yet:
https://www.dropbox.com/s/ws0llv902xb1xuw/alpaca_test_case_run_3.png?dl=0

I deactivated the strategy after the error, to make sure I could grab an image of the error in the Order Manager, before it got replaced by a successful Buy signal.
0
Cone8
 ( 25.44% )
- ago
#16
Yes, it's pretty hard to follow the sequence of events here.

The strategy is pretty straightforward - buy when there's no position, sell when there is. So sure, depending on where you start signaling, you have a 50% chance of getting a sell first.

That said, the Alpaca feed should not be used for trading. It's unreliable. You should be getting signals practically every minute of the day for GME, but your image is indicating trades sometimes 15 minutes apart - that's not right for 1 minute bars on GME.
2
Best Answer
- ago
#17
QUOTE:
So sure, depending on where you start signaling, you have a 50% chance of getting a sell first.

The strategy has a Condition block to only Sell if there is an Open position.
0
- ago
#18
QUOTE:
That said, the Alpaca feed should not be used for trading. It's unreliable.

I have switched both the historical data provider and the streaming data provider to no longer use Alpaca, and the Strategy now appears to be executing exactly as expected. Thank you for taking a look at my test case results, Cone.
1
Glitch8
 ( 11.81% )
- ago
#19
QUOTE:
The first Signal generated is a "Sell", when my account has no existing position yet:


As I explained above, this is to be expected, the Strategy is not linked to your Alpaca account as it runs. It will generate a sell if there was a THEORETICAL open position in the backtest.

The link comes when you generate signals. Portfolio Sync will see you don't have a actual position in your alpaca account, turn the Sell signal into the Error you saw before, and not submit it to Alpaca.
0

Reply

Bookmark

Sort