CountIf()

View as Markdown

Definition

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

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

ParameterDescription
conditionA true/false expression
periodNumber of bars to check for the test condition

Tip: The syntax for the “condition” parameter uses lambda expression syntax.

Examples

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