# Rules: when something is true, do something

> The when rule and its timing modifiers.

Source: https://algobarsx.com/docs/rules/

A rule is `when <condition> [modifiers]:` followed by what to do. Name a rule with `as` to read its counters later, such as `long_entry.triggers`.

```algobarsx
when long_setup.passed as long_entry every 4th:
    buy risk: risk, stop: atr(14) * 1.5, target: 3R

when starts(long_setup.passed) skip first 3 max 2 per day cooldown 30m:
    triggers += 1
    if triggers % 4 == 0:
        buy risk: 0.5%, stop: atr(14) * 1.5, target: 3R
```

Modifiers say when a rule may fire, on the rule itself, so there are no counters to build by hand:

| Modifier | What it does |
| --- | --- |
| [`every <ordinal> \| every bar`](https://algobarsx.com/docs/ref-modifiers/#ref-every) | Act on every Nth trigger, or count every bar the condition holds. |
| [`skip first <n>`](https://algobarsx.com/docs/ref-modifiers/#ref-skip) | Ignore the first N triggers, then act on every trigger. |
| [`max <n> per <period>`](https://algobarsx.com/docs/ref-modifiers/#ref-max) | Cap actions per day, session, hour or week. |
| [`cooldown <duration \| n bars>`](https://algobarsx.com/docs/ref-modifiers/#ref-cooldown) | Ignore triggers for a while after acting. |
| [`once per bar`](https://algobarsx.com/docs/ref-modifiers/#ref-once) | In tick mode, act at most once per bar. |
| [`within sessions <name>, ...`](https://algobarsx.com/docs/ref-modifiers/#ref-within) | Only trigger inside the named sessions. |
| [`from <time> to <time> [zone]`](https://algobarsx.com/docs/ref-modifiers/#ref-from) | Only trigger inside a daily time window. |
