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

Live Strategy Does Not Execute The Same As Sim101

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

    Live Strategy Does Not Execute The Same As Sim101

    Good morning Ninjatrader staff,

    Currently I have the same strategy running both on a Live account and a Sim101 account. The strategy places a TP and SL when a particular order is filled, but sometimes fails to do this on the Live account while it executes perfectly on the Sim101 account. Is there any way to resolve this problem?

    #2
    This is the part of the code that fails to trigger.

    if (S1 != null && S1 == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled)
    {
    TP = ExitShortMIT(0, true, 1, KyoriBands(TwentyFive, Fifty, SeventyFive).Low2[0], "TP", "S1");
    SL = ExitShortStopMarket(0, true, 1, Close[1] + 1 * TickSize, "SL", "S1");
    }
    }

    Comment


      #3
      I have figured out that the error happens only for the first trade that is placed after restarting the strategy and does not occur anymore for every consecutive trade of the same kind. What can I do to prevent this from happening?

      Comment


        #4
        Hi GLFX005, thanks for your question.

        From the code sample it looks like you are not checking for partially filled orders, which can happen on live accounts. You can also better simulate partially filled orders on the Sim101 account by enabling "Enforce Partial Fills" under Tools>Options. We have an example here that uses OnOrderUpdate and OnExecutionUpdate to submit protective orders and it even handles partially filled orders. Please replicate this in your code and let me know if you are still seeing this issue.



        Kind regards,

        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello Chris,

          I don't see how this could cause any issues since I am using only 1 contract to trade with, meaning that partial fills can't occur. The first trade happening after every restart of the strategy always comes back in the Filled order state but fails to trigger the code I have provided above in blue. A possible cause could be that I am using the "if Historical = return;" logic or that there's an issue with S1 remaining null even if the order has been Accepted and Filled. The strange thing is that it only happens Live and never on Sim101, so maybe it's a broker issue? I am connected to Dorman through Ninjatrader Brokerage.

          Comment


            #6
            Hi GLFX005, thank you for clarifying.

            There might be an error message related to the stop order. Please turn on TraceOrders in State.SetDefaults "TraceOrders = true;" and this will print out information about all orders made by the strategy. If the code is actually calling your stop loss order and its not being submitted there should be an error listed in the trace orders.

            I look forward to hearing from you.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by f.saeidi, Today, 12:14 PM
            7 responses
            15 views
            0 likes
            Last Post f.saeidi  
            Started by Russ Moreland, Today, 12:54 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by philmg, Today, 12:55 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by TradeForge, 04-19-2024, 02:09 AM
            2 responses
            32 views
            0 likes
            Last Post TradeForge  
            Started by aprilfool, 12-03-2022, 03:01 PM
            3 responses
            329 views
            0 likes
            Last Post NinjaTrader_Adrian  
            Working...
            X