I'm running a backtest on a 100+ symbols, and I want to limit the number of open positions at any one time to 5 or less. Unfortunately, ActivePositions.Count is always 0. What am I doing wrong? Thanks...
CODE:
Please log in to see this code.
Size:
Color:
CODE:
Please log in to see this code.
Size:
Color:
I'm not getting this. Now I'm getting 100's of these errors:
Error processing symbol SPY Bar number must be 609 or greater
Error processing symbol SSG Bar number must be 492 or greater
Error processing symbol SSO Bar number must be 243 or greater
.
.
.
It's taking some trades but not many. I'm not getting the concept. I thought WL produces each trade for each symbol first and then runs the portfolio simulation to decide which trades it can take. I thought the WL code is on the symbol level, but now I'm throwing in code on a portfolio level. I'm confused. When I said I wanted to limit the number of open positions at any one time to 5 or less, I meant 5 different symbols at once.
Size:
Color:
QUOTE:
I meant 5 different symbols at once.
Currently (without PosSizers) you'd have to create a Portfolio-level backtest in your code, in other words using a
DataSetSymbols loop. You run those types of backtests by clicking only one symbol (not selecting the DataSet name). Some examples are the "Symbol Rotation" strategies and "Dogs of the Dow".
Size:
Color:
QUOTE:
Error processing symbol SPY Bar number must be 609 or greater
That could be due to some other part of your code (which we need to look at).
QUOTE:
When I said I wanted to limit the number of open positions at any one time to 5 or less, I meant 5 different symbols at once.
Now I see, what you
mean and what was
said are absolutely different things. :) The code above was illustrating how to limit the number of active positions.
QUOTE:
I thought the WL code is on the symbol level, but now I'm throwing in code on a portfolio level.
If I got your point then one way or another, you can count the number of unique symbols that had trades:
CODE:
Please log in to see this code.
Size:
Color:
Eugene, I think Jim's probably running a single-position script (uses IsLastPositionActive), but wants to limit the portfolio to 5 open positions. If that's the case, this code isn't going to help... But, if he implements the strategy as I suggested, the KillDupes and ActiveSymbols routines could be useful there.
Size:
Color: