- ago
I had a scenario today, where opening short trade couldn't be filled due to slippage. When strategy reversed the position to long, both cover and long trades got placed and filled. Based on FindOpenPosition value, I was expecting the cover order will not be placed since there was no open short position.

CODE:
// Should not execute if no open short position exists if (FindOpenPosition(PositionType.Short) != null) {    PlaceTrade(bars, TransactionType.Cover, OrderType.Limit, bars.Close[idx] * (1 + exitslippage), "Short Exit Strategy 1"); } if (!eod) {    PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx] * (1 + enterslippage), "Long Enter Strategy 1"); }


It looks like FindOpenPosition may be getting set by short PlaceTrade but that order didn't get filled. Also, since that order didn't get filled, it was marked CancelPending status which I had to manually kill it after the next bar.

Question: Does FindOpenPosition value gets set if PlaceTrade is successfully placed or if the order is actually filled and position is open? If it's the former, then what's the best way to check if position is actually open? I'm using WL8 build 3.

Another issue: Since opening short trade didn't get filled due to slippage, I was expecting GetPositions().Count to remain unchanged and was expecting the reverse long position to be the first opening trade. It seems to related to the above issue since FindOpenPosition was not null, the GetPositions().Count also got updated.
0
964
Solved
3 Replies

Reply

Bookmark

Sort
Glitch8
 ( 13.30% )
- ago
#1
The strategy is based on theoretical fills, not actual films. But check out the Portfolio Sync options in Trading Preferences because they can be helpful to keep things in sync.
0
Best Answer
- ago
#2
It would be great if we can get APIs to do basic portfolio checks like:
FindPortfolioOpenPosition(string symbol, int quantity, PositionType)

Then we could use it like this:
CODE:
// Cover trade if theoretical short trade exists and actual short position also exists. // If theoretical or actual short position don't exist then don't cover if (FindOpenPosition(PositionType.Short) != null && FindPortfolioOpenPosition(mySymbol, myQuantity, PositionType.Short) != null) { PlaceTrade(bars, TransactionType.Cover, OrderType.Limit, ...); }
1
Glitch8
 ( 13.30% )
- ago
#3
I like the idea, it would be ideal to post this in a separate topic flagged with #FeatureRequest, and then vote for it yourself too.
0

Reply

Bookmark

Sort