I have run into an unusual problem where I have a buy stop order being filled earlier than it should be.. to just be brief, this is the print log I made up using a File.AppendAllText() method to show the events:
I'll comment on the block below to explain extra details not evident:
0 Main Candles now at 4pm on 6/27/2012 4:00:00 PM at price 133.18
This is the BarsObject 0, 10minute bars and it prints this line at Time[0].Hour == 16
1 (underlying 1D instrument SPY) fired off at 6/27/2012 4:00:00 PMnewGreen: False newRed: False
This is BarsObject 1, a 1 day interval of same instrument, printing this line on each close and the buystop orders are issued, replaced and canceled from this BarsInProgress event
Sending Entry Order at 133.43 SMA WAS 133.556 133.447 6/27/2012 4:00:00 PM
^sent during BarsInProgress == 1
0 Main Candles now at 4pm on 6/28/2012 4:00:00 PM at price 132.79
EntryOrder Filled at 135.2 6/28/2012 4:00:00 PM
^ Notice that the buy stop order for 133.43 was filled at 4pm on 6/28/2012 while the close (and O, H, L) were all under the 133.48 level. It somehow got filled at 135.20 which is the opening price of the first 10 minute candle on 6/29/2012.
This Order would normally have not filled because the next BarsObject1 event would have canceled it because an SMA turned down
1 (underlying 1D instrument SPY) fired off at 6/28/2012 4:00:00 PMnewGreen: False newRed: False
6/28/2012 4:00:00 PM>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>SMA WAS 133.486 133.556
2 (Daily SP500) fired off at 6/28/2012 4:00:00 PM
So where an order would have been canceled on 6/28/2012 at 4pm because of a downturned SMA, the order was being recorded as filled when BarsObject0 fires off even though the OHLC of that bar index never crossed above the level and it was somehow taking the open from the bar later. I confirmed by loading the CSV of the historical data that the OHLC prices are correct and it's not until the timestamp 20120629 93100 that we get a price above the buystop level
Does anyone have any ideas about why the buystop order is being filled prematurely?
Thank you!
Edit: I just wonder, I think it could be solved if I could reference the value of the 1D SMA of barsobject1 from BarsObject0 - maybe.. the cancel might make it in time to stop the order from existing anymore, assuming that there aren't further complication from the next bar's price being available too early. Can such a thing be done (referencing the indicator value of another barsobject that hasn't fired yet?)
Comment