Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Checking how NT handles orders with options set as I have them

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

    Checking how NT handles orders with options set as I have them

    I want to make sure that I understand the options for running Strategies correctly and that I've selected the ones that handle connection loss and re-connection the way I want.

    In my NinjaScripts, I'm using the methods such as EnterLong(), ExitLong(), EnterLongLimit() etc. This is the Managed approach, correct me if I'm wrong. In the Options dialog, I have set the Strategies NinjaScript tab, I chose

    - 'Wait until flat before executing live' in the 'On Starting' panel

    - false for 'Cancel entry orders when strategy disabled' in 'Order Handling'

    - false for 'Cancel exit orders when strategy disabled' - 'Recalculate' for 'On Connection Loss - Handling'

    - when loading the Strategy, I set the 'Sync account position' to false.

    Please can you correct me if I'm wrong, but this is what I want (and assume) to be the case with this configuration:

    (1) if my account is flat, no strategies are running, and I have deleted all existing orders, then when I start up a strategy, the strategy will not fire any exit orders for positions that would have been in place from beforehand.

    (2) if my account is not flat because a strategy has a position on, but I had to reboot my PC or some such situation, I restart my strategy and delete orders and flatten positions (or leave them) appropriately so the account is where it should be in accordance with the strategy, i.e. I manuallly manage the trading until the strategy goes flat.

    (3) because I use 'recalculate' for connection loss handling, when the strategies are interrupted and then reconnected automatically, with this config, the trading will resume according to plan with some execution price 'slippage' caused by the connection loss under some circumstances.

    I have run strategies for 2 days, changing the settings as I learn what they really mean - or what I think they mean. In the Help, there is a section on the 'Sync account position' property which states:

    Enables or disables an automatic attempt to sync the account position and strategy position. (!!! more info needed)
    Is there any more information on this now?

    Thanks
    Last edited by adamus; 05-21-2010, 09:21 AM.

    #2
    1. Correct. Your strategy will be placing virtual trades until it reaches/crosses a flat state before placing any real trades.

    2. When using WaitUntilFlat when you start up the strategy again it doesn't care what you have in your account. It will not make any live/real trades until the strategy crosses a flat state. If you have an open position you will need to manage that yourself and ensure you reach a flat state on your account by the time the strategy switches to placing live trades.

    3. Recalculate is the same thing as starting the strategy completely over. You will then be reinitiating your WaitUntilFlat logic and any prior trades would not be continued except on a virtual basis till you cross a flat state. If you want to keep running as nothing happened you would use KeepRunning.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      OK regarding (3) from what you say, I don't want 'Recalculate'.

      If I set it to KeepRunning, there are a couple of things that I'm not sure about:

      (a) what happens if the bar ends and a new one starts while disconnected?

      (b) what happens to the data that needs to be collected while disconnected? Does NT pick it up on reconnection? Otherwise there will be holes in the data history, not good for backtesting or charting.

      Thanks

      Comment


        #4
        It continues right where it reconnects. There will be no reloading of missing data. It picks up where it left off right away. Any signals that may be different due to missing data will happen.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          For backtesting and charting, I aim to keep as complete a history as possible of the instruments I follow.

          What do I have to do then to make sure that any data which is missed during disconnections eventually gets collected?

          If I called up a minute bar chart of all my instruments, would that do it? Or is there a simpler way?

          Also re: the last point of my first post: is there any more information available about the 'Sync account position' property?

          Thanks

          Comment


            #6
            adamus,

            If you want to reload your data just force a reload in the Historical Data Manager Reload tab. It will reload the data of any active instruments you have in any UI.

            Sync account position matches your account position to your strategy position on start up. If you are using WaitUntilFlat that means it will flatten your account position right as your strategy starts. Then WaitUntilFlat will wait for a flat state and then everything will be in sync for live/real trading at that point forward.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Strategies stay yellow too long, should have turned green by now

              Originally posted by NinjaTrader_Josh View Post
              1. Correct. Your strategy will be placing virtual trades until it reaches/crosses a flat state before placing any real trades.

              2. When using WaitUntilFlat when you start up the strategy again it doesn't care what you have in your account. It will not make any live/real trades until the strategy crosses a flat state. If you have an open position you will need to manage that yourself and ensure you reach a flat state on your account by the time the strategy switches to placing live trades.
              As far as I can see, NinjaTrader is not displaying this behaviour on 3 of my strategies.

              I have set the strategies to false for 'sync account position' and my options are configured to 'wait until flat', no cancelling of entries or exits, and handling is set to 'Keep Running'.

              My account was flat when I started up at around 15:00 GMT+0, and several of them were color coded with yellow to signify that they were waiting to go flat, including a couple should have been flat according to the performance report.

              The strategies are operating on hourly bars and at 16:00, some of the strategies that were yellow did in fact turn green and start trading, but I still have 3 that are yellow. One of these should be flat but in fact at 16:00 it opened a virtual position I can see in the performance report, so at this rate it might stay suspended until tomorrow.

              Are there any more configuration options that I should pay attention to which might alter this behaviour?

              Thanks

              Comment


                #8
                When you set sync to false for sure it would not cancel any of your orders. Only when sync is set to true would NT actually try anything to reconcile your account position to match your strategy position.

                Yellow lit strategies means they have not reached/crossed a flat strategy position state yet.

                Starting with a flat account position and no working orders is all you need to do when you are using WaitUntilFlat. It will start trading when the strategy position reaches a trading state.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  What I mean is, these strategies that are marked yellow should be good to go. There was no position on, they were flat. I don't understand why they didn't go green straight off from the moment I activated them.

                  I'm looking at the performance historically and I can see there were no positions on virtually.

                  Comment


                    #10
                    adamus,

                    There is a distinction between a flat account position and a flat strategy position. When the strategy is in a yellow state it means the strategy position is not in a flat state. The strategy does not care what your account position is. It only cares what the strategy position is in determining if it is in a yellow state or a green state.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Josh,

                      that is clear.

                      What is not clear is why the strategies that should be flat are not flat. When I check the historical performance for executions to see what it's doing, it shows that it's flat. Yet it's yellow.

                      I too am clear that the actual account at IB is irrelevant. I take care of that manually if necessary.

                      Comment


                        #12
                        adamus,

                        What you can do to check what the current strategy position is to just add a print out into your OnBarUpdate() of Position.MarketPosition and then you will know what direction you are in. You can print Position.Quantity to see what size the strategy position has.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          I just added the print statement to debug this.

                          It was coming up to 14:00 when the bar would update.

                          I compiled the ninjascript for the strategy and then the strategy in the control center, and re-activated it. That is necessary, isn't it? I assume so because otherwise the control center doesn't pick up newly compiled code automatically, does it?

                          Anyway, the strategy was flat but on re-activation, it turned yellow and I can see that it decided that it was in fact long because it shows a virtual entry execution in the real-time performance window and then when the bar updated, the Print statement output 'long'.

                          So what's going on?

                          Is this natural variation in the calculations for the strategy - perhaps it calculates its current position on such a short history that differences in start date change its trade history. Does that sound logical?

                          Have you had any other comments from users about this?

                          I'm using moving averages and standard deviations on rolling 20 bar periods so I guess this could be it.

                          However this 'Maximum bars look back' property has only 2 settings - currently TwoHundredAndFiftySix - and the only other option is 'Infinite'. To me 'Infinite' implies it's going to run all the history it can through the strategy before it starts. Is that right?

                          Comment


                            #14
                            adamus,

                            Yes, for code changes you will need to readd a new instance of your strategy before starting it up again. Otherwise code changes may not propegate all the way through.

                            If your strategy is saying it is long then that is why the strategy is yellow. What you should try and do in your code is isolate where the long order is originating from. You can use Print()s in OnOrderUpdate() along with TraceOrders to better isolate the trades so you can understand what is submitted and why by the strategy.

                            256 vs infinite just determines how many historical bars are available for calculations. If you are using 256 which is suitable for most cases it will save you a lot of memory by not needing to hold onto values older than 256 bars. Otherwise if you have a need to access information older than 256 bars at any point in time then you will need to use Infinite.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks for the info.

                              NT has not loaded 256 hourly bars into the HDM though. There are only 30 bars of data there. Shouldn't there be a way to force it to load up 256 bars to start with?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              628 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              361 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              564 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X