NinjaScript > Language Reference > Data >

CountIf()

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
Counts the number of occurrences of the test condition over the look back period expressed in bars. This method will NOT work on multi-series strategies.
 

Method Return Value

An int value representing the number of occurrences found

 

Syntax
CountIf(Condition condition, int period)
 
The syntax for condition must be written in the following manner:

delegate { return your true/false condition;}
 

Parameters

condition

A true/false expression

period

Number of bars to check for the test condition

 

 

Examples

// If in the last 10 bars we have had 8 up bars then go long
if (CountIf(delegate {return Close[0] > Open[0];}, 10) > 8)
    EnterLong();