Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Historical data & order object events firing out of expected order

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Historical data & order object events firing out of expected order

    Hi,

    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?)
    Last edited by RunnrX; 08-24-2016, 11:23 AM. Reason: adding extra note at end about speculative solution

    #2
    Hello RunnrX,

    Thank you for your patience.

    The behavior you detail would not be expected. Can you provide screenshots of the executions on the charts and the Daily and 10 minute charts? If possible can you include the strategy or a toy version that reproduces the behavior?

    Historically you can reference a bar ahead by calling the barsAgo index with a negative value. For example:
    Code:
    SMA(BarsArray[1], 20)[-1]
    This would reference one bar ahead of the current closed bar for BarsArray[1].

    Comment


      #3
      I've.. typed my reply a couple of times and I keep losing the message I'm trying to post because of login timeouts.. but it was meaning to say thank you for your idea, I think that will make a good situational patch for the issue. I can't show a toy/example/screenshot because the code is a bit of a complex beast and I'm not allowed to share its workings unfortunately... but if I see a way to fix this more thoroughly I'll come back here to update what happened. Thanks!

      Comment


        #4
        Hello RunnrX,

        Thank you for your response.

        Can you provide screenshots of the executions on the charts and the Daily and 10 minute charts?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Waxavi, Today, 02:10 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Waxavi, Today, 02:00 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by alifarahani, Today, 09:40 AM
        5 responses
        23 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X