Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entries Per Direction violation?

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

    Entries Per Direction violation?

    I was running a strategy last night that enters on hammer candles and calculates per tick. I have a threshold that ensures my orders are never more than 3 contracts in size, and my entries per direction is 1. This backtests fine, but last night it bought way over the expected limit. It never violated the quantity (3) I imposed but the number of concurrent orders was much higher than I expected. Is this due to tick based calculations being too fast for NT? Why would it do this? I'm using managed orders and custom entry/exit - not standard SL function, if it matters.

    starting at 2/8/2024 5:30:17 AM the strategy makes 5 distinct short orders of 3, when it should be unable to get past one order of 3? Am I misunderstanding something here?
    Attached Files

    #2
    Hello Skifree,

    Thanks for your post.

    What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)​

    What is your EntryHandling property set to (AllEntries or UniqueEntries)?

    Are you calling Enter methods and Exit methods in the same bar update? For example, calling ExitLong() and EnterShort() within the same condition.

    Is the strategy calling EnterShort() multiple times throughout the script?

    Does your strategy have a unique signal name for the EnterShort() method(s)?

    Please share an exported copy of the script with us so we may take a look at the code of the strategy to see if anything specific stands out. To export the strategy go to Tools > Export > NinjaScript Addon.

    We look forward to assisting further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon,

      What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)​
      ​- version is 8.1.1.7 64-bit

      What is your EntryHandling property set to (AllEntries or UniqueEntries)?
      - AllEntries

      Are you calling Enter methods and Exit methods in the same bar update? For example, calling ExitLong() and EnterShort() within the same condition.
      - the exit conditions are evaluated prior to entry but it's not possible to enter from and exit condition or exit from and enter.

      Is the strategy calling EnterShort() multiple times throughout the script?
      - yes in all cases except for forced exits like NT's "Exit on Session Close"

      I've attached the exported strategy zip file

      Thank you
      Attached Files

      Comment


        #4
        Hello Skifree,

        The file you provided is an assembly and we would not be able to assist with this or view the code.

        May we have you provide an open source export? (Meaning do not check the 'Export as assembly' checkbox)


        Note, the orders in your screenshot all have the same timestamp, meaning they were all submitted at the same time.

        The EntriesPerDirection is based on the position. Once a position is taken and the EntriesPerDirection is met, further entries in that direction are ignored.
        However, if multiple orders are submitted at the same time, the orders will not have enough time to be submitted, become working, fill, and change the position, which can allow further orders to be submitted.

        To prevent this, you could use a bool (or set of bools) that are changed when the entry is submitted, and then changed back when the position is closed.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          Is there an email I can send this to?

          While the dates in that window are the same, this was running per tick and this order tab timestamp column shows that each order was submitted at a different tick. Are there some functions that are too slow for tick calculations?

          Attached Files

          Comment


            #6
            Hello Skifree,

            scriptingsupport [at] ninjatrder [dot] com is our email.

            I would recommend creating a simple test script that can be shared open source on the forum for others who may be experiencing a similar issue.

            It could be that the orders are not able to fill and change the position by the next tick.
            If you print the order.ToString() object from OnOrderUpdate() and the position.ToString() from OnPositionUpdate() you would be able to see if the position is updating before the next order is submitted.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I can send the file, but this is a large strategy, broken across functions. The part I don't get is that even in tick replay testing, this issue does not show up.

              Comment


                #8
                ok, the file has been sent to that address

                Comment


                  #9
                  What's the point of me sending my code to you as requested if the response is that you can't debug? My big question is why this isn't reproduced in testing wouldn't the same behavior happen at the tick calculation?

                  Comment


                    #10
                    Hello Skifree,

                    You had asked what our email address and I have provided this.

                    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                    That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​

                    Below is a link to a few forum posts where you can see this mentioned.
                    https://www.google.com/search?q=site%3Aninjatrader.com+Unfortunately%2C+i n+the+support+department+at+NinjaTrader+it+is+agai nst+our+policy+to+create


                    "My big question is why this isn't reproduced in testing wouldn't the same behavior happen at the tick calculation?"

                    I'm not quite sure what you are asking. However, it very possible that additional orders are being sent before the previous order has filled and changed the position.

                    I would expect a simple test script that places orders on each new tick to be affected the same. This simplified test script can clarify what is occurring without the added complexity of the rest of the script so that you can focus on one specific issue.

                    Have you added the prints in OnOrderUpdate() and OnPositionUpdate() to view the sequence of the orders filling and the position updating?
                    (If you see in the output an order submitted and then another order submitted before the position updates, this would confirm what is happening)
                    If so, please attach the output text file to your next post.

                    You can fix this with logic. You can use bools to know which order methods have been called or you could save orders to variables and set them to null when the trade exited and check if they are null in the entry condition or you could an integer as a counter to count how many times an entry method has been called and stop sending orders once your limit is reached.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by imjustkaze, Today, 08:08 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post imjustkaze  
                    Started by quebequer, Today, 06:51 AM
                    2 responses
                    15 views
                    0 likes
                    Last Post quebequer  
                    Started by Rraannddyy, 09-15-2021, 06:14 PM
                    6 responses
                    1,013 views
                    0 likes
                    Last Post MiCe1999  
                    Started by algospoke, 02-20-2025, 08:12 PM
                    9 responses
                    100 views
                    0 likes
                    Last Post MiCe1999  
                    Started by michelz, 02-18-2025, 08:30 AM
                    30 responses
                    975 views
                    0 likes
                    Last Post michelz
                    by michelz
                     
                    Working...
                    X