I have read the posts on ActivePositions and have a follow up question on use of Active Positions within a strategy.
I have a simple RSI strategy that generates a buy signal when the RSI series pass up (crossover) through a lower threshold and generates a sell signal when the RSI series passes above an upper threshold.
I am trading a single symbol and limiting the number of positions through the Percent of Equity option in the Portfolio Simulation Mode. In this case, the limit is 20%.
I decided to extend the strategy by including a "circuit breaker" if an open position should incur a loss of a certain magnitude (param) for a certain number of days (param). In order to implement this circuit breaker I added the following code (somewhat simplified for clarity):
CODE:
Please log in to see this code.
So, if circuiteBreaker = true, I exit all positions immediately:
CODE:
Please log in to see this code.
What I found when testing this code is that the list of trades in ActivePositions not only includes the positions that were generated from signals that were accepted and executed for the portfolio, but also includes a position for every buy signal for potential transactions that were rejected because of portfolio capital limitations.
Thus, when looping through the ActivePositions to determine if a circuit breaker is warranted, I was testing the profitability of positions that were never actually executed. I found this when looking at the backtest results and saw that the circuit breaker had triggered an exit when all the active transactions were profitable. So, I printed the active transactions prior to the exit and found far more active transactions in ActivePositions than there should have been.
Is this a bug or am I misusing the ActivePositions collection?
If I am misusing ActivePositions collection, how should I be evaluating positions that have actually been accepted and executed (allowing for capital limitations)
Thanks,
- Kevin