- 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
53
5 Answers

Reply

Bookmark

Sort
- 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
- 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
- ago
#4
Can you try my sample strategy and see if you are getting the expected sell of 10 quantity?
0
Cone7
- 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

Reply

Bookmark

Sort