Hello,
I am looking for help creating a CountIf Function for PRT. Essentially something I can pass a Boolean condition and integer value and then check how many times the Boolean condition was true in the last integer value bars. For example,
CountIf ( Close[0] <= Close[1] , 10 ) // this ideally would return the number of times the close was below or equal to the previous low in the previous 10 bars. Possible values would be 0 to 10 with 0 being 0 occurrences and 10 being all 10 bars it was true.
Here is an early attempt
count = 0
trigger = 0
no_of_bars = 10
for count = 0 to no_of_bars do
if condition[count] then trigger += 1
next
return trigger
Thanks,
David
This will do the trick
summation[10]( Close[0] <= Close[1])
it will return the number of occurrences of the condition within parenthesis after scanning the number of bars within brackets.
Snippet added as Row 63 here Snippet Link Library
Good explanation @robertogozzi