AlfyParticipant
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.
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.
AlfyParticipant
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?
It already turns negative numbers into positive ones with ABS() in line 3.
AlfyParticipant
Average
Oh thanks so much for explaining that!