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

Identify high and lows

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

    Identify high and lows

    Hey,

    How do I identify previous and future highs and lows in a UniRenkochart
    Because I want to check if the bars are making higher highs and simultanously higher lows and vise versa. Even when it is only a "small" und high/low.

    So I have to check the current state of a new formed high that was established to the previous high and also for lows.

    If this is possible can I also plot a circle shape at this specific high/low and reference exact this Position for further processing?

    Thanks
    Last edited by anmu1990; 11-26-2019, 06:53 AM.

    #2
    Hello anmu1990,

    You could use HighestBar and LowestBar for this type of use case, these methods take a series like the High or Low series and check what the highest/lowest bars were withing a period.




    This returns a BarsAgo which could be used to collect the prices as shown in the examples.


    If you want to actually make a condition checking for the highest high you could do that by creating a variable and checking if the price is higher than the variable, if so reset the variable to the price. Doing this over the period you want to check will accumulate the highest value, the same could be accomplished for the lowest value.

    For plotting I would suggest looking at the help guide here: https://ninjatrader.com/support/help...t8/drawing.htm

    The drawing objects can be used to mark the chart with the prices/BarsAgo found from the methods above.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hey,

      thank you for your answer. I will have a look on it.

      Furthermore, here a image of what I am searching for.
      + Compare the most recent High/low (dot price) with the previous one to know if it made a higher high and a lower low.

      The problem I see with HighestBar is that I have to define a period. But as you can see if the period is too small and it haven't made a "real" high peak it
      would take the highest price of the bars in the period. E.g. if the price would only fall in the period it takes the first bar with the highest price. but that not what I looking for.

      Your second recommendation could be used I think?
      e.g. if I search for a new established High it would mean that the high of the previous and the following bar is smaller than the bar with the high?
      If this is met I save this price in a "list" and compare it with the new high that will eventually appear with the same condition as mentioned before, right?

      Comment


        #4
        Hello anmu1990,

        Are you just looking for the high/low of the current session or did you want to configure the amount of time that is included in the search?

        For the current high/low of the session you can just use the CurrentOHL indicator: https://ninjatrader.com/support/help...sub=currentday

        If the indicator does not work for the use case an accumulation to variables could likely work.

        e.g. if I search for a new established High it would mean that the high of the previous and the following bar is smaller than the bar with the high?
        You wouldn't need to check any of the previous highs if you are just trying to get the current high. A quick example of what I meant would be:

        Code:
        //variables
        private double myHighPrice = 0; 
        
        
        if(myHighPrice < Close[0])
        {
            myHighPrice = Close[0];
        }
        This just sets a new high price each time the price is higher than what was previously stored. This would accumulate a new highest price from when the logic was run which could include all of historical data loaded.

        Lowest would be the same concept except you would need to define the variable with a high starting value such as the current Close or 9999 to make sure it sets a new lowest value when running.

        If this is met I save this price in a "list" and compare it with the new high that will eventually appear with the same condition as mentioned before, right?
        A list wouldn't be needed, just storing a double variable to make sure the price is the highest. If you wanted to do a comparison over a specific period to get a trend you could just use the close and bars ago:

        Code:
        if(Close[0] > Close[1] && Close[1] > Close[2])

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello all,
          I'm coding (manually) an algorithm that requires to find Highs and Lows, as asked, previously.

          After coding this on my own, I had to come here because of a problem with the results it shows.

          But when reading here, my code is the same as here. So, I'm wondering where the problem is:

          Here's what I did:
          - I declared the variable as above (the same place where all variables are usually declared - I have different type of variables (private/public/static/double/string/bool/int)
          - My code is now copied from the example above (I was trying to remove all possible mistake from my own)
          - I printed the results at each steps of the sequence to the output window to see what is hapenning and here's what I see:

          A print line (to the output window) at the very beginning of the code shows that the variable has already an unknown value assigned: (3421,25)
          The futures market is at 3412, at the time I'm writing this.

          I had a look in the past close candles and no candle has a close at this exact level. So, I'm wondering where this 3421,25 is taken.

          Here's my code:
          Code:
          public class Example : Strategy
          {
               private double myHighPrice = 0;
          }
          
          ........
          
          protected override void OnBarUpdate()
          {
               if (BarsInProgress != 0)
               return;
          
               if (CurrentBars[0] < 1)
               return;
          
               ClearOutputWindow();
          
               Print("myHighPrice = " + myHighPrice.ToString());
          }
          .............
          That's mostly what, I think, it is required to say as of now.

          Thanks in advance.
          Last edited by Bricolico; 10-07-2020, 08:44 PM.

          Comment


            #6
            Hello Bricolico,

            From the given details there is not enough information to say why that value was seen. If it was a price value and not 0 that would be from you setting the value somewhere in your logic. If you can provide a more complete sample we may be able to gather more details from that.

            One note here is that you are clearing the print on every bar, so you will only see realtime or the most recent print. You may want to remove ClearOutputWindow(); and see if you have a more understandable result.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse,
              I realised today that the whole chart seems to be analysed when the Strategy opens. As I have a 7-day chart settled in minutes, it shows me the highest point of the whole 7 days. I thought the data analysed would begin at the time I start the strategy but it doesnt seems to be like that. As I dont want to define a range, this doesnt seems to fit with what I want to do.

              But as I was searching for something else, I found that the SWING indicator (in the indicator section) could maybe fit with the way I'm working. I'll have to work with that indicator for a few days to see how I can use it properly in a coded context but at first, this seems to respond very nicely to what I was searching.

              Thanks for your time. Always a very supportive forum and fast responses. It is very appreciated.

              Thank you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by WHICKED, Today, 12:56 PM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cre8able, Today, 01:16 PM
              0 responses
              2 views
              0 likes
              Last Post cre8able  
              Started by chbruno, 04-24-2024, 04:10 PM
              2 responses
              47 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by WHICKED, Today, 12:45 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by samish18, Today, 01:01 PM
              0 responses
              6 views
              0 likes
              Last Post samish18  
              Working...
              X