Buy if 9:30-10:00 Subject to Indicators with Trail
Author: NewDayTrader
Creation Date: 8/13/2009 12:25 PM
profile picture

NewDayTrader

#1
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.


profile picture

Eugene

#2
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.

profile picture

NewDayTrader

#3
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.
profile picture

Eugene

#4
No, changing the time isn't required: only the start of the main loop.
profile picture

NewDayTrader

#5
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.)
profile picture

Eugene

#6
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).