• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

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

Collapse
X
 
  • 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.

    Ian

    #2
    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.
    https://ninjatrader.com/support/help...TheAccountsTab

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

    Comment


      #3
      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?

      Ian
      Attached Files

      Comment


        #4
        Hello Ian,

        You are looking at a historical position.

        When a strategy is yellow 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.
        https://www.screencast.com/t/D2GRrGe5MfzJ

        A link to the help guide on the strategy parameters.
        http://ninjatrader.com/support/helpG...tegyProperties

        As well as a link to the start behavior options.
        http://ninjatrader.com/support/helpG..._positions.htm

        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.
        http://ninjatrader.com/support/helpG...ediatelySubmit

        The start behavior can also be set in the State.SetDefaults of the script to default to a particular selection.
        http://ninjatrader.com/support/helpG...rtbehavior.htm

        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 public variable is not available to the Strategy Builder.

        The code needed would be some thing like:
        Code:
        if (State != State.Realtime)
        return;
        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:
        Code:
        if (State == State.Historical)
        return;
        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:
        Code:
        if (State == State.Historical && CurrentBar == Count — 2)
        Below is a link to the help guide on the 'State' NinjaScript property.
        http://ninjatrader.com/support/helpG...n-us/state.htm


        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-09-2019, 07:20 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,

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

          Thanks,

          Ian

          Comment


            #6
            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?

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

            Comment


              #7
              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

              Comment


                #8
                Chelsea,

                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.

                Thanks,

                Ian

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Erhard, Today, 04:24 AM
                2 responses
                17 views
                0 likes
                Last Post Erhard
                by Erhard
                 
                Started by rontronimous, Yesterday, 05:55 PM
                2 responses
                20 views
                0 likes
                Last Post rontronimous  
                Started by brunoviveiros, Today, 04:26 AM
                0 responses
                3 views
                0 likes
                Last Post brunoviveiros  
                Started by StevenNelson, 11-19-2019, 05:39 AM
                3 responses
                22 views
                0 likes
                Last Post brucerobinson  
                Started by guidoisot, Today, 03:01 AM
                0 responses
                8 views
                0 likes
                Last Post guidoisot  
                Working...
                X