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.


    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 (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 virtual 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 virtual order is not submitted to the broker and is only used to change the strategy position to 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://drive.google.com/file/d/1nXrEz7Rw5C66xiKuuaw0qwju9LaCTeP5/view?usp=sharing

        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 within the OnBarUpdate() method, as the Historical property 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)
        {
            if (Position.MarketPosition == MarketPosition.Long)
                ExitLong();
            if (Position.MarketPosition == MarketPosition.Short)
                ExitShort();
        }
        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; 02-21-2022, 12:00 PM.
        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, 03: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


                  #9
                  Hello Chelsea,

                  I tried adding

                  if (State != State.Realtime)
                  return;

                  in a few places within my code and I'm not getting the desired results. After adding this code my strategy is entering as soon as the strategy is enabled but not waiting for the correct entry parameters to be met.

                  See my attached snippet of code for reference...Now entry 1 is triggering as soon as the strategy is submitted and not waiting to be (close + minticksaway*ticksize < line)

                  Thanks for the help

                  Comment


                    #10
                    Hello mlprice12,

                    Thank you for your note.

                    Skipping historical data will cause your strategy to always start from a flat position. If the trades being taken are not expected, debugging steps should be taken to understand how the script is behaving.

                    It is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

                    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

                    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

                    Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
                    https://ninjatrader.com/support/foru...121#post791121

                    Please let me know if I may further assist
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Brandon,

                      Ninjatrader has to be restarted for the changed strategy code to register correct?

                      Comment


                        #12
                        Hello mlprice12,

                        Thank you for your note.

                        NinjaTrader does not have to be restarted. You would simply compile the script using the Compile button in the NinjaScript Editor window to save changes made to your script. If your script is enabled in the Strategies tab of the Control Center or a chart, you would need to remove the strategy, add it back to the chart, and re-enable it. Or, if your strategy is on a chart you could click on the chart and press F5 to reload NinjaScripts.

                        Please let us know if you have further questions.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          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 virtual 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 virtual order is not submitted to the broker and is only used to change the strategy position to 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://drive.google.com/file/d/1nXrEz7Rw5C66xiKuuaw0qwju9LaCTeP5/view?usp=sharing

                          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 within the OnBarUpdate() method, as the Historical property 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)
                          {
                          if (Position.MarketPosition == MarketPosition.Long)
                          ExitLong();
                          if (Position.MarketPosition == MarketPosition.Short)
                          ExitShort();
                          }
                          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.
                          The link to the video that demonstrates start behavior is flash and does not work.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Christopher_R, Today, 12:29 AM
                          0 responses
                          9 views
                          0 likes
                          Last Post Christopher_R  
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          166 responses
                          2,235 views
                          0 likes
                          Last Post sidlercom80  
                          Started by thread, Yesterday, 11:58 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post thread
                          by thread
                           
                          Started by jclose, Yesterday, 09:37 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post jclose
                          by jclose
                           
                          Started by WeyldFalcon, 08-07-2020, 06:13 AM
                          10 responses
                          1,415 views
                          0 likes
                          Last Post Traderontheroad  
                          Working...
                          X