- ago
Today, I finally got "Ready for Use" approval for Schwab API and I connected my Schwab (former TDA) account to an existing strategy I have been running the same strategy with a dummy broker account, waiting for the Schwab API to be usable. All the settings for both strategies were identical, including daily run time, except for the broker account.

When these strategies ran simultaneously at their set time, it looks like they shared account positions and provided signals accordingly. This led to a successful close of two legacy positions (from TDA) in the Schwab account, and errors on attempted close of the same positions that did not exist in the Dummy account.

I was not trying to break anything; I just didn't anticipate there could be an account position sharing corruption running these simultaneously. I'm wondering there's some sort of memory sharing. Is this a caution not to run two identically configured strategies simultaneously?

0
173
12 Replies

Reply

Bookmark

Sort
Cone8
 ( 7.89% )
- ago
#1
Incomplete picture. The result looks correct to me if you ran both strategies on 2 symbols for 2 accounts.

Give me a more complete picture.
1. What tool ran the strategies? Interval?
2. Was Live Positions enabled?
0
- ago
#2
QUOTE:
The result looks correct to me if you ran both strategies on 2 symbols for 2 accounts.

No, because the starting state, before running the strategies, was that the Schwab account had positions for EDC and TQQQ, but the dummy broker had no positions in either of these symbols. Yet, the strategy connected to the dummy broker attempted to sell the positions that were somehow detected from the Schwab account, and errored when they were not there.

QUOTE:
1. What tool ran the strategies?
WL SM
QUOTE:
Interval?
Daily
QUOTE:
2. Was Live Positions enabled?
No
0
Cone8
 ( 7.89% )
- ago
#3
Strategies run hypothetically. The strategy had hypothetical long positions that it sold.

If you want the strategy to sync to a position in the live Account (includes paper accounts), then you need to enable Live Positions.

The result was correct.

Finally, if you don't want to see those exit order errors for Positions that don't exist, you can enable the first Portfolio Sync preference to "Block Exit Orders when Position not Found". And, for brokers like IB and TS, it will keep you from entering a trade in the opposite direction (Short for a Sell) that you didn't intend to take.
0
- ago
#4
QUOTE:
Strategies run hypothetically. The strategy had hypothetical long positions that it sold.

I'm not sure I understand what a hypothetical long position is, but I don't understand why the strategy that was connected to the dummy broker would have those positions as hypothetical. They just don't exist in the account connected to that strategy. The only way the dummy broker strategy could have "seen" those positions was as a result of the Schwab strategy running at the same time. Is there some shared memory? The dummy broker strategy never tried to sell these non-existent positions until the Schwab strategy ran along with it today.

I appreciate your taking the time to provide some other suggestions, but this is not a serious issue for me as I do not plan on running the dummy broker for this strategy anymore, now that Schwab is up and running. I just thought you might want to see what I found. I am not able to run Live Positions because it is not compatible with some of my strategies and it has to be enabled globally, not by strategy.

However, here is a scenario that I do plan to run going forward: running four instances of this strategy in the SM, each connected to a different Schwab account. I was planning on running them at the same time but can space the runs out by 5 min if you think that's safer.
0
Cone8
 ( 7.89% )
- ago
#5
Maybe there's something about your WL workspace that I'm not understanding because this shouldn't be news to you.

1. The strategy ran in some tool (like a Streaming window or Strategy monitor) with Schwab selected for the broker, correct?

2. The strategy also ran in some tool (like a Streaming window or Strategy monitor) with the Dummy broker selected for the broker, correct?

There's only a problem if the answer is "no" to 1 or 2.
0
- ago
#6
Both the Schwab and dummy-connected strategies ran in the SM simultaneously on a daily schedule.

I am surprised that the dummy-connected strategy acted as if it had active symbol positions in its designated dummy account that it didn't have but were active in the Schwab account. I'm not understanding how that's possible and why that is expected behavior. Why would a strategy connected to one account detect open positions in another account that it's not connected to.? What am I missing here?
0
Cone8
 ( 7.89% )
- ago
#7
What were the answers to 1 and 2 in Post #5?

If both were "yes", read Post #3 until it "syncs in". Pun intended.
0
- ago
#8
The answer was yes. I provided more detail. I thought it would be clear.

I'm lost. I give up.

I would still appreciate an answer to the practical situation I posted:

I plan to simultaneously run 4 identical instances of the same strategy in the SM, each instance connected to a different Schwab account. Do you see a potential problem with that?

ADDENDUM
One detail I didn't mention is that this strategy is a variation on pair trading, so the symbol in the dataset is not the same as the symbol traded. Further, the strategy pings the broker on each run to figure out what positions are actually live at the broker and tests for buy or sell signals accordingly.

The broker account number is set in BackTestBegin() by parameter and saved as a static variable. The active broker positions are fetched and saved in a static list here as well. Is it possible there is some cross-strategy sharing of static variables when strategies are running at the same time and these static variables have the same names?
0
Cone8
 ( 7.89% )
- ago
#9
QUOTE:
The active broker positions are fetched and saved in a static list here as well.
That's quite a revelation that you saved until now. If you can't troubleshoot your strategy with the code, I definitely cannot without it.

Since you said that you're using the same strategy to trade different accounts, I'd be curious to know how you make a strategy instance aware of a different BrokerAccount. That would be a good place to start.
0
- ago
#10
QUOTE:
That's quite a revelation that you saved until now.

Definitely not intentional. I kept thinking about why I couldn't understand your responses and then it struck me that maybe you were making default assumptions about aspects of my setup, which were important but that I hadn't clarified. One of your comments made me think your response might be consistent with using Positions rather than BrokerPositions for signals and trading, and that might be relevant.

QUOTE:
I'd be curious to know how you make a strategy instance aware of a different BrokerAccount.

I hope this answers your question.:
1. The obvious one is in the SM Strategy Setting I set the Broker and Streaming Provider to the correct broker account.
2. The one you are more likely asking about is I use a custom account parameter to let the strategy know which account it should be using to get account value, cash, and open positions. The account number and the broker account object are instantiated in the BacktestBegin() method. So, I have to make 2 settings, one in the SM standard settings, and one to set my account parameter to the assigned number (1, 2, 3 .......) that corresponds with that account. I have all my account numbers that I auto-trade saved in every strategy, and I use a Switch structure in BacktestBegin() to pick the one that matches the number selected in the custom account Parameter.



0
Cone8
 ( 7.89% )
- ago
#11
1. >> Nothing obvious about that. We're talking about the strategy, and it has access to the broker account setting in only one scenario: S. Monitor (or Streaming Chart), Live Positions enabled, and only it can determine the account selected using Backtester.LiveAccount... but this is not your scenario. On to #2.

2. >> Sure this will work, but it seems you have an error in your code that you need to track down.
0
- ago
#12
QUOTE:
but this is not your scenario

There is a technical reason I couldn't use Live Positions. I think it was because of pair trading.

QUOTE:
Sure this will work, but it seems you have an error in your code that you need to track down.

You don't think this could be a result of my setting the broker object for each strategy in the BackTestBegin() method? Is there no possible sharing of memory locations across strategies.?

In any case, these two type assignments at the class level
CODE:
      private static string activeAcctNum;       private static BrokerAccount brokerAccount;

...should prevent memory sharing from happening since they are private variables, correct? (I'm not even sure what I'm asking could happen in the real C# world.)

ADDENDUM

I just realized both of my twin strategies running in the SM must have the same namespace, unless WL prevents that from happening. Not sure if that could be relevant to this issue.

0

Reply

Bookmark

Sort