kazuna8
 ( 35.63% )
- ago
GetPositions() returns the positions for the current symbol.
GetPositionsAllSymbols() returns all the positions for all symbols in the backtest.

How can I get positions for the external symbols for the current symbol?
GetPositionsAllSymbols() returns the positions not only for the external symbols but also other symbols in the backtest.

Examples:
Symbols: SPY, QQQ
External Symbols, UPRO, TQQQ from GetHistory()

Strategy running SPY trades either SPY or UPRO.
Strategy running QQQ trades either QQQ or TQQQ.

Strategy running SPY wants to see neither QQQ nor TQQQ.
Strategy running QQQ wants to see neither SPY nor UPRO.
0
173
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
Use a LINQ query with the custom condition to limit the symbols e.g. GetPositionsAllSymbols().Where(p => p.Symbol != bars.Symbol) and along those lines?
1
Best Answer
kazuna8
 ( 35.63% )
- ago
#2
I wish there was a WL6-like Position where it contains symbols only from the currently running symbol so that it would have made life easier to migrate from WL6 to WL8.
0
kazuna8
 ( 35.63% )
- ago
#3
Thank you for your suggestion.
I came up with a solution like this and it works great.
CODE:
List<Position> GetPositionsLocalSymbols() {    return GetPositionsAllSymbols().Where(p => p.Symbol == Symbol || p.Symbol == Symbol3x).ToList(); }
1

Reply

Bookmark

Sort