Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to find the lowest and highest price in a range of bars

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

    Trying to find the lowest and highest price in a range of bars

    I'm trying to make my complicated strategy enter on a cross of the lowest bars in a certain number of bars (so basically in a time period).
    I'm trying to get the lowest PRICE in a certain time period and then enter if it crosses below that lowest PRICE.
    I'm not sure which part I'm getting wrong.

    1) I set that IF the current time period is the right one then my Lowbar double = LowestBar(close, in 12 bars)
    2) IF my LowBar double = the currentBar(close) then my LowPrice double = current Low[0] bar.
    3) IF the close crosses below the LowPrice then enter short.

    thanks

    #2
    Hello ezrollin,

    I would suggest to post the code you are trying to use for the 3 steps you mentioned, while that sounds like it may work I would need to see what you made to be sure of that.

    The second step you mentioned may fail if you are checking if two prices are equal, you may want to change that to less than or equal to make sure the low is set to the variable in case the equality check fails. Double numbers in C# have a hard time comparing equality, you can read about that here https://ninjatrader.com/support/help...arithmetic.htm

    Comment


      #3
      ​ ​​Click image for larger version

Name:	image.png
Views:	357
Size:	44.7 KB
ID:	1271919

      My variables

      Comment


        #4
        Click image for larger version  Name:	image.png Views:	0 Size:	40.1 KB ID:	1271924

        If during the right time span (premarket)
        then assign the lowest BAR to the premarketLOW double variable up to 12 bars back

        Comment


          #5


          Click image for larger version

Name:	image.png
Views:	355
Size:	40.6 KB
ID:	1271926


          If the premarketLOW bar is the current bar
          then assign the low PRICE of that bar to the PremarketLowPRICE double variable.

          then if close is less than the PremarketLowPRICE double then enter short.

          Comment


            #6
            Not 100% sure what you're asking, but from your OP it sounds like you're going to need some sort or MIN or MAX function. For example, to find the lowest price of the last 10 bars, you would so something like

            double lowestLastTen = MIN(Low, 10)[0]

            You can store this value in a variable and use it to compare against any other value you like. Hope that helps!
            jaybedreamin
            NinjaTrader Ecosystem Vendor - Zion Trading Algos

            Comment


              #7
              Hello ezrollin,

              The most simple change from the images that you provided is to use the MIN and MAX indicator functions instead of LowestBar or HighestBar. The lowestbar function returns a number of bars ago and not a price. The MIN and MAX functions work in the same way but return a price instead.


              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              50 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              126 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              69 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