I asked for help on more than one occasion and tried these various solutions that did not work:
1. Don't trigger a trade if Historical is true. Based on the strategy and various parameters, historical information is loaded to populate indicators, etc. This can sometimes trigger the OnBarUpdate.
2. Evaluate ToTime(Time[0]) >=093000 to begin trading. Meaning, make sure the timestamp of the bar is greater than you session begin time.
3. (Bars.BarsSinceSession > X) Where X is the number of bars you want to skip.
Many of these solutions seemed to work, but ultimately failed. I finally sat down and debugged several sessions where the problem occurred using the session replay, which is a really great tool. I determined that the cause of the issue was fairly simple. For whatever reason, the first bar of the session, was actually the closing bar of the previous session. Armed with this tid bit, you would think the Historical test would weed this bar out, but not so. In all my tests, Historical was false for the last bar of the previous session. Strange, eh? For obvious reasons, the ToTime evaluation didn't work either. The last bar was tagged with a time of 4 pm which is definitely greater than 9:30 am. Counting bars with the BarsSinceSession didn't work because it includes the 4PM bar in the current session so it is always off by one.
The easy solution is to compare the date of the bar to today's date. Only execute a trade if they are the same.
if (DateTime.Today.ToShortDateString() != Time[0].ToShortDateString())
{
return;
}
Remember this solution will work in real-time trading... which is where it's needed. Comment out this block during backtesting for obvious reasons.
I hope this helps anyone experiencing this very frustrating issue.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Comment