CountIf()

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Common > Analytical >

CountIf()

Previous page Return to chapter overview Next page

Definition

Counts the number of instances the test condition occurs over the look-back period expressed in bars.

 

Note: This method does NOT work on multi-series strategies and indicators.

 

 

Method Return Value

An int value representing the number of occurrences found

 

Syntax

CountIf(Func<bool> condition, int period)
 

Parameters

condition

A true/false expression

period

Number of bars to check for the test condition

 

 

Tip:  The syntax for the "condition" parameter uses lambda expression syntax

 

 

Examples

ns


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