Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Preventing Entry+Exit Orders at same time

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

    Preventing Entry+Exit Orders at same time

    My strategy is set up such that it is conceivable an entry and an exit can occur on the same bar, cancelling each other out and incurring transaction costs.

    Is there some logic I can add to the strategy to prevent this from happening? I would like the strategy to identify if an entry order will be placed simultaneously with an exit order, and to ignore both orders.

    I currently am using the Strategy Builder. Any input is appreciated though.

    #2
    Hello liquid150,

    Thanks for opening the thread.

    Yes, you can use additional logic to outline when your strategy should specifically enter or exit. I have created a demonstration showing how you can use bools to make you entry and exit conditions more explicit.

    Demo - https://www.screencast.com/t/wrRtdOkq

    Additional tips on using the Strategy Builder can be seen in the Strategy Builder 301 webinar. I will provide a link to a publicly available recorded version of this webinar.

    Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello liquid150,

      Thanks for opening the thread.

      Yes, you can use additional logic to outline when your strategy should specifically enter or exit. I have created a demonstration showing how you can use bools to make you entry and exit conditions more explicit.

      Demo - https://www.screencast.com/t/wrRtdOkq

      Additional tips on using the Strategy Builder can be seen in the Strategy Builder 301 webinar. I will provide a link to a publicly available recorded version of this webinar.

      Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

      Please let me know if you have any additional questions.
      Ah, thanks Jim.

      I was hoping there was some easier way to do this by checking for order submittals, but this will (probably) work.

      Comment


        #4
        Hello liquid150,

        You may also consider checking BarsSinceEntryExecution before submitting your exit order. This method is also available in the Strategy Builder.

        BarsSinceEntryExecution - https://ninjatrader.com/support/help...yexecution.htm

        If you have any questions on this method, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jim View Post
          Hello liquid150,

          You may also consider checking BarsSinceEntryExecution before submitting your exit order. This method is also available in the Strategy Builder.

          BarsSinceEntryExecution - https://ninjatrader.com/support/help...yexecution.htm

          If you have any questions on this method, please don't hesitate to ask.
          Sure, quick question on this method. If I set BarsSinceEntryExecution to zero, will this capture an entry execution and change a boolean parameter to "false" before the exit order is executed?

          I am trying to figure out if there is an order of operations the software follows which I can exploit...

          Comment


            #6
            Hello liquid150,

            BarsSinceEntryExecution is a method and not a property. It will return a value when called and you cannot set its value. This return value is an integer, not a bool.

            From the help guide:
            Definition
            Returns the number of bars that have elapsed since the last specified entry.

            Method Return Value
            An int value that represents a number of bars. A value of -1 will be returned if a previous entry does not exist.
            In other words, this will tell you how many bars have passed since an entry method has been executed (filled.)

            I suggest to print the return value of this method in a simple strategy to visualize how it works. You can place the print in the actions section of an empty condition to see it print with each bar update. Prints can be observed in the NinjaScript output window. (Control Center > New > NinjaScript Output)

            If you have any questions on the results you are seeing, please don't hesitate to write back with the prints you are receiving.
            JimNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jim View Post
              Hello liquid150,

              BarsSinceEntryExecution is a method and not a property. It will return a value when called and you cannot set its value. This return value is an integer, not a bool.

              From the help guide:

              In other words, this will tell you how many bars have passed since an entry method has been executed (filled.)

              I suggest to print the return value of this method in a simple strategy to visualize how it works. You can place the print in the actions section of an empty condition to see it print with each bar update. Prints can be observed in the NinjaScript output window. (Control Center > New > NinjaScript Output)

              If you have any questions on the results you are seeing, please don't hesitate to write back with the prints you are receiving.
              My apologies for my unclear language. I intend to be asking the following:

              If I call BarsSinceEntryExecution, and create a Boolean variable "AllowExit," and define BarsSinceEntryExecution = 0 call o be AllowExit = False, will this work?

              I suspect not, but it's much easier than isolating the exact conditions in the strategy which need be filtered out.

              Comment


                #8
                Hello liquid150,

                When BarsSinceEntryExecution() == 0, this means an entry order has just been filled. You would not see this on the same bar of an order submission. I would suggest to set AllowExit to true when BarsSinceEntryExecution() > SomeNumberOfBars.

                I would still suggest to set up tests to observe the functionality of BarsSinceEntryExecution so you can use it properly in your strategy.

                I have a created a video demonstrating such a test.

                Demo: https://www.screencast.com/t/sShhayIXFli

                Please let me know if I may be of further assistance.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jim View Post
                  Hello liquid150,

                  When BarsSinceEntryExecution() == 0, this means an entry order has just been filled. You would not see this on the same bar of an order submission. I would suggest to set AllowExit to true when BarsSinceEntryExecution() > SomeNumberOfBars.

                  I would still suggest to set up tests to observe the functionality of BarsSinceEntryExecution so you can use it properly in your strategy.

                  I have a created a video demonstrating such a test.

                  Demo: https://www.screencast.com/t/sShhayIXFli

                  Please let me know if I may be of further assistance.
                  Thanks, anyway Jim. I had a feeling it had to be filled for it to register. I will isolate the condition which should switch a pair of booleans as you previously suggested. I am already using a BarsSinceEntry and BarsSinceExit condition in other places in the strategy, but thank you for your time.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  16 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  106 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  609 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X