• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Handling of WFO boundary open positions

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

    Handling of WFO boundary open positions

    It seems that as WFO moves from unseen data to the next segment that the optimizer closes any open position at the boundary bar, I guess to fully account for trades on that period.

    Can you confirm whether this is the case and/or whether any alternative methods are available, like leaving the trade open and delaying to change the parms until existing position flattens.

    If true, I think WFO has changed the logic of my system by adding an arbitrary exit at each boundary bar when a position is open and so invalidates the entire stats gathered.

    A better approach would be to update existing exit orders with any new values, i.e. change stops and targets. Then when the trade closes either decide to give the trade to the previous period or prorate it based on number of bars on either side of of the boundary.

    This is not a problem for day trading systems (given the day change coincides with the session close) .
    Last edited by lavalampmj; 10-09-2013, 04:43 PM.

    #2
    Hello lavalampmj,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    You are correct here, the WFO closes the position before moving to the next period. I will forward your suggestion to our development team.

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hi Patrick;

      The WFO is almost an incredible tool. However no optimizer should ever change the logic of the system (whether on seen or unseen data) just the parms....

      Its a really important issue for me as in "stats we trust", but if the stats become suspect then there is no hope.

      The issue is however more complex than I outlined previously. Let me explain:

      Choosing the next set of parms can have the following effect on position state:

      Before -> After
      Flat -> Flat <- great no problem trade forward
      Flat -> Long <- go long on next bar or skip that trade?
      Flat -> Short<-go short on next bar or skip that trade?
      Long -> Flat <- what to do exit the position or wait for it to exit with old exit parms?
      Long -> Long <- adopt updated exit orders
      Long -> Short <- go short or wait for it to exit with old exit parms
      Short -> Short<- adopt new exit parms as suggested previously
      Short -> Long<- reverse or let short exit with old parms and skip new long?
      Short -> Flat <Exit?

      I think that its most likely that the same position state would exist before and after parameter adjustment.

      The best (or easiest) case would be to always be flat when adjusting parms Next best would be to have long long or short short states and adjust exit orders.

      However, there is no guarantee what position state you'll be in before and after. So you'd have to think through how to handle these corner cases. Again the goal is not to introduce new logic due to optimization (this is a super no no) and to emulate what you'd do when you occasionally adjust parms. Most of us do that during closed hours and/or while flat. Hope that helps..
      Last edited by lavalampmj; 10-09-2013, 06:03 PM.

      Comment


        #4
        Hello lavalampmj,

        Thank you for your response.

        Please clarify further on this matter. The state of the position should be flat when beginning the test for a new period or set of parameters. Positions do not carry over, they are closed on the last bar of the test for each test.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Hi Patrick;

          My point was that the current method of WFO closing a trade introduces new logic into a trading system. So the optimizer is now part of the system logic. This makes the WFO unusable in testing, as an optimizer should only adjust the parms that drive the logic not change the logic itself.

          However, the notion of the optimizer adjusting parameters at any given bar is problematic. As there are no guarantees that the position state remains the same before or after the parameter change. As an example, think about a simple reversal system where the systems is either long or short but never flat.

          Its a tricky area. For me ideally the optimizer would allow the user to decide what to do to manage these trades and how to account for them statistically, but as you can see from my previous post there are nine position states that can occur as a result of changing parms.

          So in short its not as simple as ensuring your are flat when you change the parms, as the new parms may put your system into a long or short position state but of course in the real world. I was just contemplating that the likely hood of causing a state mis-match would be reduced if you were flat.

          Comment


            #6
            Hello lavalampmj,

            Thank you for your patience.

            While this has been inserted into our tracking system with the number #2574, we would suggest using ExitOnClose == false and lengths of time in historical data that support the full trade logic.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Exitonclose == false in my code? It's not my code that is arbitrarily adding an exit, its the WFO opitmizer. The optimizer is changing the logic of the system. For example, upon moving forward and issuing an exit when there is an open trade across a WFO boundary, this may result in a new trade being opened on the first bar of the next period and having that trade's exit keyed off of the fresh entry price. It all depends if the strategy is coded to enter if true on any bar or just on one signal. This mean the optimizer may have actually caused two trades not just one.

              This is very dangerous for all who don't understand what is actually happening.

              This problem and perhaps the solution relates to the available user defined options to manage strategy and account syncing options upon strategy startup:

              I quote from the help:

              It is critical to understand the various options available to you that determine how the strategy will behave on startup. NinjaTrader provides several option combinations that can be used in different scenarios depending on what your requirements are. Please first review the information about strategy position vs account positions as this article builds on that concept.

              The "Wait until flat before executing live" and "Immediately submit live working historical orders" settings can be found in the Strategies tab of the Options dialogue.

              The "Sync account position" option can be found in the NinjaScript strategy dialogue window when you are adding a strategy.

              Wait until flat before executing live, Sync account position = false

              These are the default settings for your strategies and are the least disruptive in terms of handling your current Account Position. It assumes your Account Position is in a flat state.

              When your strategy starts it will check for any active orders previously generated by the strategy on your account and cancel those first. 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.



              · If the Strategy Position is flat, then the Account Position and Strategy Position are assumed to be in sync with each other. The next order placed by your strategy would be placed as a live order to your account.

              · If the Strategy Position is not flat, the strategy will place all trades in a "virtual" sense until the Strategy Position reaches or crosses a flat state. Once a flat state is achieved the Strategy Position will be assumed to be in sync with the Account Position and all future orders will be placed live.



              Should your Account Position not be flat at the point in time the Strategy Position reaches a flat state your Account Position and Strategy Position will NOT be in sync.


              Wait until flat before executing live, Sync account position = true

              This combination should be used when you want to begin trading your strategy off a flat state with minimal user interaction to sync your Account Position prior to start.



              When your strategy starts it will check for any active orders previously generated by the strategy on your account and cancel those first. 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. After the strategy is successful in cancelling any orders that required action it will check your current Account Position and compare it to a flat state. On multi-instrument strategies it will perform this check for all instruments used by the strategy.



              · If the Account Position is flat already, no reconciliatory order will be submitted. The strategy will then wait for the Strategy Position to reach a flat state as well before submitting any orders live.

              · If the Account Position is not flat, NinjaTrader will submit a market order(s) to reconcile the Account Position to a flat state. The strategy will then wait for the Strategy Position to reach a flat state before submitting live orders.



              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.


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

              This combination should only be used when you are sure your Account Position is the way you want it to be in relation to the Strategy Position prior to strategy 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 will begin managing your Strategy Position assuming your Account Position is in sync with it.



              * A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical.


              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 will then try to sync your Account Position to your Strategy Position through the process below.



              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.



              * A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical.




              Please be aware that these options will only help you sync your Account Position to your Strategy Position once on startup. These options will not guarantee your Account Position remains in sync afterwards. Any active orders you may have had on your account prior to strategy start that was not generated by your strategy would not have been cancelled on start and can lead to your Account Position being out of sync from your Strategy Position. Placing manual trades or running multiple strategies on the same instrument can also lead to your Account Position being out of sync from your Strategy Position.



              Note: Using "Sync account position = true" can close or place live trades to your account.

              Comment


                #8
                lavalampmj, your understanding is correct and thanks again for sharing your input with us. At this time the boundary you set for testing would mean the opened trades are closed, stats done and then the script is put through another testing window. What you then suggest would be a completely different approach to WFO - so to have the testing window open as long as any trades dictated by trade logic are open once a min window is passed? So to not force an early exit outside from the strategy? Same as you would do then in manual trading, reoptimizing the script after the trade is done and then reapplying anew?
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by indy73, Yesterday, 10:52 PM
                0 responses
                3 views
                0 likes
                Last Post indy73
                by indy73
                 
                Started by martyn73, Yesterday, 07:04 PM
                0 responses
                5 views
                0 likes
                Last Post martyn73  
                Started by sergey_z, Yesterday, 02:56 PM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by samir, Yesterday, 02:46 PM
                1 response
                20 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by neoikon, Yesterday, 02:24 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChristopherJ  
                Working...
                X