CountIf Function

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #70806 quote
    dburgh
    Participant
    Average

    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

    #70807 quote
    robertogozzi
    Moderator
    Master

    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.

    #71001 quote
    dburgh
    Participant
    Average

    Awesome. Thank you.

    #79898 quote
    GraHal
    Participant
    Master

    Snippet added as Row 63 here Snippet Link Library

    Good explanation @robertogozzi

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

CountIf Function


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
dburgh @dburgh Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by GraHal
7 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/18/2018
Status: Active
Attachments: No files
Logo Logo
Loading...