In build 41 video you explained how to close part of an open position by assigning value to 'exit' transaction, but I couldn't apply the logic.
in below example, I bought 1000 shares by setting transaction quantity. Then I want to sell only 100 shares. can you point me to an example or show me how to to do that?
in below example, I bought 1000 shares by setting transaction quantity. Then I want to sell only 100 shares. can you point me to an example or show me how to to do that?
CODE:
if (!HasOpenPosition(bars, PositionType.Long)) { Transaction trans= PlaceTrade(bars, TransactionType.Buy, OrderType.Market); trans.Quantity = 1000; } else { // Sell 10% of open position. }
Rename
I tried to do this:
but it generated 10 positions for each one I opened.
CODE:
ClosePosition(LastOpenPosition, OrderType.Market); if(Backtester.TransactionLog.Count > 0) { Backtester.TransactionLog[Backtester.TransactionLog.Count - 1].Quantity = 100; }
but it generated 10 positions for each one I opened.
Wealth-Lab creates open positions in the past automatically when a position is split by selling a part of it. This is by design.
You can do it like that or for example, by splitting the last position (in a single position scenario) like this:
You can do it like that or for example, by splitting the last position (in a single position scenario) like this:
CODE:
PlaceTrade(bars, TransactionType.Sell, OrderType.Market).Quantity = LastPosition.Quantity * 0.10;
Thank you. Your suggestion is much cleaner than my code.
Your Response
Post
Edit Post
Login is required