Narrow range counter

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #182705 quote
    Alfy
    Participant
    Average

    Good morning guys, i hope you are all keeping well. I wondered if anyone could help me. Im looking to build a counter that counts for how many days todays range is the narrowest. I describe range as either open versus close or high-low i don’t mind which. So for example, if todays range was 50 cents and it was the narrowest range of the last 3 days then the answer would be 3. Thanks in advance for any help you can offer.

    #182710 quote
    robertogozzi
    Moderator
    Master

    There you go:

    N       = 500      //LookBack period
    //MyRange = range
    MyRange = abs(open - close)
    Result = 0
    FOR i = N DOWNTO 2
       IF MyRange = lowest[i](MyRange) THEN
          Result = i
          break
       ENDIF
    NEXT
    RETURN i AS "Count"

    You can select the type of range in lines 2 and 3, just comment out the one you don’t want to use (now it’s OPEN-CLOSE).

    N is the lookback period to scan, 500 hundred bars is quite high, with more than 1K units it could be slow.

    Using the indicator’s settings you may make it an histogram.

    Alfy thanked this post
    #182719 quote
    Alfy
    Participant
    Average

    Hi Roberto, first of all thank you. The indicator works well for high -low but with open-close i forgot that some days the open close would be negative numbers. Is there a way of normalising the open close numbers so that all days are positive and then the indicator picks up the lowest number irrespective of whether the open close difference was up or down on the day please?

    #182725 quote
    robertogozzi
    Moderator
    Master

    It already turns negative numbers into positive ones with ABS() in line 3.

    Alfy thanked this post
    #182727 quote
    Alfy
    Participant
    Average

    Oh thanks so much for explaining that!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Narrow range counter


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Alfy @alfy Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Alfy
4 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/02/2021
Status: Active
Attachments: No files
Logo Logo
Loading...