- ago
If my strategy is long a position, and I use PlaceOrder to sell the position at market, and then immediately set the resulting transaction's Quantity property to a particular value then WL8 seems to ignore the Quantity property value and always utilizes the Trading preferences settings. I've tried the various combinations of trading preferences "Reduce size of exit order to match position quantity" and "Always set exit order quantity to full position quantity" to no avail.

My requirement is to sell a specific share quantity.

User Cone, in another thread, gave an example, except it was for a buy. Hence, in my code I'm doing the following for the sell:

CODE:
Transaction t = PlaceTrade(bars, TransactionType.Sell, OrderType.Market); t.Quantity = (some_calculated_quantity);

Perhaps I'm overlooking a setting? The issue occurs when running the strategy in the strategy monitor.
0
456
9 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.08% )
- ago
#1
Maybe you have some portfolio sync options enabled in the Trading Preferences, several of these will override the quantity of a sell order based on a broker's position or account size.
0
Glitch8
 ( 12.08% )
- ago
#2
I tried this simple test strategy in the SM, and in this case it's using the quantity of 10 that I assigned to the Transaction object. Maybe see if it works for you here and then we can see what the differences are.

CODE:
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) {          if (idx == bars.Count - 50)             PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          if (idx == bars.Count - 1)          {             Transaction t = PlaceTrade(bars, TransactionType.Sell, OrderType.Market);             t.Quantity = 10;          } } } }


0
- ago
#3
I have tried the various combinations of the Portfolio Sync trading preferences with no impact. The strategy, when run in the strategy monitor, always respects the Portfolio Sync settings and does utilize the Transaction.Quantity property. By the way, I'm using the dummy broker.
0
Glitch8
 ( 12.08% )
- ago
#4
Can you try my sample strategy and see if you are getting the expected sell of 10 quantity?
0
Cone8
 ( 28.25% )
- ago
#5
QUOTE:
I have tried the various combinations of the Portfolio Sync trading preferences with no impact. The strategy, when run in the strategy monitor, always respects the Portfolio Sync settings and does utilize the Transaction.Quantity property.
This is confusing. Did you mean "does not utilize"?

Let's be clear. If you want to use the t.Quantity, Reduce Size... and Always set... Portfolio Sync options should not be selected.
1
- ago
#6
NOTE: for this to work for a BUY, the Strategy Setting "Position Size" should be set to "Fixed Value". If it is set to "Percent of Equity" AND "Basis Price" is set to "Market Open Next Bar" it will not work. It will use the % Equity and show the signal in $$ instead of number of shares. Wasn't sure if this had been noted before.
0
Cone8
 ( 28.25% )
- ago
#7
Actually, it does work for that case too. The Signal will display the $dollar size amount (see Strategy Settings > Basis Price > Important Notes for Market Open Basis), but when you Place the signal with the broker, the share size you set in the strategy will be used - just like in the backtest.

For entry orders (Buy/Short), assigning a Transaction.Quantity in the Strategy always overrides the Position Sizer. It's just that for a Market Open Basis you won't see that size until you place the order with the broker.

For exit orders (Sell/Cover), assigning a Transaction.Quantity in the Strategy can sell any number of shares of the Position, but WealthLab can change the shares based on the .Portfolio Sync preferences when you Stage/Place the order.
0
- ago
#8
Thanks @Cone for the clarification. As you guessed I was relying on the misleading $$ amount for the signal. I didn't try a trade.
0
Cone8
 ( 28.25% )
- ago
#9
misleading?... I know what you mean, but keep in mind that you selected a basis price (tomorrow's open) that doesn't exist in causal reality. The idea of the feature is to give you the amount of cash available for the trade. This is a convenience for trading mutual funds, for example. There's no way to convert dollars into shares for a non-existent price, and that's why the actual basis for shares is always the last close for market orders.
0

Reply

Bookmark

Sort