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

Entry on Signal not Next bar open

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

    Entry on Signal not Next bar open

    Hi. I am sorry if this has been answered before, But I could not find solution.

    In strategy builder, How can make strategy to buy at the signal. Not the price open on next bar. EX)Low crosses 9MA and as soon as it happens, send out buy order(market)

    Thank you
    kapa

    #2
    Hi,

    Under "Default Properties" in Strategy Builder, set "Calculate" to "On Price Change".

    br,
    Chris

    Comment


      #3
      Hello kapa1,

      Thanks for your post and welcome to the forums!

      Member suroot is correct, by default the strategy builder creates the strategy to run in the mode of Calculate.OnBarClose which means that the strategy code executes once at the end of each bar and will perform calculations on completed bars. If your strategy determines to enter an order, the order would be placed on the next bar. In this mode, your strategy will operate the same historically as it does when connected to real time (or replay) data.

      Using the calculate mode of Calculate.OnPriceChange, or Calculate.OnEachTick, will allow the strategy to be executed with greater frequency which means your code will be executed on each tick or each change in price. Depending on the bar size and market volatility this can be a significant number of times per bar. You would be working with right edge data that can change and your strategy conditions can change from one tick to the next. Entry orders would be executed intrabar instead of waiting until the next bar.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thank you Chris and Paul.

        Paul.
        I can limit the number of enties by "Entries per direction" If it is set to 1, no matter how many buy signal has been generated on same bar, it will fill just 1 trade. correct?

        Is there any way I can have strategy builder to enter at Ma cross price for back testing? If 9 MA is at 2500, low cross over, buy at market.

        Thank you and have a wonderful day.

        Comment


          #5
          Hello kapa1,

          Thanks for your reply.

          The entries per direction works with position information. An order is placed and sent asynchronously to the strategy executions to the exchange/ broker, filled and returned as filled. This does take time, meanwhile, your strategy continues execution on each tick or on each price change, so it is possible, depending on market conditions that you may have many orders sent before the position information is updated.

          There are multiple ways to only allow one order through coding in the strategy builder. A couple of examples are:

          1) Use a bool that is set to true initially and is checked to be true as part of your entry conditions, then in the action section where the order is placed you would set the bool to false, thus preventing further orders, you would need to determine and use another set for creating a reset condition for the bool to reset back to true when you are next ready to place a new order.

          2) Create an integer variable to save the bar number of the CurrentBar when the order is placed and then the entry condition would check to see if the variable holds a different bar number than the current bar (thus allowing entry when different and preventing entry when same bar). This would allow your strategy to place a new order on the next bar so it may not be enough time, depending on the circumstances that you will need to test.

          Regarding, "Is there any way I can have strategy builder to enter at Ma cross price for back testing? If 9 MA is at 2500, low cross over, buy at market." Yes, please see the helpguide section on order fill resolution (Backtesting): http://ninjatrader.com/support/helpG...ical_fill_.htm
          Paul H.NinjaTrader Customer Service

          Comment


            #6

            Hello, I have selected in my strategy that "On price change" is calculated as you say in the post above. However, it continues to execute the market orders at the beginning of the next bar. I don't understand the reason.


            It is also about the crossing of an average, but I want you to launch the order at the time of the crossing, not at the next bar since the price can be very different. Thank you.



            Last edited by herkok; 01-21-2020, 04:53 AM.

            Comment


              #7
              Hello herkok,

              Thanks for your post.

              If you are applying this to a strategy in the strategy analyzer then the selected calculate mode will not matter as all historical trades are performed based on Calculate.OnBarClose. This means if the code runs only once on a bar and determines to place a trade it can only be filled on the next bar.

              Have you tried your strategy on live (or market replay) data?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_PaulH View Post
                Hello herkok,

                Thanks for your post.

                If you are applying this to a strategy in the strategy analyzer then the selected calculate mode will not matter as all historical trades are performed based on Calculate.OnBarClose. This means if the code runs only once on a bar and determines to place a trade it can only be filled on the next bar.

                Have you tried your strategy on live (or market replay) data?
                Yes, I am testing it on a demo account and it does it correctly.

                Comment


                  #9
                  Hello herkok,

                  Thanks for your reply.

                  To confirm, your strategy is placing intrabar order when connected to live data. This would be expected when using the calculate mode of OnPriceChange or OnEachTick on live data.
                  Calculate.OnBarClose would mimic historical data processing where orders are placed at the end of one bar and filled on the next (market orders).

                  Reference: https://ninjatrader.com/support/help...?calculate.htm


                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by trilliantrader, 04-18-2024, 08:16 AM
                  4 responses
                  18 views
                  0 likes
                  Last Post trilliantrader  
                  Started by mgco4you, Today, 09:46 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by wzgy0920, Today, 09:53 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post wzgy0920  
                  Started by Rapine Heihei, Today, 08:19 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by Rapine Heihei, Today, 08:25 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post Rapine Heihei  
                  Working...
                  X