• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I determine if a bar closes at the top 25% of the bars range?

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

    How do I determine if a bar closes at the top 25% of the bars range?

    I guess I put the entire question in the title.

    I've been attempting to use:


    if(Close[0] >= (.75 * High[0]))

    but that doesn't seem to work at all....

    #2
    Originally posted by Darth_Trader View Post
    I guess I put the entire question in the title.

    I've been attempting to use:


    if(Close[0] >= (.75 * High[0]))

    but that doesn't seem to work at all....
    Code:
    if(Close[0] >= 0.25 * Low[0] + (.75 * High[0]))

    Comment


      #3
      I'm sorry.

      I'm not sure how that makes any sense.

      I want the code to determine if the bar closes at the top 25% of it's range do X. Which is why I was using:

      if(Close[0] >= (.75 * High[0]))

      But it doesn't seem to work.

      I'm not sure how adding .25* Low to the .75 of the high does what I want it to do.

      Comment


        #4
        Originally posted by Darth_Trader View Post
        I'm sorry.

        I'm not sure how that makes any sense.

        I want the code to determine if the bar closes at the top 25% of it's range do X. Which is why I was using:

        if(Close[0] >= (.75 * High[0]))

        But it doesn't seem to work.

        I'm not sure how adding .25* Low to the .75 of the high does what I want it to do.
        So are you arguing the elementary algebra or the the philosophical difference in your understanding?
        Last edited by koganam; 05-31-2015, 10:36 AM.

        Comment


          #5
          Wow, well...I wasn't arguing anything.

          I just didn't feel from your answer, that you understood my question...so I thought I'd clarify.

          I didn't expect arrogant hostility...

          So, to make sure...I actually put your code changes in...and they still didn't work.

          Comment


            #6
            If print statements to the output window were involved, we could see what was going on.

            Take an imaginary ES bar, high = 2118, low = 2111

            print 2118 * .75

            we see that is 1588.50.. and we see why the original formula doesn't work. This is just looking at a bar with high of 2118 and low of 0.00.


            Looking at Koganam's formula -

            print 2118 * .75 = 1588.5
            print 2111 * .25 = 527.75
            print 1588.5 + 527.75 = 2116.25

            I would have done it a little bit longer way

            print 2118- 2111 = 7
            print 7 * .75 = 5.25
            print 2111 + 5.25 = 2116.25

            so both way are valid.

            if the close is > 2116.25 then you have achieved .75% of the high.


            So can you put in some print statements and see why/what isn't "Working"?

            The output window is under Tools.

            The Print command would look like this officially:

            Print ( "High[0]=" + High[0] + " High[0]*.25=" + High[0]*.25 );

            use the + command to concatenate items.

            Comment


              #7
              if(Close[0] >=Low[0] + 0.75*(High[0] - Low[0]))


              and make sure calculate on bar close is set to true

              Comment


                #8
                Thank You!

                I really appreciate the explanation Sledge. I now understand completely and this will help a ton in the future.

                Thank you too GKonheiser, what you posted worked precisely how I intended.

                Thank you too Koganam for the attempt. However, not explaining anything and then giving me a problem when I asked a clarification question made you come across as less friendly to me than you probably really are. I now understand what you were getting at although GKonheiser nailed it.

                Comment


                  #9
                  Originally posted by Darth_Trader View Post
                  Wow, well...I wasn't arguing anything.

                  I just didn't feel from your answer, that you understood my question...so I thought I'd clarify.

                  I didn't expect arrogant hostility...

                  So, to make sure...I actually put your code changes in...and they still didn't work.
                  I have looked at my answer again, and agree with you that it sounds hostile. I apologize. I intended to put a smiley there, which I forgot, but I do not think that really makes a difference.

                  Further, here it is. You asked for a Close that is at or above 75% of the range.

                  So we translate that into math. The candle starts (well, is lowest) at its low, so we add 75% of the range to the Low.

                  That is how we come up with:

                  Code:
                  Close[0] >= Low[0] + 0.75 * (High[0] - Low[0])
                  or alternatively:
                  Code:
                  Close[0] - Low[0] >= 0.75 * (High[0] - Low[0])
                  if initially written as a ratio.

                  They both resolve to:
                  Code:
                  Close[0] >= 0.25 * Low[0] + 0.75 * High[0];
                  How exactly do you mean "... and they still didn't work". The math does not lie. If what you see is not what you expect, you will need to look elsewhere in your code to determine why.
                  Last edited by koganam; 05-31-2015, 10:47 AM.

                  Comment


                    #10
                    Hi,

                    Yeah, I did kinda feel it was grouchy, however it WAS like 3am here Hawaii time....so could have been me too...lol. I'm cool. A smiley probably would have made me consider it tongue-in-cheek....it's all good. I'm very easy

                    Thanks for explaining; I see how it should work, but honestly it was coloring every candle instead of only the ones that were closing above 75% of the candle range.

                    This doesn't mean I didn't do it wrong, mind you...I'm still coming to terms with gathering the syntax and manipulating data in this language/protocol.

                    But like I mentioned before, GKonheiser's version worked precisely when plugged in. So I just turned it over for the bottom 25% bars and viola! Got what I needed.

                    Your version probably works great, but understanding that if I want a ratio of the entire candle, the (High[0] - Low[0]) seems very easy to remember.

                    Comment


                      #11
                      Originally posted by Darth_Trader View Post
                      ... it was coloring every candle instead of only the ones that were closing above 75% of the candle range.
                      Which probably means that you were using CalculateOnBarClose = false. Not that that is impossible to code up. It just means that you have to specify colors for both when the condition is true and when it is false, and use the correct color as necessary.

                      Look again and you will see that the condition will always be true at the start of a bar, so if COBC = false, every bar will meet the condition at the start of the bar. (At the start of the bar, the Close is necessarily and axiomatically, 100% of the range).

                      Comment


                        #12
                        You know what?

                        I think you were precisely correct. That way does give me a bit more flexibility...and making sure I understand the calculate on close T or F seems kinda like having the safety on or off...LOL

                        I better figure that out quick.

                        Comment


                          #13
                          @ Darth_Trader or anyone else:

                          Would you be so kind to attach the completed indicator. I've been looking for this and am not much of a skilled coder. I would really appreciate it, thanks!

                          Comment


                            #14
                            Here it is

                            I hope it's what you are wanting.

                            All it does it color the bars that close at the X top of the range or X bottom of the range (adjustable).

                            And you can choose the color of the up and down bars.

                            Hope you like it.

                            - D
                            Attached Files

                            Comment


                              #15
                              Thanks Darth_Vader! Works like a charm, appreciate it.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kabott, Today, 10:47 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post kabott
                              by kabott
                               
                              Started by bc24fl, Today, 10:00 AM
                              3 responses
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by TonyParisi, Today, 07:38 AM
                              2 responses
                              11 views
                              0 likes
                              Last Post TonyParisi  
                              Started by fx.practic, Today, 10:03 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post fx.practic  
                              Started by traderpards, 12-12-2018, 01:15 PM
                              6 responses
                              154 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Working...
                              X