- ago
With my ongoing testing /development of an option strategy to open / close option positions based on an underlying signal, I have reverted to letting WL do the heavy lifting. While I am not (can't) use the Live Positions trading option with external symbols, I am also not (in the latest code version) checking the broker position quantity on exit.

Running in the SM, the setting for sizing to % equity is working fine for setting the quantity for opening a position, but I noticed that for exiting, it doesn't automatically sync with the broker quantity size (even though the backtest positions have the broker quantity). Instead it uses the "Starting Equity" in the settings as the sizing equity, not the broker equity.

The simple code approach I am using is

CODE:
         else //position is open          {             if (smoother.CrossesUnder(smoother2, _index))             {                WriteToDebugLog(bars.DateTimes[idx] + " Signal to Close " + _pos.Symbol);                ClosePosition(_pos, OrderType.Market, 0, "Sell At Market");             }          }    

...where _pos is the option position. Do I have to query the broker to get the actual quantity and then use a constuction like this instead? Or should WL be using the broker equity for closing position quantity as well, when "Use Broker Account Value" option is selected in Trading Preferences?

CODE:
transaction t = Place Trade(obars, .........) t..Quantity = brokerQuantity
0
155
11 Replies

Reply

Bookmark

Sort
Cone8
 ( 25.44% )
- ago
#1
It will sync with the size of the position as long as you have that Portfolio Sync Trading Preference selected.

Here's a test (because you made me doubt it):
I started with $5000 size which bought 23 contracts. Then before it sold, I changed the Position Size to $6,100. The signal was to sell 29 contracts, but it was sync'd to the 23-contract size in the broker account.



0
- ago
#2
QUOTE:
It will sync with the size of the position as long as you have that Portfolio Sync Trading Preference selected.


Are you referring the "Always set Exit Order Quantity..." checkbox preference? I do not have this checked because I have an active automated strategy that partially exits positions based on an allocation signal. In that case, do I have to manage by myself as I described above?

These preferences are very helpful, but it would be additionally helpful if some of them could be applied by strategy, not globally.

0
Cone8
 ( 25.44% )
- ago
#3
Okay, let's go back...
QUOTE:
Instead it uses the "Starting Equity" in the settings as the sizing equity, not the broker equity.
Did you enable the Trading Preference to use the broker account value?
0
- ago
#4
Yes. Entry works fine.
0
- ago
#5
I shouldn't have used the term "Broker Equity," which is only for entry sizing. It's not relevant for exit; only the broker quantity is. Maybe I've answered my own question.
0
Cone8
 ( 25.44% )
- ago
#6
Now I see. If you're using Broker Equity to size the position, you'll have to use Portfolio Sync to get the right size for the exit. Because later, it's a just hypothetical Backtester position that uses the equity curve based on the Starting Equity size of the control.

We'll have to think about it. Maybe we can "recall" the size of an Auto-Traded position. And maybe that just opens another can of worms.
0
Cone8
 ( 25.44% )
- ago
#7
Thought about it, and no, this won't work because it assumes you'd never shut down WealthLab after trading into a position.
The only way to sync an exit to the size in the account is to use the feature for that purpose.
0
- ago
#8
QUOTE:
Because later, it's a just hypothetical Backtester position that uses the equity curve based on the Starting Equity size of the control.

Yes, that's the conclusion I came to when I thought further about it. The hybrid nature of this strategy (backtest positions shifting to live positions on last day / bar) has been a little tricky to implement with a few surprises, all of which look like they can be addressed.

QUOTE:
Now I see. If you're using Broker Equity to size the position, you'll have to use Portfolio Sync to get the right size for the exit.

By "Portfolio Sync" do you mean enabling Live Positions trading preference? I can't do this because it is an external option symbol on an underlying (which is in the dataset).

QUOTE:
The only way to sync an exit to the size in the account is to use the feature for that purpose.

Which feature? I can query the broker positions, store in a list and query this list in place of an OpenPositions list to see if there is a live position for the underlying. Also, the Quantity property is available for Broker Positions, so once I have it, I can find how quantity I need to sell to close the position. This requires a separate method / logic for handling live positions vs. backtest positions.

Fortunately, I know how to do this with current WL capabilities and code examples you have previously shared. I wanted to confirm that this special handling is necessary, and you have confirmed it. Thank you.
0
Cone8
 ( 25.44% )
- ago
#9
This one -

0
- ago
#10
Post #2 explains why I can't set this feature, at least until it can be set by strategy instead of globally.

If I were to use this feature and modify the code in my strategy that reduces allocation to set t.Quantity, would it override this feature?
0
Cone8
 ( 25.44% )
- ago
#11
Yes, if you assign Transaction.Quantity in a script or a manual order, then that will be the order quantity for shares/contracts.
0

Reply

Bookmark

Sort