Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Weird behavior with entries per direction

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

    Weird behavior with entries per direction

    I'm experiencing something weird and I think maybe I don't understand something.

    I have a multi-instrument multi-timeframe strategy. When I run with Entries per direction set to 1-6 I get the same number of trades as I do when setting it to 1. But if I set it to 7 I get more trades. Close inspection shows that only 2 trades are done in parallel when I use 7. I have it set up to trade 7 markets, I think the 7 entries per direction and 7 markets is a big coincidence.

    I was thinking I put 1 entries per direction and I'd get say just ES for a given date. And if I put 2 entries per direction I'd get a trade on ES & YM for a given date. But from what I see I only get ES & YM when I put 7.
    Last edited by cunparis; 12-21-2008, 09:51 PM.

    #2
    Hello,


    It is difficult to say without looking at your code. I suggest using TraceOrders and debug it:


    Not you will probably want to use the last (advanced) method on this link to enter your trades as it allows you to specify bars in progress:


    Also, take it one step at a time: one instrument> one trade, two instruments> two trades, etc.
    DenNinjaTrader Customer Service

    Comment


      #3
      The trace orders confirms what I thought was happening. I set the # of entries to 5 and "allEntries".

      Code:
      10/30/2007 9:20:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:20:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L2' FromEntrySignal=''
      10/30/2007 9:49:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:49:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal=''
      10/30/2007 9:49:00 PM Ignored PlaceOrder() method at 10/30/2007 9:49:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
      The first entry works and the second is rejected. I can't find any reason why it'd be rejected and I suspect this may be a bug.

      Now I put entriesPerDirection at 7:

      Code:
      10/30/2007 9:20:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:20:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L2' FromEntrySignal=''
      10/30/2007 9:49:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:49:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal=''
      10/30/2007 9:59:00 PM Entered internal PlaceOrder() method at 10/30/2007 9:59:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal=''
      10/30/2007 9:59:00 PM Ignored PlaceOrder() method at 10/30/2007 9:59:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L0' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
      Now the first 2 trades are accepted and the third one is refused.

      I'm really stuck on this, I hope there is an explanation. Thanks for looking at it.

      Comment


        #4
        cunparis,

        You need to break down your code to its bare essentials. Then slowly debug it. You need to manually track your orders and see what is happening. After you determine the simplest case works then you can slowly add layers of complexity to your testing. You shouldn't just jump all of a sudden to testing 7 different orders simultaneously. One step at a time.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          cunparis,

          You need to break down your code to its bare essentials. Then slowly debug it. You need to manually track your orders and see what is happening. After you determine the simplest case works then you can slowly add layers of complexity to your testing. You shouldn't just jump all of a sudden to testing 7 different orders simultaneously. One step at a time.
          I understand what you're saying. I just don't understand how this could possibly be happening. I mean I have my strategy enter two orders and the 2nd is rejected due to the entriesPerDirection property. I'm not sure that breaking my strategy down would make a difference but I will give it a try since I'm really stuck on this and I can't do anything else.

          I still suspect there is a bug here because I can't find any way for a 2nd trade to get rejected when I have specified 5 entries!

          Comment


            #6
            cunparis,

            It is very simple to test on your end. Just create a strategy that goes EnterLong() twice and you will see it works just fine. Because the base case works it is likely something in your code and that is what you need to find. You need to eliminate all the variables possible and slowly reintroduce them one by one.

            If you find the simple base case not to work then that is a different story, but on our end the base case works without fail.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the ideas, I suspect it's a problem using multi-timeframe & multi-instrument. I'll do as you say and then make it multi-timeframe and then multi-instrument. I'll report my findings.

              On a related note, if I want to limit the entries myself, how can I do this? Do I use the IOrder and then OnOrderUpdate? The problem is I submit orders that are not always valid (do not always match the entry signal) so I need a confirmation that the order was executed.

              Thanks

              Comment


                #8
                Then you can use IOrder and check status off of the IOrder object.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  I think I might have found what was wrong, but the problem is I don't understand EntriesPerDirection. When I started this thread, I had put

                  Code:
                  EnterLong(1, 1, "L" + BarsInProgress);
                  In testing today I wanted to test with a position size of 2. Since I'm using the timeframe parameter to submit to a shorter timeframe, I have to specify the quantity. Can I do that like this?

                  Code:
                  EnterLong(1, EntriesPerDirection, "L" + BarsInProgress);
                  I don't think that's correct but I'm not sure.

                  EDIT: Ok it seems I'm mixing up the quantity with entriesPerDirection. I understand the latter is used to prevent one from having multiple positions. So am I supposed to code up the quantity myself? I could add a variable with getter/setter to make it configurable with the strategy parameters. Or I can code up a position sizing algorithm based on account balance?

                  Speaking of account balance, I've read that Ninjatrader doesn't know our account balance, but for me it's showing my real balance with Mirus.

                  Thanks
                  Last edited by cunparis; 12-29-2008, 06:59 AM.

                  Comment


                    #10
                    Hello,

                    So am I supposed to code up the quantity myself?
                    >> Yes.

                    I could add a variable with getter/setter to make it configurable with the strategy parameters.
                    >> Yes, you could do this.

                    Or I can code up a position sizing algorithm based on account balance?
                    >> Yes, you will need to track the account balance yourself within your code. NT does not know your account balance. This link demonstrates how to keep track of this:
                    DenNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Ben View Post
                      Hello,

                      So am I supposed to code up the quantity myself?
                      >> Yes.

                      I could add a variable with getter/setter to make it configurable with the strategy parameters.
                      >> Yes, you could do this.

                      Or I can code up a position sizing algorithm based on account balance?
                      >> Yes, you will need to track the account balance yourself within your code. NT does not know your account balance. This link demonstrates how to keep track of this:
                      http://www.ninjatrader-support2.com/...ead.php?t=4084
                      Thanks Ben, much clearer now. At first Ninjatrader seems simple but the more I use it the more powerful it is. Just need to know C# to unleash it.

                      Comment


                        #12
                        I'd like to revisit this subject because I'm working on this right now.

                        My strategy basically has two instruments. in the code I do an algorithm like this:

                        Code:
                                    if(Position.MarketPosition == MarketPosition.Flat) {
                        // entry criteria here
                                    } else if (Position.MarketPosition == MarketPosition.Long) {
                        // exit criteria here
                                    } else if (Position.MarketPosition == MarketPosition.Short) {
                        // exit criteria here
                                    }
                        My question is if I'm trading two instruments, let's say the first 1 enters a trade. Will the 2nd instrument then go into the Flat code block? And if so and if there is an entry, will it enter?

                        Now I think this last part has to do with the "entries per direction". I assume if I put 1 that the second instrument would not enter the trade, it'd be ignored. and that if I want it to trade then I put it to 2. What do I put for entries handling?

                        I currently have my entriesPerDirection to 1 and the EntryHandling to "all" and I was surprised that I got a trade on the 2nd instrument while I already had one on the first. I thought I needed to put entriesPerDirection to 2 to get that behavior. This was live trading, I've never seen that with the backtesting.

                        Basically what'd I'd like is to have 1 trade max for each instrument. So if it's ES & YM, I'd like to be able to have one of each but not have 2 ES or 2 YM.

                        Thanks for clarifying this.

                        Comment


                          #13
                          When working with multiple instruments you should bracket the segments with if (BarsInProgress == 0) to segregate which code block is for which instrument. When checking Position.MarketPosition on a multi-instrument strategy you could use Positions[0].MarketPosition instead.



                          Just put EntriesPerDirection as 1 and EntryHandling = Unique Entries. Then you can trade both, but only once per entry order.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Josh View Post
                            When working with multiple instruments you should bracket the segments with if (BarsInProgress == 0) to segregate which code block is for which instrument. When checking Position.MarketPosition on a multi-instrument strategy you could use Positions[0].MarketPosition instead.



                            Just put EntriesPerDirection as 1 and EntryHandling = Unique Entries. Then you can trade both, but only once per entry order.
                            I want to be able to have open trades on both instruments. I'm playing around and I put EntriesPerDirection=2 and EntryHandling=UniqueEntries and that seems to let me buy one of each. I think this is what I want.

                            Comment


                              #15
                              That setting will allow you to buy twice per instrument. If that is acceptable to you then you are set.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Today, 03:20 PM
                              1 response
                              9 views
                              0 likes
                              Last Post cre8able  
                              Started by fiddich, Today, 05:25 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post fiddich
                              by fiddich
                               
                              Started by gemify, 11-11-2022, 11:52 AM
                              6 responses
                              803 views
                              2 likes
                              Last Post ultls
                              by ultls
                               
                              Started by ScottWalsh, Today, 04:52 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by ScottWalsh, Today, 04:29 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post ScottWalsh  
                              Working...
                              X