Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Signals Discrepancy In Backtest

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

    Multiple Signals Discrepancy In Backtest

    Hello,

    I have coded a very simple test strategy to investigate the behaviour of using different signal names for different trades within the same strategy. I am a bit confused by the results.

    The strategy has an option DoTradeMultiple to trade either one signal (EMA 50) or three (EMA 50/100/200). The signal names are EMA 50/100/200 accordingly.

    As I undertstand it the Entry and Exit points for the EMA 50 strategy should be identical whether DoTradeMultiple is set or not. But this does not appear to be the case.

    I have attached spreadsheets for the backtest results of EMA50 only and EMA50/100/200 to compare, and the test strategy code.

    Please could you let me know what is causing this behaviour, and whether it is expected or a bug? Thanks

    One example of a discrepancy is below, and there are many more:

    50 100 200
    ES 09-12 Sell 1 1350.25 20/06/2012 11:21 NT-00078 Exit 6L NT-00084 EMA50 0 1 Backtest
    ES 09-12 Sell 1 1349.00 20/06/2012 11:25 NT-00081 Exit 7L NT-00087 EMA50 0 1 Backtest

    50
    ES 09-12 Sell 1 1350.25 20/06/2012 11:21 NT-00036 Entry 1S NT-00036 EMA50 0 1 Backtest
    ES 09-12 Buy 1 1350.75 20/06/2012 11:49 NT-00038 Entry 1L NT-00038 EMA50 0 1 Backtest
    Attached Files

    #2
    Results attachements for the above...
    Attached Files
    Last edited by pmcgoohan; 06-26-2012, 05:12 AM.

    Comment


      #3
      Hello pmcgoohan,
      The Entry methods, closes any existing position in the opposite direction before entering a position. For example if you are long and a short signal is generated via the EnterShort() method, then it will first close the long position and then will enter the short position.

      From the 50.txt file

      NinjaTrader is closing existing position
      ES 09-12,Sell,1,1350.25,20/06/2012 11:21,NT-00035,Exit,-,NT-00035,Close position,0,1,Backtest,
      and then entering new short position
      ES 09-12,Sell,1,1350.25,20/06/2012 11:21,NT-00036,Entry,1S,NT-00036,EMA50,0,1,Backtest,
      Exiting the short
      ES 09-12,Buy,1,1350.75,20/06/2012 11:49,NT-00037,Exit,-,NT-00037,Close position,0,1,Backtest,
      Entering a new long position
      ES 09-12,Buy,1,1350.75,20/06/2012 11:49,NT-00038,Entry,1L,NT-00038,EMA50,0,1,Backtest,
      This is expected.
      JoydeepNinjaTrader Customer Service

      Comment


        #4
        I think you missed the point a bit there- I have no problem with the way the 50 EMA trades on its own.

        As I understand it using different signal names means the position of other signals is ignored, so the 100/200 EMA trades shouldnt interfere with the 50 EMA trades at all.

        But the 50 EMA trades are different when running on their own, as compared to when running alongside the 100/200 EMA trades. Why is this?

        Comment


          #5
          Hello pmcgoohan,
          Thanks for the clarification.

          To assist you further can you tell me, while backtesting,
          1. What Entries per direction you have set
          2. What is the Entry Handling you have set.


          I look forward to assisting you further.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Entries per direction = 1
            Entry handling = UniqueEntries
            Exit on close = false

            As I understand it, UniqueEntries should ensure that the three different MA trade types ignore each others positions.

            If you want to recreate it- I am running against ES the 500 Tick Bar from 20/06/2012 to 24/06/2012.

            Comment


              #7
              Hello pmcgoohan,
              It may be the case where your strategy logic is sending Long and Short order on the same bar which is making the positions count to go haywire. I would suggest to check for the order direction for all the EMA's so that no reverse order gets submitted on the same bar.

              Also even for unique entries there will only one market position.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                But surely the point of using different signal names is that you dont need to check what the other signals are doing?

                What is the point of using signal names if you have to check whether other signals are submitting orders at the same time?

                Unless I have misunderstood something, it seems to me that this should be treated as a serious bug.

                Comment


                  #9
                  Hello,

                  We did have some internal discussion on this case as I can see your point.

                  However take the following scenario which is the primary issue and what occurs in your case.

                  protected override void OnBarUpdate()
                  {
                  EnterLong("EMA50");
                  EnterLong("EMA100");
                  EnterShort("EMA50");
                  }

                  If you run this the output is as follows:

                  Buy 1 tagged EMA50
                  Buy 1 tagged EMA100
                  Sell 2 to close and return to flat tagged Close
                  Sell 1 tagged EMA50

                  Once that EnterShort() occurs it sells 2 to close both the tagged EMA100 and tagged EMA50 positions due to the EnterShort command(Even though entershort was only tagged EMA50). Thus in an event where the strategy would need to reverse its entire position the entry of another named unique entry can effect the performance of another leg since the strategy has only one master Position.MarketPosition. This is a limitation of our managed code and you would need to introduce your own handling to create your own MarketPositions for each leg and update them baised on specific orders filling in OnOrderUpdate() if you need this capability or utilize the unmanaged mode.

                  Now we did see an item where position would report higher then expected. This is being further isolated to see if this is expected or there is an issue that needs to be looked into for next major release however that is separate to your primary concern described above..

                  -Brett

                  Comment


                    #10
                    Thanks for looking into this for me.

                    I would have expected the following behaviour:

                    Position 0
                    EnterLong("EMA50");
                    Position 1L
                    EnterLong("EMA100");
                    Position 2L
                    EnterShort("EMA50");
                    Position 0

                    To continue...
                    ExitShort("EMA50");
                    Position 1L
                    ExitLong("EMA100");
                    Position 0

                    In other words, I don't see why reversing the earlier EMA50 leads to a total reversal of market position. It should just cover 1 and short 1, even if that means we end up flat. That is self crossing and is legitimate and transaction efficient. If you have contradictory trading signals, you should be flat.

                    Isnt this what it would do if you ran the EMA50 and EMA100 as seperate strategies on the same instrument? This is a genuine question, as this is probably the way I will have to do it now.

                    Edit: also managed orders should submit once the OnBarUpdate event in all timeframes has fired and the total position adjustment is known. eg: you should never send 1 long and 2 short orders on the same bar from different signals- just 1 short order.
                    Last edited by pmcgoohan; 06-26-2012, 11:53 AM.

                    Comment


                      #11
                      Hello,

                      Understood, what you are expecting is not how the feature works which is why I clarified. To do what you want would require separate strategies with separate position events, you can Tag them with names in a single strategy but it is primarily for accounting purposes.

                      -Brett

                      Comment


                        #12
                        Ok- thanks Brett.

                        I will split my logic across several strategies, and try to use managed orders still.

                        Looking at your rules for managed order entry, I see that "new order entries are ignored when the strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction"

                        Can I get round this by cancelling any previous EnterLongLimit/EnterShortLimit orders just before (ie: the code line before) a new EnterLong/EnterLongLimit call using CancelOrder. Is CancelOrder compatible with managed orders in this way?

                        Comment


                          #13
                          Hello,


                          Yes this can be done, however keep in mind that these cancellation have to go out through your network and take milleseconds to get fully cancelled. I would suggest waiting at least one OnBarUpdate to make sure the order is truly cancelled and not filled before you submit the second entry order.


                          Please see this sample: http://www.ninjatrader.com/support/f...ad.php?t=18890

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Barry Milan, Today, 10:35 PM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by WeyldFalcon, 12-10-2020, 06:48 PM
                          14 responses
                          1,428 views
                          0 likes
                          Last Post Handclap0241  
                          Started by DJ888, Yesterday, 06:09 PM
                          2 responses
                          9 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          40 views
                          0 likes
                          Last Post jeronymite  
                          Started by bill2023, Today, 08:51 AM
                          2 responses
                          16 views
                          0 likes
                          Last Post bill2023  
                          Working...
                          X