Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Counter when Bar Creates new High

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

    Counter when Bar Creates new High

    I would like to write an indicator with the following rule set but I'm not sure how to proceed.
    • After price has crossed an EMA of 9, I would like to Label this bar with a new High ( with letter A) .....
    • If another candles closes Higher I would like to have that previous Higher Label removed and to have the new candle labeled as HIgh. (Old label moves to this new Candle with Letter A)
    How would this be possible?

    #2
    Hello r3n3v,

    Thanks for your post.

    When you use the Draw methods, and use the same "Tag name", when a new draw object is added with the same tag name, the first draw object is automatically removed.
    Reference: https://ninjatrader.com/support/help...?draw_text.htm

    You would want to check to see if the High[0] price is greater than the EMA(9)[0] and if so then check to see if it is higher than the previous high value that you would want to save into a variable. For example, create a variable like: private double prevHigh = 0;

    in OnBarUpdate():

    if (High[0] > EMA(9)[0] && High[0] > prevHigh) // is the high greater than the EMA and is the high greater then the previouis high?
    {
    prevHigh = High[0]; // save the new high
    Draw.Text(this, "my tag", "A", 0, High[0] + 3 * TickSize, Brushes.Red); // place a Red A 3 ticks above the new high
    }


    The above would work until you reach the highest high, above the EMA(9).

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

    Comment


      #3
      Ok. Thanks for your answer. This worked! However I want to leave this marker on for every time it rotates up and down the EMA. Meaning If price crosses down the EMA I want to leave that A-Label on that candle.

      Comment


        #4
        Hello r3n3v,

        Thanks for your reply.

        So that will require the use of a counter which is just an int type variable.

        Each time the price crosses above the EMA you would increment the counter. You would then add the counter to the tag name to create a tag name that will remain the same until the price crosses above the EMA again. That way the last one placed will remain and a new one will be created on the next cross.

        Create a privte int like private int myCounter = 0;

        In OnBarUpdate()

        if (CrossAbove(Close, EMA(9), 1))
        {
        myCounter++; // increment the counter
        prevHigh = 0; // reset the high for the next excursion above the EMA.
        }


        Then

        if (High[0] > EMA(9)[0] && High[0] > prevHigh) // is the high greater than the EMA and is the high greater then the previouis high?
        {
        prevHigh = High[0]; // save the new high
        Draw.Text(this, "my tag"+myCounter, "A", 0, High[0] + 3 * TickSize, Brushes.Red); // place a Red A 3 ticks above the new high
        }

        Comment


          #5
          Hello Paul,

          One last thing.
          When I do this for the Low Side The text doesn't come up. It's the exact opposite of the High Side. Any ideas?

          Comment


            #6
            Hello r3n3v,

            Thanks for your reply.

            Make sure you are using a different counter and that the tag name is different.

            If in doubt, post that part of your code.

            Comment


              #7
              Code:
              if (Low[0] < EMA(9)[0] && Low[0] < prevLow)
              {
              prevLow = Low[0]; // save the new high
              Draw.Text(this, "mytagB" + myLowCounter, "B", 0, Low[0] - 3 * TickSize, color1);
              }
              this is what im using...with a separate variable..

              Comment


                #8
                Hello r3n3v,

                Thanks for your reply.

                Do you see any errors in the "log" tab when you run the indicator?

                If no errors then I would suggest adding a print statement to verify that the condition is becoming true.

                For example, in side the { }:

                Print (Time[0]+" Low[0] = "+Low[0]+" EMA9[0] = "+EMA(9)[0]);

                The print statement sends its output to the NS window so before running the script make sure to open the window New>Ninjascript output window.

                If you do not see a print then the if condition is not becoming true.

                If you do see the prints then I would next look at the value of color1 and the value of myLowCounter

                Comment


                  #9
                  No no errors..
                  Can you please test this on your end?

                  Comment


                    #10
                    Hello r3n3v,

                    Thanks for your reply.

                    If you want to attach your script I can test however, have you tried using the print statements I advised and if so what results did you get?

                    Comment


                      #11
                      [QUOTE = NinjaTrader_PaulH; n1172608] Hola, r3n3v:

                      Gracias por tu respuesta.

                      Sin embargo, si desea adjuntar su script, puedo probarlo, żha intentado utilizar las declaraciones impresas que le aconsejé y, de ser así, qué resultados obtuvo?

                      [/ QUOTE]

                      Hello, I can't get the maximum and the minimum of an ocsilator .. I tried but it appears on the graph instead of the indicator .. you have an example .. once having the highest histogram, get -10% of the histogram (that value We will call it A for the example) .. and to choose a minimum it must meet two conditions, one must be less than "A" and a minimum of 4 histogram .. and the rise the same but inverse .. if (difewo> 0) else
                      Last edited by TraderElegante; 10-24-2021, 07:24 AM.

                      Comment


                        #12
                        Hello TraderElegante,

                        Thanks for your post.

                        I am confused by your post, can you clarify how it relates to the topic title of "Counter when Bar Creates new High".

                        Did you mean to reply to a different topic?

                        Are you creating an indicator or a strategy?

                        I suspect that you should be creating your own topic in the correct forum (indicator or Strategy) to avoid any further confusion.
                        I can help you with that if you can clarify.



                        Comment


                          #13
                          Originally posted by NinjaTrader_PaulH View Post
                          Hello TraderElegante,

                          Thanks for your post.

                          I am confused by your post, can you clarify how it relates to the topic title of "Counter when Bar Creates new High".

                          Did you mean to reply to a different topic?

                          Are you creating an indicator or a strategy?

                          I suspect that you should be creating your own topic in the correct forum (indicator or Strategy) to avoid any further confusion.
                          I can help you with that if you can clarify.


                          I am creating an indicator .. My doubt was that I want the maximum of an ocsilator .. from there take the -10% to take a minimum that is less or break the -10% and a minimum of 4 histogram .. how could I do it would be with an intende counter of various ways and I couldn't ..

                          Comment


                            #14
                            Originally posted by NinjaTrader_PaulH View Post
                            Hello TraderElegante,

                            Thanks for your post.

                            I am confused by your post, can you clarify how it relates to the topic title of "Counter when Bar Creates new High".

                            Did you mean to reply to a different topic?

                            Are you creating an indicator or a strategy?

                            I suspect that you should be creating your own topic in the correct forum (indicator or Strategy) to avoid any further confusion.
                            I can help you with that if you can clarify.


                            Attached an example in an image would be greater or less than -10% and a minimum of 4 bars

                            Comment


                              #15
                              Hello TraderElegante,

                              Thanks for your reply and screenshot.

                              If I understand correctly, when your histogram creates a new high you want to then start counting bars when the histogram exceeds the +/- 10 % of that high?

                              If that is correct, what part are you having difficulty with? What would be your specific question?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              577 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X