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

which StartBehavior option to use

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

    which StartBehavior option to use

    Hi,

    From reading the help guide , I am still confused about which option to choose for the startbehavior. Here is a scenario/use case that I do every time I start to trade.

    My account position is flat. I do not have active positions when I start to trade at the beginning of the day because I don't keep anything overnight.
    What I want is that once the strategy is enabled, the strategy will:

    - if strategy position is not flat, I do not want the strategy to place a market/limit order so that my account position and strategy position to be synced. (So it should rule out all the synchronizing start behaviors)
    - if the strategy position is not flat, I want it to think that it's flat. So that it will place order when there is a Next entry that fits the conditions. (So this should rule out all the wait start behaviors because I do not want to wait to flat)
    - if strategy position is flat, then it's good. Everything is synced so this works as normal.

    So with this, I have 2 options left: "immediately submit" and "adopt account position" . I don't know which one to use because I don't understand the difference of these two options. Can you help highlight the differences of these two?
    Last edited by affilife; 02-26-2024, 04:09 PM.

    #2
    Hello affilife,

    using the default of wait until flat should be fine for that situation as long as your strategy is programmed to exit positions before the end of the session or uses exit on session close. If your strategies logic allows for entries to be placed after a pre determined exit or the seconds you set for exit on session close it could end up waiting. This also depends on how far into the current trading session you enable the strategy, if you enable it later into the session that gives your logic time to evaluate historical trades for the current session, starting the strategy at the session start would be recommended if you want to use wait until flat.

    The other options you need to carefully read the descriptions of and make sure your strategy and specific use case work with that behavior. The default is the safest option as that will not send orders to the account based on how the strategy evaluates until it is in sync with the account in realtime.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse. However, I try not to wait because sometimes there is a match for entry criteria, but I have a virtual strategy position open so it won't do anything until it's flat.

      Based on what written in the first sentence in adopt account position in the help guide you provided,
      This setting should be used if you would like your strategy to disregard the historical virtual Strategy Position and to start in the same position as the real-world Account Position.
      This would be my option because it's disregard historical virtual position and start in the position as the real-world account position (in my case, it's flat and I do want strategy position to be flat right after enabled). However, what confuses me is this part just a few line below the first quote
      Any remaining active strategy orders that cannot be successfully paired will be submitted live and the strategy will then try to sync your Account Position to your Strategy Position.
      Why is it trying to sync Account Position to Strategy Position? It's conflicting with the first quote. The first one says sync Strategy position to real-world Account Position. Which one is correct here?

      Comment


        #4
        Hello affilife,

        That may work for you however you need to carefully read all the steps that adopt account position does to make sure that works for your goals.

        If your account is flat and you want the strategy to be flat after enabled you need to make sure it exits positions before the end of the trading session. As long as it did not enter a position before the next session then it will be flat. It would only not be flat if you enable it after it should have entered a position in realtime, it will evaluate that as a historical trade at that point. You can also add a condition to check if the State is realtime if you only want the strategy to work in realtime and prevent it from historically trading.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse. So how do I check if there is an active virtual historical position open once we are in either Transition state or Realtime state?

          And I don't want to prevent it from historically trading because I run backtest with Strategy Analyzer. So I need to identify if there is an open historical Position, then close it before jumping into realtimetime
          Last edited by affilife; 02-26-2024, 05:01 PM.

          Comment


            #6
            Would something like this work? Will this exit all historical open position before going into realtime trading? Will this affect my backtest from strategy analyzer? I think it would not because it should never reach State.Transition in backtest. Am I correct? Can you confirm?
            Code:
            else if (State == State.Transition)
            {
                 if (Position.MarketPosition == MarketPosition.Long)
                     ExitLong();
                 else if (Position.MarketPosition == MarketPosition.Short)
                     ExitShort();
            }​

            Comment


              #7
              Hello affilife,

              To make sure it is not in a position you would use OnBarUpdate and exit the position before the session close or if you have ExitOnSessionClose being used you would just need to ensure your entry conditions do not happen again after that point.

              Making sure its flat in the current session would be more difficult, that depends on what conditions you have and when they become true during the session. The best way to approach this would be to either make sure you are applying the strategy before that point in time during the session or allow the orders to happen and see what triggered your entry condition and then use logic to prevent that from happening. You can find the last historical bar by checking for State.Historical and also using CurrentBar == Count - 2
              JesseNinjaTrader Customer Service

              Comment


                #8
                Can you explain why my approach as mentioned in the previous post does not work?

                Comment


                  #9
                  Hello affilife,

                  To close historical positions you need to do that during historical bars before the strategy transitions into realtime so it is flat when transitioning into realtime. If a position is open when it transitions the start behavior will see that and wait until the conditions to close that position happen in realtime.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jesse View Post
                    Hello affilife,

                    To make sure it is not in a position you would use OnBarUpdate and exit the position before the session close or if you have ExitOnSessionClose being used you would just need to ensure your entry conditions do not happen again after that point.

                    Making sure its flat in the current session would be more difficult, that depends on what conditions you have and when they become true during the session. The best way to approach this would be to either make sure you are applying the strategy before that point in time during the session or allow the orders to happen and see what triggered your entry condition and then use logic to prevent that from happening. You can find the last historical bar by checking for State.Historical and also using CurrentBar == Count - 2
                    What's Count in your post?

                    Comment


                      #11
                      Hello affilife,

                      Count is the number of bars, -2 would get you the last closed bars index for the series. Checking if the CurrentBar which is the bar being processed is equal to Count - 2 would let you know the bar being processed is the last bar in the dataset.
                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Segwin, 05-07-2018, 02:15 PM
                      14 responses
                      1,789 views
                      0 likes
                      Last Post aligator  
                      Started by Jimmyk, 01-26-2018, 05:19 AM
                      6 responses
                      837 views
                      0 likes
                      Last Post emuns
                      by emuns
                       
                      Started by jxs_xrj, 01-12-2020, 09:49 AM
                      6 responses
                      3,293 views
                      1 like
                      Last Post jgualdronc  
                      Started by Touch-Ups, Today, 10:36 AM
                      0 responses
                      13 views
                      0 likes
                      Last Post Touch-Ups  
                      Started by geddyisodin, 04-25-2024, 05:20 AM
                      11 responses
                      63 views
                      0 likes
                      Last Post halgo_boulder  
                      Working...
                      X