CountIf Function

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #70806 quote
    dburghdburgh
    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
    robertogozzirobertogozzi
    Moderator
    Legend

    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
    dburghdburgh
    Participant
    Average

    Awesome. Thank you.

    #79898 quote
    GraHalGraHal
    Participant
    Legend

    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 GraHalGraHal
8 years, 1 month ago.

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