Rules are the boolean building blocks of a ta4j strategy. Each rule implements theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ta4j/ta4j/llms.txt
Use this file to discover all available pages before exploring further.
Rule interface and returns true or false when evaluated at a given bar index.
The Rule interface
tradingRecord. Indicator-based rules ignore it.
Boolean combinators
EveryRule exposes four fluent combinators that each return a new Rule:
ChainRule — sequential rule evaluation
ChainRule requires an initial rule followed by one or more ChainLink steps. Each step must be satisfied within a configurable number of bars after the previous one fires.
Indicator-based rules
Crossover rules
Crossover rules
Rules that fire when one indicator crosses another.
CrossedUpIndicatorRule
CrossedUpIndicatorRule
Satisfied when
indicator1 crosses above indicator2 (or a fixed threshold).CrossedDownIndicatorRule
CrossedDownIndicatorRule
Satisfied when
indicator1 crosses below indicator2 (or a fixed threshold).Comparison rules
Comparison rules
Rules that compare an indicator’s value against a threshold or another indicator.
OverIndicatorRule
OverIndicatorRule
Satisfied when the indicator is strictly greater than the threshold or second indicator.
UnderIndicatorRule
UnderIndicatorRule
Satisfied when the indicator is strictly less than the threshold or second indicator.
OverOrEqualIndicatorRule
OverOrEqualIndicatorRule
Satisfied when the indicator is greater than or equal to the threshold.
UnderOrEqualIndicatorRule
UnderOrEqualIndicatorRule
Satisfied when the indicator is less than or equal to the threshold.
IsEqualRule
IsEqualRule
Satisfied when two indicators produce equal values at the current bar.
InPipeRule
InPipeRule
Satisfied when the indicator value falls between
lower and upper (inclusive).InSlopeRule
InSlopeRule
Satisfied when the indicator’s slope (change from the previous bar) falls within
[minSlope, maxSlope].Trend rules
Trend rules
Rules that evaluate multi-bar directional behavior.
IsRisingRule
IsRisingRule
Satisfied when the indicator has been rising for the last
barCount bars.IsFallingRule
IsFallingRule
Satisfied when the indicator has been falling for the last
barCount bars.IsHighestRule
IsHighestRule
Satisfied when the indicator’s current value is the highest over the last
barCount bars.IsLowestRule
IsLowestRule
Satisfied when the indicator’s current value is the lowest over the last
barCount bars.Timing rules
Timing rules
Rules that control when a signal may fire based on elapsed bars, time of day, or position duration.
WaitForRule
WaitForRule
After
rule fires, prevents it from firing again for numberOfBars bars.JustOnceRule
JustOnceRule
Wraps another rule so it can only fire once per backtest run.
OpenedPositionMinimumBarCountRule
OpenedPositionMinimumBarCountRule
Satisfied only after the current position has been open for at least
barCount bars.OpenPositionDurationRule
OpenPositionDurationRule
Satisfied when the current open position has been held for a specified number of bars. Useful for time-based exits.
DayOfWeekRule
DayOfWeekRule
Satisfied on specific days of the week.
HourOfDayRule
HourOfDayRule
Satisfied during specific hours of the day (UTC by default).
MinuteOfHourRule
MinuteOfHourRule
Satisfied at specific minutes within the hour.
TimeRangeRule
TimeRangeRule
Satisfied when the bar’s end time falls within a specified time-of-day range.
Other rules
Other rules
BooleanIndicatorRule
BooleanIndicatorRule
Wraps a
Boolean-typed indicator as a Rule.BooleanRule
BooleanRule
A constant rule that always returns the provided value. Useful as a placeholder or in tests.
FixedRule
FixedRule
Returns a pre-defined sequence of
true/false values by bar index. Useful for unit tests.VoteRule
VoteRule
Satisfied when at least
requiredVotes of the supplied rules are satisfied simultaneously.AndWithThresholdRule / OrWithThresholdRule
AndWithThresholdRule / OrWithThresholdRule
Threshold-aware AND/OR combinators that also incorporate a numeric threshold parameter alongside the boolean evaluation.
MomentumStateRule
MomentumStateRule
Satisfied when a momentum indicator is in a specified state (e.g., bullish or bearish momentum phase).