Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to enter on the high+1 tick of a candle?

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

    How to enter on the high+1 tick of a candle?

    Having a little trouble with this one for some reason. Here is what I want to tell strategy builder to do (in a basic format):

    Green bar 1
    Green bar 2
    Submit order one tick above the high, including the wick, of green bar 2 to enter long

    My assumption would be that this is how I would do this, for example, in a condition set:

    open < close 2 bars ago
    open < close 1 bar ago

    Do the following:

    Enter long limit High 1 bar ago + 1 tick offset

    What seems to be happening however is the limit order is submitted at the close of bar 2 + 1 tick instead of the high. I have this strategy setup to update on price change, as I have had issues in the past with stop orders not being submitted with the calculation of on bar close. When I have used the on bar close method, stop orders are not submitted in backtesting until a bar closes, which is not great practice as a lot can happen in a bar!

    If someone can check my logic here, that would be great.

    Chart example, with annotated bars to match above:

    Click image for larger version

Name:	image.png
Views:	215
Size:	1.4 KB
ID:	1338448

    I'd like to have a limit buy order submitted one tick above the wick of bar 2, but only after the bar closes.

    #2
    Hello, Thanks for your message.

    After analyzing your conditions and actions, everything seems correct with your conditions. The issue is with the type of order you're selecting. Your limit orders are getting filled immediately, at the current market price, because you're trying to submit a buy limit order above the current price, which results in your order being filled at the current price.
    This also applies if you try to submit a sell order limit below the market price. This results in the orders being filled immediately.
    To submit buy-limit orders above the asking price, you have to use the EnterLongStopLimitOrder method.
    In principle, this will work the same way a BuyLimitOrder, except it will allow you to place this order above the market price.
    One detail that is important to remember is that for EnterLongStopLimitOrder you also need to set a StopPrice being only the Limit price.
    Another information that is important to consider is that EnterLongStopLimitOrders will be rejected if entered below the market price so you need to ensure your condition will meet this requirement.

    To Enter an EnterLongStopLimit order, within the action portions of the "Conditions and Actions" section, click the add button located in the lower-right corner. Under the Order Management folder, you will find the "Enter Long position by Stop Limit Order". Ensure you enter a valid price for both the Limit price and Stop Price.

    Addressing the second part of your inquiry, in regards to your having issues with your stop orders not being submitted with the calculation of on-bar close, we recommend you check out the link below, which it contains an example where that will demonstrate how you can use inputs and variables in the strategy builder to keep your stop orders alive https://forum.ninjatrader.com/forum/...rategy-builder

    Also, you mentioned that your Stop orders are not being submitted until the bar closes.
    You can add a 1-tick series to your strategy and submit orders to this series to achieve intrabar granularity. Be aware that this requires you to unlock your strategy and manually edit your script.
    Below you will find a sample code that demonstrates how you can achieve that.

    https://support.ninjatrader.com/s/article/Developer-Guide-Improving-backtest-order-fill-accuracy-with-intrabar-granularity?language=en_US

    Comment


      #3
      Originally posted by NinjaTrader_Helom View Post
      Hello, Thanks for your message.

      After analyzing your conditions and actions, everything seems correct with your conditions. The issue is with the type of order you're selecting. Your limit orders are getting filled immediately, at the current market price, because you're trying to submit a buy limit order above the current price, which results in your order being filled at the current price.
      This also applies if you try to submit a sell order limit below the market price. This results in the orders being filled immediately.
      To submit buy-limit orders above the asking price, you have to use the EnterLongStopLimitOrder method.
      In principle, this will work the same way a BuyLimitOrder, except it will allow you to place this order above the market price.
      One detail that is important to remember is that for EnterLongStopLimitOrder you also need to set a StopPrice being only the Limit price.
      Another information that is important to consider is that EnterLongStopLimitOrders will be rejected if entered below the market price so you need to ensure your condition will meet this requirement.

      To Enter an EnterLongStopLimit order, within the action portions of the "Conditions and Actions" section, click the add button located in the lower-right corner. Under the Order Management folder, you will find the "Enter Long position by Stop Limit Order". Ensure you enter a valid price for both the Limit price and Stop Price.

      Addressing the second part of your inquiry, in regards to your having issues with your stop orders not being submitted with the calculation of on-bar close, we recommend you check out the link below, which it contains an example where that will demonstrate how you can use inputs and variables in the strategy builder to keep your stop orders alive https://forum.ninjatrader.com/forum/...rategy-builder

      Also, you mentioned that your Stop orders are not being submitted until the bar closes.
      You can add a 1-tick series to your strategy and submit orders to this series to achieve intrabar granularity. Be aware that this requires you to unlock your strategy and manually edit your script.
      Below you will find a sample code that demonstrates how you can achieve that.

      https://support.ninjatrader.com/s/article/Developer-Guide-Improving-backtest-order-fill-accuracy-with-intrabar-granularity?language=en_US


      Sorry for the delay on this, this makes perfect sense and I really just completely missed it. Related to the original issue, I'm having some trouble with some of the logic that I'm hoping you can help me with.

      I have some really simple logic, here it is:

      open[3]<close[3] (sequence start, up bar)
      low[3]<low[2] (second bar in sequence, higher low than bar above)
      open[1]<EMA (last bar in sequence, opening below EMA)
      close[1]>EMA (last bar in sequence, closing above EMA)

      Do the following:

      Enter longstopmarket high[1]+1 tick


      Here is a screenshot of an ideal setup:

      Click image for larger version

