Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sync-ing an always in strategy across weekends

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

    #16
    You're welcome drolles - though I'm not 100% sure I follow you both - so you say your restart (with historical recalc) of the strategy on Monday changes the historical strategy position you saw on Friday thus bringing your account position now out of sync? I think what Andreas meant is save the strategy position on closing of business and Friday and then submit a historical order of this qty on restart of the strategy, thus 'forcing' it to be in sync (given your account still shows the same qty, too). Would that be what you seek here?

    Thanks,
    BertrandNinjaTrader Customer Service

    Comment


      #17
      Yes Bertrand,

      I save executions AND all open orders of the strategy.
      On Monday you examine the state of the open orders. Some of your open orders might have become executions.
      Do the math and you get the state of your strategy on Monday morning. (State=position + open orders)

      regards

      Andreas

      (I do this in my strategies, and you might understand why I am not happy with the known NT7 flaw that external executions get a wrong timestamp in NT7)

      Comment


        #18
        Thanks for your input Andreas, this current limitation of external executions timestamps in on our list to look into.
        BertrandNinjaTrader Customer Service

        Comment


          #19
          No problem, I have already written a workaround this NT7 "limitation"

          regards

          Comment


            #20
            Bertrand,

            Thanks for the reply.

            To aid the discussion I’ve attached a strategy which implements the scenario I have detailed below. Just to reiterate the strategy:

            1. Classic 20 Donchian Channel Break out
            2. Target time frame is Daily data
            3. Always in (i.e. always holds a position)
            4. Reversal of position is the entry and exit method
            5. The stop size is calculated on the width of the channel
            6. 1% of the account is risked on each trade
            7. The account starting value $10,000 in this instance
            8. Trades are rejected if the stop means they would consume more than 1% of equity
            9. This implementation uses market orders (i.e. not limit orders)

            I am aiming to understand how to best implement it with the standard NT functionality as it stands. I appreciate what is Andreas is saying but for now let’s put it aside at the moment. I am trying to understand what’s NT’s recommendation is for its implementation using standard functionality.

            The constraints I want to place on the putting it live are these:

            1. It should not sync position size each time strategy / NT is re-launched (e.g. on a Sunday night after a weekend shut down)
            2. It should open a “new” position at the correct position size (i.e. based on the current account equity)

            Why would I not want to the account to be sync with the strategy position each time? As you can see from the results of the backtest on GBPUSD from 01/01/2009 one of the trades lasted 135 days. That is approximately 19 restarts (135 divided by 7) for the strategy one for each week; this obviously doesn’t include any emergencies – e.g. computer crash. Imagine that the position is re-synced every weekend? This creates a cost of trading issue. The cost of submitting market orders to reconcile the positions 19 (likely more) times would degrade the profitability of the trading strategy.

            Secondly, with the inability of NT to distinguish between being live and backtest, the position size of the sync could well be wrong. Why? When executing the on historical bars the account value, and obviously the resulting 1% of that value), is calculated from the value set in the strategy or the simulation value set in the Control Centre.

            Even if you were to a) type the current account equity value into the strategy and recompile each time or b) change the account value in the control centre by the time the strategy came to execute the real time orders they would not be of the “correct” (i.e. calculated from the actual Account value) as the historical executions would be different than the actual live executions. We could not replicate exactly the executions of the past.

            So I don’t really understand your comment. Are you saying that there is no way by using standard NT7 functionality that the strategy can be implemented without a significant number of re-sync orders being submitted, which will probably be of the wrong quantity? Which only leads to Andreas implementation? Is that right?

            Thanks and regards,

            drolles
            Attached Files

            Comment


              #21
              The strategy attached as well. I could only add 2 attachments.

              Thanks,

              drolles
              Attached Files

              Comment


                #22
                drolles, thanks for the detailed clarifications - here's what I was saying -

                a) if your strategy position / qty changed after you've restarted it after the weekend - there will need to be a sync order applied to ensure the account position matches the strategy position.

                b) if the strategy position is equal to the account position after restart, no sync is needed as it's already fine.

                I understand you would like the account position to be in the 'drivers seat' here but unfortunately for now that's not possible with the default options we provide - I can understand the need for more options here though and have added it to our list of feedback - this would then lead you to the custom approach Andreas has outlined in his posts.
                BertrandNinjaTrader Customer Service

                Comment


                  #23
                  Bertrand,

                  Thanks for the reply.

                  Are you saying that there is no way to do this without syncing the Strategy and Account Positions?

                  Thanks and regards,

                  Dan

                  Comment


                    #24
                    Hi Dan, unfortunately yes this is the case - if you restart a strategy and it's held position differs from the account position syncing is needed - A workaround is like Andreas mentioned is to introduce a synthetic historical position matching your account position, so the sync is 'forced' this way.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #25
                      Bertrand,

                      Thanks for your reply. And thank you for your persistence and patience.

                      I’ve followed your recommendation and started to look at Andreas’s solution.

                      I’ve found the sample code generated by Andreas on one of his numerous posts on the topic (cross reference to a key one here for others following this thread - http://www.ninjatrader.com/support/f...ad.php?t=26571). [I can’t say it enough times – Thanks again to Andreas for assisting on this thread.]

                      I’ve found a snippet of that follows this:

                      Code:
                      
                                  if(Position.Quantity!=oldq) {
                                      Print("Strategy Position:"+Position.MarketPosition+" "+Position.Quantity.ToString());
                                      oldq=Position.Quantity;    
                                      Position ap=Account.Positions.FindByInstrument(Instrument);
                                      if (ap != null) Print("Account Position:" + ap.MarketPosition + " " + ap.Quantity.ToString());
                                      else Print("Account Position==null");
                                  }
                      I can’t find any documentation on this Account object, none at all. I’ve searched help on Account, Accounts, etc. Can I assume that Andreas as found an object that is used by NT internally and not documented or supported? A question which I think is answered here: http://www.ninjatrader.com/support/f...ad.php?t=27171. Is the position detailed in this thread by Dierk still the position of NT for supporting this functionality?

                      If I interpret this object correctly this is exactly what I need and solves the problem, right? If I’ve understood it provides access to the actual Account Position and not to the Strategy Position? If I have understood this correctly then this could be really very easy.

                      A strategy can be in basically 3 contexts:

                      1. Backtesting (this includes development and debugging)
                      2. Market Reply
                      3. Live

                      Therefore, if the data the strategy is processing is Historical and not live the strategy author can assume that the strategy is in backtest or being put live and is currently executing historical data. Once it is processing “live data” (i.e. Historical == false) we should be looking at the Account states and not the Positions states. We could ignore the usual Strategy Position programming tests used for backtesting a strategy and do tests on Account.Positions object, right? Or one step further you could “reverse sync” i.e. force the Strategy Position to reflect the Account Position.

                      Just so you know (sorry if you already do) the 3 states approach is exactly the approached used by Esignal in their EFS scripts. Whereby, you can test for each state as the strategy developer to determine what data you executing (backtest, Market Reply, Live) so you can determine difference strategy behaviour if in backtest, market reply or live.


                      Thanks and regards,

                      drolles

                      Comment


                        #26
                        drolles, I will have Bertrand get back to you tomorrow.
                        AustinNinjaTrader Customer Service

                        Comment


                          #27
                          drolles, as you already noted those methods / properties are unfortunately not documented / supported by us - though you can for sure 'play' around with them and see if they fit your needs. If you would like to implement different scenarios for Replay, Strategy Analyzer or Live Trading you could setup custom user inputs toggling those on / off.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #28
                            Trying to understand this since I also run strategies holding positions over weekends and therefore eg. need to restart TWS so the strategy will have to be restarted. Therefore I am looking for a simple way to handle this issue.

                            Seems to me the best thing to do is skip NT's sync attempt. And manually sync if the strategy and account ever become out of sync.

                            Comment


                              #29
                              I'm still looking for a "best practice" approach to realize fixed fractional position sizing in NT. This is actually a really basic concept, yet it seems difficult to realize in NT, since it's not possible to get the current account balance.
                              Would anyone be so kind to share his/her experiences?

                              2nd question: During this thread it was mentioned several times, that there are considerations to add functionalities to Ninjascript for getting account information (also a reference to some mysterious account object). I would find this extremely helpful - any hints if or when this will become an official feature?

                              Comment


                                #30
                                Ignignokt, we could not give you an ETA or commitment on those features unfortunately, but for sure those ideas are tracking in our product enhancement lists as below:

                                # 654 for adding a sync option to sync the strategy to acutal broker account position
                                # 776 for NinjaScript access to the account held market positions
                                BertrandNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by GussJ, 03-04-2020, 03:11 PM
                                16 responses
                                3,281 views
                                0 likes
                                Last Post Leafcutter  
                                Started by WHICKED, Today, 12:45 PM
                                2 responses
                                19 views
                                0 likes
                                Last Post WHICKED
                                by WHICKED
                                 
                                Started by Tim-c, Today, 02:10 PM
                                1 response
                                9 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by Taddypole, Today, 02:47 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post Taddypole  
                                Started by chbruno, 04-24-2024, 04:10 PM
                                4 responses
                                53 views
                                0 likes
                                Last Post chbruno
                                by chbruno
                                 
                                Working...
                                X