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

Missed OnExecution

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

    Missed OnExecution

    My strategy has the following code:

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    [snip]
    entryOrder = EnterLongStop(0, true, DefaultQuantity, longFill, signalName);
    [snip]
    }

    protected override void OnExecution(IExecution execution)
    {
    if (entryOrder != null && entryOrder.Token == execution.Order.Token)
    {
    if (entryOrder.Action == Action.Buy)
    {
    stopOrder = ExitLongStop(0, true, DefaultQuantity, stopValue, signalName + "Stop", signalName);
    targetOrder = ExitLongLimit(0, true, DefaultQuantity, targetValue, signalName + "Limit", signalName);
    }
    }

    // Reset our stop order and target orders' IOrder objects after our position is closed.
    if ((stopOrder != null && stopOrder.Token == execution.Order.Token) ||
    (targetOrder != null && targetOrder.Token == execution.Order.Token))
    {
    if (execution.Order.OrderState == OrderState.Filled ||
    execution.Order.OrderState == OrderState.PartFilled)
    {
    stopOrder = null;
    targetOrder = null;
    entryOrder = null;
    }
    }
    }


    If I remember correctly, I took the bulk of this code from the sample code. Basically what I want to do is once I get into a long position, I want to set the target as well as stop prices immediately.

    This code has been working pretty reliably for about 1 month, since I implemented it.

    However, last Thursday night, I found that this code was never triggered. This was trading the DAX on the Eurex. It left my position open and just hanging there and my position had crossed both the target and stop levels.

    The only thing I can think of is that OnExecution was never called, or it came out of order somehow.

    My broker is IB. Is this a possibility? If so, what can I do to prevent this from occurring again? My faith in the reliability of this code is shaken because I expect this to cover all situations and I run it overnight while I sleep. I don't want to wake up again and see it in a massively losing trade.

    Thanks in advance,

    Ken

    #2
    Hello,

    Did you run strategy overnight or keep an order overnight? If so, this is not supported with IB because they reset their servers at night.
    DenNinjaTrader Customer Service

    Comment


      #3
      No, the trade occurred around during regular trading hours for the DAX, around 10am CET.

      Comment


        #4
        kjackson, could have been ignored as you do not check against the inside market if the stopprice is valid before submitting - please check your log file for the data and time in question to see if there's a related entry offering insight into matters.

        Thanks
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TAJTrades, Today, 11:03 AM
        0 responses
        1 view
        0 likes
        Last Post TAJTrades  
        Started by wuannetraam, Today, 02:40 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by jjs12, Today, 10:29 AM
        2 responses
        8 views
        0 likes
        Last Post jjs12
        by jjs12
         
        Started by Ludwik, Today, 03:52 AM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by sdauteuil, 09-23-2021, 10:16 AM
        5 responses
        1,221 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Working...
        X