Name:	image.png
Views:	160
Size:	9.4 KB
ID:	1339697


      What I want to have happen, is that right after bar 1 closes, a stopmarket order is submitted 1 tick above the high of that bar. But, you can see from the example above, I'm either off on my timing, or something isn't backtesting correctly.

      I've had issues putting together the bar sequencing before, and I can't quite find any rhyme or reason to it. With the logic I have above, should the strategy be executing as I expect? Or do I have something wrong? ​


      The strategy is running with "on price change", which I know won't behave the same in backtesting, but even with the lack of intrabar granularity, my expectation would be that the order is submitted and displayed even in backtesting on bar 0, not two bars later.

      There are other cases as well, that the strategy seems to just go off the rails, which leads me to believe the timing is off. Here is an example:

      Click image for larger version

Name:	image.png
Views:	178
Size:	8.5 KB
ID:	1339699

      I can't even see why this order was submitted based on the logic I have constructed.

      Can you please take a look and let me know what you think?

      Thanks



      ​​
      Attached Files

      Comment


        #4
        Hello sclay115,

        Thanks for your response.



        To understand the behavior of your NinjaScript, such as why orders are or aren’t being placed or why certain actions are happening or not, it’s essential to add Print statements throughout the script. These help reveal how the logic is evaluated by showing the values being used in real-time.


        The standard approach involves using Print and TraceOrders to debug. This guide builds on those concepts by showing how to drill down into a specific line of code and analyze the output to uncover exactly what the script is doing.

        In your prints, ensure that you print the time of the bar, and all values being compared in the condition with labels for each value and comparison operator. Also, note that the type of order used is related to the current market price. You need to ensure that the high of the previous bar plus 1 tick is greater than the current ask.

        We advise you to check out the link below, which contains the Print() and OrderTrace concepts and information on how to use it.

        https://support.ninjatrader.com/s/ar...language=en_US This content is a preview of a link.support.ninjatrader.com
        support.ninjatrader.com

        Comment


          #5
          Originally posted by NinjaTrader_Helom View Post
          Hello sclay115,

          Thanks for your response.



          To understand the behavior of your NinjaScript, such as why orders are or aren’t being placed or why certain actions are happening or not, it’s essential to add Print statements throughout the script. These help reveal how the logic is evaluated by showing the values being used in real-time.


          The standard approach involves using Print and TraceOrders to debug. This guide builds on those concepts by showing how to drill down into a specific line of code and analyze the output to uncover exactly what the script is doing.

          In your prints, ensure that you print the time of the bar, and all values being compared in the condition with labels for each value and comparison operator. Also, note that the type of order used is related to the current market price. You need to ensure that the high of the previous bar plus 1 tick is greater than the current ask.

          We advise you to check out the link below, which contains the Print() and OrderTrace concepts and information on how to use it.

          https://support.ninjatrader.com/s/ar...language=en_US This content is a preview of a link.support.ninjatrader.com
          support.ninjatrader.com
          Yes, I'll add some prints, I'm familiar with them. I suppose I'm looking for more of a confirmation if the logic as I have outlined it is correct.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          42 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          65 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X