Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy when bar closes over the high of the recent low bar

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

    Buy when bar closes over the high of the recent low bar

    Hi
    I'm new to the forum and new to the Strategy Builder, but I have read and studied several guides and video tutorials.

    I try to build a strategy in Strategy Builder, that buys when the first bar closes over the high of the recent low bar.

    First I've tried to build the strategy of the Swing indicator, but I could not make it work, because I failed to define high of the low bar. Then I tried to follow the forum example where the low bar is coloured https://ninjatrader.com/support/foru...-or-x-bar-high

    However, eventhough I succeded by defining the low bar, and buy on the next bar that closes over the high of the recent low bar, I fail to make the next buy wait for a new low after the buy either makes it takeprofit or stoploss. The strategy will buy on the higher close. Instead it shall wait on a new low is maded.


    Code:
    CodeCode2
    Chart
    Caption


    Can it be done - either with this code, or by using the swin indicator? Can you help? :-)

    Best regards


    #2
    Hello KKJtrader1973,

    I'm not clear on the condition you are wanting "when the first bar closes over the high of the recent low bar".

    You are wanting when the current price (Close of 0 bars ago) crosses above the high price of the bar with the lowest low within a certain number of bars?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      Thank you for your quick reply.

      I have tried to illustrate the strategy. Buy of a new low

      Comment


        #4
        Hello KKJtrader1973,

        What are the rules that made this image?

        Think of this how a computer would think of this.

        What rule makes a "Low bar". Is this the bar with the lowest low in 5 bars? Is this the low the day?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea

          My code is set for 14 bars, however, when I use it, it will automaticly open a new buy order, after it has taken profit, instead of waiting until the chart makes a new low. I was wondering, if there were and indicator (swing?) I could use to make this scenario happend?

          Comment


            #6
            Hello KKJtrader1973,

            To understand the behavior of your current conditions Print() the time of the bar and all values used in the condition along with labels showing what each value is.

            Below is a link to a forum post that demonstrates using Print() and TraceOrders to understand behavior.



            So you want the condition to evaluate as true when the current price (Price -> Close) is greater than the high (Price -> High) of the bar that has the lowest low in the last 14 bars, is this correct?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea

              Thanks for your reply.

              I have used print, but unfortunately I have not managed to get my code to stop trading every time the condition is met. Is there a method/code which stops trading until there is a new low or high.

              Ex.
              Close [0] <MAX (Low, Lookback) [10] -> Enter Short

              When the trade either takes profit or is stopped out then I want a code/method that waits(/halts the code) until a new low or high is established.

              Sorry I can not figure it out.

              Comment


                #8
                Hello KKJtrader1973,

                You can use a bool that is set to true when the condition is true. The bool must be false in the condition to place an order.

                The exitOnCloseWait bool in the PreventEntryAfterExitOnCloseExample linked below does something similar.
                NinjaTrader Community, A common inquiry is that the Exit on close didn't work in a NinjaScript Strategy because there is a position after the exit on close should have occurred. When viewing the log we often find that the Exit on close does indeed exit the position shortly before the end of the session (based on the Exit on


                It sounds like you are confirming you want a condition 'when the current price (Price -> Close) is greater than the high (Price -> High) of the bar that has the lowest low in the last 14 bars'.

                You can use LowestBar() to find the bar with the lowest low in 14 bars.


                Once you have that bar number you can get the High of that bar by subtracting the bar number from currentBar.

                High[CurrentBar - lowestBarFound]

                And compare the Close[0] to be greater than High[CurrentBar - lowestBarFound].

                To allow trades again, set the bool back to false.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

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