I am coding a strategy that buys and sells amounts that are calculated on the fly and at bars that are determined on the fly. For example, add $D1 to the position on one bar, sell $D2 from the position on a later bar, and buy/add $D3 on yet a later bar. The amounts and bars are calculated by my strategy.
From the documentation, it seems that I need to use SetShareSize() and WealthScript Override (SetShareSize). However, I found
this post.
That post does not use SetShareSize(). I assume this is because that post is using a constant transaction size, correct?
How do we handle selling shares that do not map directly to positions? The wealth-lab code I have written to-date all assumes that I open and close positions completely, e.g. buy N shares (open the position) and then later sell all shares (close the position). But now I want to buy N shares one day, buy M shares another day, and later sell an arbitrary number of shares. So the shares that I am selling could be part of one of the positions or could cut across multiple positions, if each purchase equates to a distinct position. How to do this in Wealth-Lab? When I go to sell N shares out of the various positions that I had previously opened for the symbol, which particular position do I sell from? Do I need to write code to calculate how much to sell from various positions or is there a way to do this directly in Wealth-Lab?
Thanks.
Ron