Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Starting strategy still excutes order immediately

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

    Starting strategy still excutes order immediately

    Dear all,

    I have a problem with starting my two strategies which are 15 minutes bars, updated on close of bar, based on European (Dutch) index futures (08:00-22:00 GMT+1). One strategy for buy's and one for sell's. The session template is set on Default 24/7.

    When the day starts at 08:00 sometimes orders are still executed immediately while I have all settings placed not do do so (wait until flat, sync false if there are no positions). Furthermore I have a statement in my code that there may be no trading activity at the first bar of a session (Bars.FirstBarOfSession == false) as well a extra safety that orders are not placed based on the close of the last bar of the previous session by setting that orders are only placed after the first bar and before the last of a session (Bars.BarsSinceSession > 1 and Bars.BarsSinceSession < 55).

    This problem keeps popping up everytime I start (enable) the strategies before 08:00. If I wait untill the first tick, then everyting seems to work fine, but only if there are no open positions. In the latter case it even executes orders also when I wait for the first ticks after the opening at 08:00, while I have adjusted the wait untill flat into 'immediate' and set the account syncing to true. In that case proper running orders are cancelled sometimes by placing a sell against a proper buy (remember it are two seperate strategies, but the settings rule out that two positions are activated simultaniously).

    As an example it occured right this morning and it is driving me nuts. I had no positions open and enabled the strategies at 07:58. The first tick popped up at 08:00, slightly higher than the previous night close and the strategy had no trigger on the last bar close (last bar of previous session, on which it is not allowed to trade anyway) but an sell order was executed immediately. A few secons later is was closed again, indeed on one of the exit parameters.
    This also happens when I want to sync a buy position (overnight) and start/ enable the sell strategy also. It closes the proper buy positions by entering a sell, which flattens my overall position.

    The only thing I can think of after all I've done is that the strategy 'looks' ate the previous day close of the index itself at 17:30 GMT+1 instead of the close of the index futures at 22:00, although the session template is set to default 24/7. Does this makes sense?

    Please give me your thoughts, as this just doesn't work properly and I have done everything I can come up with.

    Regards,
    Francis

    #2
    First of all : welcome here to the forums Francis. Are you working on the latest NT 7 release 21?

    Are those Multi-series strategies, meaning you add for example the index data to arrive at trading decisions?

    Do you see the same happening if you replay the day in Market Replay, so you could debug accurately which condition triggers your entry still?

    Also I would suggest focusing on one side / strategy only and then testing the combination of both to add complexity.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Bertrand,

      Thank you for your quick respons.

      I'm using NT 7.21 indeed.

      The data to arrive at trading decisions is purely based on the asset traded itself: the AEX index future, in this case the October series (FTI 10-10).
      I suppose you aim at the probability the asset trading might have slightly other price development as the data. This is clearly not the fact here. Besides that the price at opening is far from the one which would trigger a sell order.

      This problem does not occur in market replay. None of the days I've had these kind of orders are shown in the market replay.

      The thing is I can't test for this problem only in real live mode. The only way to prevent from executing orders is to wait with enabling of the second strategy (sell) untill the running positions of the other (buy) ar flattenend. Another way is to start the strategies both simultaniously after the opening ticks. In this way it is not possible to let the strategies run active overnight and I have still to be there every session opening.

      I understand it might be difficult for you to see what is going on. Especially while I've done pretty much to prevent from trading on the first bar. The only explanation which seems plausible is that on opening the price of the index at closing matters at 17:30 instead of the future at 22:00. Pricewise this is possibile. But than it's still curious while the strategies may not trade on the first bar.

      What exactly means the default 24/7 template? Does it remarks session breaks for example? When I set the template to instrument setting, the chart won't update at the start of a new session. Is the session template Euronext GMT Index Futures different in handling my European time futures then the default 24/7 template?

      Comment


        #4
        Hello Francis,

        Yes, default 24 / 7 will have session breaks at midnight each day, based on the setting selected. You can view the exact settings through Tools > Session Manager > selecting Default 24 / 7.

        while I have adjusted the wait untill flat into 'immediate' and set the account syncing to true.
        Please see here for expected behavior in this case . This section is also excerpted below. Is it possible the orders you're seeing are designed to bring the account position in line with the strategy position?

        ===
        Immediately submit live working historical orders, Sync account position = true

        This combination should be used when you want to begin trading with your strategy immediately while not worrying about your Account Position prior to start.

        On startup the strategy will begin executing orders immediately.

        Any active orders on the account previously generated by the strategy that does not match an active strategy order will be cancelled. Should the strategy be unable to cancel and receive confirmation on the cancellation of these orders within 40 seconds the strategy will not start and an alert will be issued.
        The matching active orders on the account will then be mapped to the active strategy orders
        Any remaining active strategy orders that cannot be successfully paired will be submitted live and the strategy

        After the strategy is successful in cancelling and submitting any orders that required action it will check your current Account Position and compare it to your Strategy Position. On multi-instrument strategies it will perform this check for all instruments used by the strategy.

        If the Account Position matches your Strategy Position, no reconciliatory order will be submitted. The strategy will then begin managing your Strategy Position immediately.
        If the Account Position does not match your Strategy Position, NinjaTrader will submit a market order(s) to reconcile the Account Position to match your Strategy Position. The strategy will then begin managing your Strategy Position immediately.

        Note: The reconciliatory market order is submitted outside of the strategy so your strategy will not be able to manage it from methods like OnOrderUpdate(), OnExecution(), etc.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hello Ryan,

          I have seen the session template manager and it's time per session template. I was more curious about the difference in how NT reacts to them, or isn't there any besides ther trading hours?

          I think I understand the different options on the way NT handles account positions pretty well. Normally I want to wait untill flat, except when I have an position overnight, which is only possible with buys in my strategies. This account syncing works fine. The problem like this morning is in the fact that there was no position to sync and thus the setting were wait until flat en sync on false. Both the buy and sell strategies were enables before the first tick of the session. Just at the first tick a sell was generated, and en few seconds later is was closes again as if NT corrected it mistake itself. The trigger to sell did make no sense at all; the previous bar did not activate a sell trigger, besides the fact trading should start after the first session bar.

          I just found out on some trial and erroring that in the back test the situation can be replayed if I set the Exit On Close on false. I have this always on true on the sell strategy. So this might lead you to some idea of the problem? Again this still is weird, because at the end of the previous session no sell position was open, so there was no running sell. Besides the fact I had the strategy set on true.

          I can think of only one thing; at the time of the closing of the bar in the previous session no trigger was set, but it nearly did. At hindsight, when moving averages are formed on more following bars, NT thought there should be an open position at the close of the session. While there was none, it openend one at the start of the new session and closes it immediate because all parameters for a sell were already passed closing it. Does this makes any sense?

          Comment


            #6
            I suggest simplifying things to isolate what's happening. It's hard to say with two strategies and their own combinations of account position, strategy position and their own settings.

            Work from one strategy, identify all relevant settings, and look at the source of the orders. Are these reconciliatory orders from syncing or are they generated by the strategy?

            Use Print() statements for signal confirmation.
            Use TraceOrders output to troubleshoot the origin of the orders.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              The problem still arises. Also when I isolate the strategies.

              This morning I started the long strategy just before opening of the day session. Settings 'Wait until flat', sync = true (I had a flat account position as I do not want to start with live trades from the sixth bar, hence the BarsSinceSession>6), trading not of first bar of session (bars.FirstBarOfSession=false).
              The previous session closed at 22:00 CET with a Buy signal. On opening of the new session this morning, at the first tick this Buy order was executed... So on the signal of the closing of the last bar of previous session. The only way to prevent this is by adding the line of code Bars.LastBarOfSession=false. Then this order would not be executed this morning, while I have also the line of code BarsSinceSession>6 and the wait until flat settings. Why is this last line of code not holding the execution on the opening of the new session, but it does this so on the five following.

              It seems there are some irregularities with Ninja on opening sessions and how it handles executions. using the Print() and TraceOrders() output does not help, as I see these exact orders shown in my chart.

              Comment


                #8
                Hello Francis,

                Thank you for the additional information. Can you please try to setup a simple strategy that demonstrates the issue, as well as the steps needed to see it. We can then work on reproducing and reporting any issues to development.

                Also, please confirm if our understanding of the issue is correct:
                Your strategy is submitting orders when you do not expect, and you have not been able to identify source or cause of these orders with TraceOrders output or Print statements.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Ryan,

                  Unfortunately I can't simulate a simple example where the situation at close is exact one which does match my combination of signals. Or I have to build one on TimeValue instead of price signals.
                  The only thing I can do is send you my exact strategies.

                  Thing is I think it's also the problem that NT only allows to set the starting a new strategy ninja script options 'Wait until flat' or 'Immediate' for the strategies together, where I, and I think more people with me, rather would set these per strategy. For my long strategy I need this on 'Immediate' and sync true, for my short it has to be 'Wait until flat' and sync is false. This way I never can trade automated on opening with NT, as I have to set these every morning manually according to that day's account position. And even then NT acts 'surprisingly' then...

                  Again this morning I had some syncing activities I did not want and which has cost me real money...
                  Yesterday evening one buy (futures contract) was generated at 21:30. This one was correct. My buy strategy allows to go overnight, so I had one long position in account this morning at the opening of a new session. No short position in account, as that strategy does not allow overnights.
                  Before opening of the new session I have set starting new strategy option on 'Immediate' and my long strategy sync on true, as I needed to be my long to be insync with my long account position. The buy strategy started fine at 08:00 showing up green and running indeed with one long position.
                  On starting the sell strategy at 08:06 however everything seems to go fine also (green and no position). But when the long position was closed at 08:15 by the buy strategy parameters my loss was much more that the ticks allowed it to be. And yes, again two longs were closed... One from the correct overnight and one extra SHORT position which NT had bought at 08:06 on starting the sell strategy to synchronize 'something'. There was nothing to sync except the one already in account and which was running fine since 08:00 and there was no reason at all to go short (far from the sell strategy signals).

                  So two longs were closed at 08:15, NT buy and sell strategies both were flat but my still account showed the one extra synced short which was running negative already andwhich I have to flatten manually. I'm getting pretty pissed about this recurring issue and it has done my reliable feeling about NT's starting and syncing no good...

                  Comment


                    #10
                    Francis, we would need to review your trace / logs from the days of the issue to understand what was happening, can you please submit them via the Help > Mail to Support option?

                    It might also be a good idea to start with one strategy only for your testing as of now, as it's easier to keep track of the sync in this case before involving more strategies and account / strategy position combinations. If you have the auto Sync on, the strategy position is paramount : the account position would be synched to it with a market order as needed and not the other way around.

                    Here are all cases explained -

                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Bertrand,

                      I can't send the log and trace files. NT shows a pop up; Access denied, invalid HELO name. See RFC2821. 4.1.1.1. After that Ninja stalled. I'm having some strategies running, so I rather send these log files another way of later on.

                      I have tested the syncing issue also on just one strategy. Then everything is ok, after I added the piece of code to prevent from trading on data on the last bar of the previous session.

                      You say that the strategy position is paramount. I understand that. But as if this is the case and my running long trade is syncing ok with the active long strategy (Immediate and syncing true), why is a sell order generated when I activate the short strategy, which has by far no signal for this. The only way this could be is that the strategy and account position are not assigned/ fixed to each other properly. At the moment I activated the short strategy, the long strategy was also already triggerd to close the long position with a sell, but did not do this, because it was not at the close of the bar yet (15mins). The activation of the short strategy (also immediate because this is NT over and not specified to unique strategies) triggered this sell order immediatley on syncing (set to false) the current complete account position again instead ruling out those positions already assigned to the active long strategy. This way the account was set to zero positions by flattening the long with an extra sell. The long strategy still thinks it has one long to close at the end of the bar. when the bar is close, this long is closed and all strategies are flat, while the account has still one sell running.

                      Summarized: The setting 'immediate' flattens the entire account, also when positions are assigned to running strategies already. It seems NT does not know how to handle the same underlyings to different strategies. And it does not matter if these are already active or not. This should not be how strategies should react on starting up.

                      Comment


                        #12
                        Francis, thanks for the details - what strategy position is showing historically for the Short strategy as you enabled it? As you would not have the sync enabled for it, could it be a historically working exit order being executed to offset the long the account holds for the long strategy?

                        You can also directly email in your logs and trace (please zip them up), they reside in the MyDocuments > NinjaTrader 6.5 / 7 > log / trace folders.
                        BertrandNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DanielTynera, Today, 01:14 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post DanielTynera  
                        Started by yertle, 04-18-2024, 08:38 AM
                        9 responses
                        40 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by techgetgame, Yesterday, 11:42 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post techgetgame  
                        Started by sephichapdson, Yesterday, 11:36 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post sephichapdson  
                        Started by bortz, 11-06-2023, 08:04 AM
                        47 responses
                        1,615 views
                        0 likes
                        Last Post aligator  
                        Working...
                        X