I'm attempting to write code to execute a buy during only the 9:30-10:00 am timeframe subject to DI+/DI- crossover and increasing CMF. I've found all of my compiling errors, but I can't determine why I'm receiving the following Debug and Error Message--"Error processing symbol SPY Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index." My best guess is that I have a logic error in my code. I'm backtesting the code using SPY 1-minute data in June 2009. Any help would be appreciated.
Here's my code:
CODE:
Please log in to see this code.
Size:
Color:
You shouldn't be starting the loop like that:
CODE:
Please log in to see this code.
Because you will be accessing the value of some data series on bar-3:
CODE:
Please log in to see this code.
In addition, your 15-period indicator should have some amount of seed data to stabilize.
Now, if you've tried to access the value at bar-3 and it's bar #1, this will be bar #-2 (=1-3) - which is impossible, as you understand.
Therefore, change the main loop to start at no less than your indicator's period (or
bar-3, whichever is greater):
CODE:
Please log in to see this code.
Size:
Color:
I see the problem; however, if I understand your solution correctly, no trades would be triggered until 9:45 am. Is there a solution that would use pre-market data to solve the problem? I have attempted to do this by changing the main loop as you've suggested but starting the time at 9:15 am.
CODE:
Please log in to see this code.
Unfortunately, the indicators are being calculated using data from the previous day rather than pre-market data.
Size:
Color:
No, changing the time isn't required: only the start of the main loop.
Size:
Color:
Even if I change only the start of the main loop, the indicators are still calculated using data from the previous day rather than pre-market data. Is it possible to use pre-market data? (I've tested this with BGU on 8/12/09 using Active Trader Pro with and w/o pre-market data.)
Size:
Color:
Size:
Color: