No announcement yet.

Partner 728x90


How to Reset SIM on NinjaTrader 8? Can't close open position.

  • Filter
  • Time
  • Show
Clear All
new posts

    How to Reset SIM on NinjaTrader 8? Can't close open position.

    This should be an easy one, but I can't figure this out. I was running a strategy in SIM and disabled it to restart another strategy, but it left an orphaned postion open (1L) and an average price kind of hanging, since this is in play still it will not take any further trades on any other strategies. I need to clear this out somehow so I can enable a new strategy and take additional trades in SIM.

    Here is what I have tried so far:

    1. Reset DB
    2. Repair DB
    3. Uninstall / Reinstall.
    4. Change Logged in User (I have a a SIM account and a Lifetime Account) Nothing removes this orphan open position.
    5. I deleted all the files from My documents, as as well as C: Programs prior to the uninstall / reinstall.

    In NinjaTrader 7 there were some other ways to reset SIM, but in 8 I don't see anything like this.

    What am I missing. Please help.


    Hello Ian,

    Are you not able to manually close the orphaned position by manually placing a sell market order with a quantity of 1 to the same account and instrument?

    Having a position with an instrument on an account should not prevent a strategy from being enabled.

    Are you receiving an error message when enabling the script?
    If so, what the full error message?

    You can reset an account in the Edit Account window from the Accounts tab on the Control Center.
    Below is a publicly available link to the help guide.

    However, I'd like to assist you in resolving the issue without resetting the account.
    Chelsea B.NinjaTrader Customer Service


      Hi ChelseaB,

      Thanks for following up with me. I am enclosing an image of what I am seeing.

      Basically, I logon to the live data feed. The connection works, it turns green. I go to enable a strategy (any strategy), and the strategy turns orange, the position shows 1L and the avg price shows 2688. I can click enable and it will show up checked as enabled. The issue is that it won't run. I have tested strategies that just print on every bar update and they won't print, and I am getting a live data feed I can see.

      So what I am trying to do is close the position that is open and essentially reset this.

      I have also tried resetting the SIM by way of Accounts Tab> Edit Account > Reset.

      This didn't work either.

      Any ideas?

      Attached Files


        Hello Ian,

        You are looking at a historical position.

        When a strategy is yellow (or orange on some monitors) in the Strategies tab of the Control Center, this means that the strategy entered a historical (theoretical) position in the historical data that has been loaded.

        It also means that you have "Wait until flat" selected for the 'Start behavior' option in the strategy parameters.

        This means that once the strategy has finished processing the historical data and has transitioned to real-time, it will wait until there is a real-time order submission that will cause the strategy to become flat. This also includes changing from a long position to a short position or vice versa as the position would pass through flat.

        This also applies to secondary instruments if there are added series to the script. All positions must be flat before real-time orders will begin.

        Below is a link to a video I've recorded that demonstrates startup behavior.

        A link to the help guide on the strategy parameters.

        As well as a link to the start behavior options.

        To change the behavior here, you have a couple of options.

        You can change the start behavior to "Immediately submit" in the parameters of the strategy. This means that if in the historical data the strategy submitted an order to enter a long position, once the strategy has transitioned to processing real-time data it will use this long position as the live position (and will not wait to become flat first). Any working orders that are still in a working state when the strategy transitions from historical to live (such as protective stop losses and profit targets) it will submit as live orders when the strategy is started.

        The start behavior can also be set in the State.SetDefaults of the script to default to a particular selection.

        You could also modify your script so that it only places orders if the data is real-time data. To do this you will need to edit the code of your script directly, as the Historical property is not available to the Strategy Builder.

        The code needed would be some thing like:
        if (State != State.Realtime)
        This condition checks to see if the script is not processing real-time data (meaning it is processing historical data) and if true will stop any code appearing after it in the same method from evaluating.

        This can also be written as:
        if (State == State.Historical)
        This checks to see if the script is processing historical data and will stop processing if true (which is the same condition and action as above).
        If this logic is placed at the beginning of OnBarUpdate, the strategy will not process until it reaches real-time data and will not calculate historically.
        If this is placed in the conditions for making an order, it will prevent the order from being placed until the strategy reaches real-time data.

        You could also optionally trigger any open position to exit with an exit market order on the last historical bar.

        To find the last historical bar:
        if (State == State.Historical && CurrentBar == Count - 2)
            if (Position.MarketPosition == MarketPosition.Long)
            if (Position.MarketPosition == MarketPosition.Short)
        Below is a link to the help guide on the 'State' NinjaScript property.

        As a heads up, I do not recommend changing the Start behavior or Account of a strategy instance after it has been enabled. Instead, add a new instance with the that start behavior and account selected.

        Also, I do not recommend changing the Account selected for a strategy after it has placed a real-time order. Changing the account will likely cause the strategy to be unable to start with an error such as 'Unable to cancel out live orders' as the strategy start behavior attempts to find and cancel previously placed orders that do not match.
        Last edited by NinjaTrader_ChelseaB; 05-07-2020, 03:05 PM.
        Chelsea B.NinjaTrader Customer Service



          Thanks for the information. I was able to get it working again by just changing the start up behavior as you described.




            Just out of curiosity, is there any way to avoid having it try to put my into a historical position right off the bat in SIM?

            Why is it doing this in the first place?

            After getting it to run for a while it throws an error: "The historical order has turned into a live order, so the strategy will be disabled."

            This effectively prevents it from doing anything further. Outside of adjusting my code as you mentioned to only trade live orders not historical, is there anything that can be done to prevent this behavior every time I start up SIM live?

            Last edited by iantg; 12-26-2017, 03:13 PM.


              Hello Ian,

              Is the suggestion I made in post #4 to use if (Historical) return; not working as expected?

              Scripts process historical data before processing real-time data.

              If you allow orders to be placed in historical data, this will make a historical position.. If you do not allow historical orders, then there will be no orders to make a historical position.
              Chelsea B.NinjaTrader Customer Service



                I haven't tried that yet, but I suppose that should take care of the issue.

                I will get it a try later and report back if I have any issues.




                Latest Posts


                Topics Statistics Last Post
                Started by soon123, Today, 08:16 PM
                0 responses
                Last Post soon123
                by soon123
                Started by brownsfan019, Today, 07:56 PM
                0 responses
                Last Post brownsfan019  
                Started by Grantx, 01-25-2017, 07:15 AM
                4 responses
                Last Post Adfra
                by Adfra
                Started by mv075sn, Today, 03:42 PM
                2 responses
                Last Post mv075sn
                by mv075sn
                Started by vantojo, Today, 03:06 PM
                4 responses
                Last Post vantojo
                by vantojo