Cone8
 ( 6.32% )
- ago
Bring back SplitPosition!

CODE:
Position SplitPosition(Position position, double percentToRetain);


Careful attention should be taken not to repeat its pre-Version 7 bugs:

1. Having split a Position into two with SplitPosition, the following properties incorrectly report 0 or NaN for the first part of the splitted Position if Strategy is run in a Portfolio Simulation mode: MFEAsOfBarPercent, MFEAsOfBar, MAEAsOfBarPercent, MAEAsOfBar, NetProfitAsOfBarPercent, NetProfitAsOfBar.
Partial workaround: Switch to a Raw Profit position sizing mode.

2. Portfolio Simulation Mode, expect that either all or none of the Positions resulting from SplitPosition will be rejected according to the amount of cash available on the entry bar. While building the equity curve, Wealth-Lab treats each split Position as a separate Position competing for cash, and, if Position.Priority is random each Position has a random chance of being selected or rejected in a high-exposure MSB Portfolio Simulation.
Partial workaround: To help reduce the frequency (but in no way guarantee) of taking different actions for split Positions, assign the same Priority to the new split Position as the original after calling SplitPosition.
6
940
Solved
1 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.10% )
- ago
#1
Just completed a really elegant code change for this feature. No more SplitPosition! To sell a part of a position, all you need to do is assign the amount you want to sell to the Transaction.Quantity.

This works both ways, selling a portion of an open position will split the Position into two automatically. If you specify more quantity than a single open Position has, you can close multiple open Positions with one PlaceTrade. If you assign a value like Double.MaxValue to Transaction.Quantity you can effectively sell all open Positions at once.
0
Best Answer

Reply

Bookmark

Sort