**Trading -> Trading rules** in your admin dashboard.

Your challenge rules answer what a trader made: the profit target, the daily
loss, the drawdown. These answer how they made it.

A rule is three decisions. What to measure, where the line sits, and what
happens when somebody crosses it. You compose them out of a fixed catalogue of
seven patterns, each of which is a specific calculation over the trade log. You
cannot add your own pattern, because a new pattern is a new calculation and that
is something we build.

You need the `view_trading_rules` permission to open the screen and
`manage_trading_rules` to write, switch, copy or delete a rule. Without the
second you see the same screen with nothing to change.

## The rulebook

The screen opens on your rules alone, across the whole width, and opens none of
them until you pick one. Each row shows the rule's name and what it catches in
the words a trader reads, where it applies, what happens when it fires and from
which violation, how often it fired in the last 30 days and when it last did,
and whether it is on. A rule that is off reads faint, and a rule that reaches
nothing at all, because every challenge it named was deleted, carries a warning
mark.

Under the title the list counts your rules, the ones that are on and the ones
that can stop a trader. The last two are also filters: click one to see only
those, click it again to see everything. The count of violations in the last 30
days opens the list of violations on that period.

The search box finds a rule by its name, its pattern, its threshold, where it
applies or its `trule_` id. The filter menu narrows to rules that are on or
off, to one pattern, to one consequence or everything that can stop a trader, to
one width, and to the rules that reach one challenge. The same menu sorts by
the order of your rulebook, by name, by what caught most, by what fired last or
by the newest, and clicking the head of the Rule or 30 days column does the same.
The list holds fifty to a page.

J and K move through the list and Enter opens the rule they rest on. A right
click on a rule offers to open it, switch it on or off, duplicate it, see the
violations it caught, copy its name, id or link, and delete it.

## A rule

Picking a rule folds the list to a column on the left and slides the rule in
beside it. The cross or Escape folds it away again, with the list as it was.
Every rule has its own address, `/admin/trading-rules/trule_...`, with the open
tab part of it, so a link from a violation, a review flag or the command palette
opens on it. Typing a rule's name in the command palette finds it too.

The head says whether the rule is on, whether it can stop a trader, whether it
reaches nothing, and when it last fired, with a button to switch it on or off.
Under it: the pattern and when it is checked, what happens and from which
violation, where it applies and on how many accounts that can trade right now,
what it caught in the last 30 days and in total, and when it was added.

| Tab      | What it holds | Needs |
| -------- | ------------- | ----- |
| Rule     | The rule itself, to read or change, with what it does in plain words beside it | |
| Caught   | What it caught in 30 days, how much of that it acted on and on how many traders, what its violations led to, the traders it caught most in the last 90 days, and its latest 25 violations | |
| Activity | When it was made, every change saved to it and every time it was switched, with who did it and a link to the full log | `view_activity_logs` |

## Writing a rule

**New rule** opens an empty rule beside the list. Name it, pick the pattern, set
its thresholds, say where it applies and what happens, and create it with the
bar at the bottom of the screen. The rule you made then opens in the same place.
With the list narrowed to one challenge, a new rule starts on that challenge,
the same as **New rule for this challenge** on the challenge editor.

Changing a rule works the same way. Every field is a change, and the bar counts
them and saves them together, or puts them all back. Only what you changed is
sent, so a rule that was open for an hour never puts back a threshold a
colleague tuned or a switch somebody turned in the meantime. Leaving with
unsaved changes, by picking another rule, another tab or another screen, asks
first.

Beside the form, on a wide enough screen, the rule is read back as a sentence
while you write it: what it catches, when it is checked, where it applies, on
how many accounts that can trade right now, what happens then and what your team
gets to review. Under that sentence it warns about every way the rule cannot do
what it says:

- a challenge it names was deleted since,
- void was picked for a pattern that points at no single trade, so there is no
  profit to void,
- the phase it covers already caps risk per trade and refuses the order itself,
- it acts from a later violation with no window, so violations count forever,
- a more specific rule for the same pattern takes over on some phases, which it
  names,
- another rule for the same pattern applies on the same accounts beside it,
- it is off, so it applies to nobody.

The count of accounts follows the same precedence as the engine, so a rule on
every account says how many it really covers once the rules on single
challenges and phases have taken their part.

## Switching off, copying and deleting

Switching a rule on or off happens at once, from the head of the rule or a right
click in the list: that is what you do in a hurry when a rule catches the wrong
people. The switch on the Rule tab does the same as part of a save.

**Duplicate** opens a new rule filled in from another one, named as its copy and
switched off, so it changes nothing until you switch it on. That is the quick
way to give one product a stricter version of a house rule.

Deleting a rule asks first. It stops applying at once, and the violations it
already caught are kept.

## The seven patterns

| Pattern | What it measures | When it runs |
| --- | --- | --- |
| Minimum hold time | Seconds between opening and closing. Set it low to catch tick scalping | When a position closes |
| Trade burst rate | Positions opened inside a rolling minute | Before the order is placed |
| Oversized risk | The distance to the stop loss, as a share of the starting balance | Before the order is placed |
| Grid and martingale | A chain of trades that grow after each loss, and stopless positions held at once | When a position closes |
| Lot consistency | The trade furthest from the usual size, measured against the median | Hourly sweep |
| One-sided bets | The share of trades in one direction, across too few instruments | Hourly sweep |
| Single-trade target | The best trade as a share of net profit | Hourly sweep, and again at a phase pass or a payout |

Every one of them has knobs, and the editor tells you the range and the normal
value for each.

### Some detail worth knowing

**Minimum hold time only counts closes the trader chose.** A stop loss that hits
two seconds after the open is the market, and a margin call is us. Flagging
somebody for either would be accusing them of something they did not do, so only
a manual close and a take profit count.

**Hold times are measured to the millisecond**, so a floor of half a second is
a real rule rather than a rounding error. The lowest you can set is a tenth of
a second.

Below about a second, remember what the clock is measuring: we stamp the open
when our server writes the position and the close when the request to close it
arrives. A slow connection therefore reads as a longer hold, not a shorter one,
so the error only ever works in the trader's favour. Nobody is flagged for
somebody else's latency.

**Grid and martingale is two checks under one name.** The chain is a run of
trades in the same instrument and direction, each opened after the previous one
closed at a loss, each at least so much bigger than the one before. The grid is
several positions held at once in one direction without a stop loss. Either one
firing is a violation.

**Lot consistency measures against the median, not the average.** The single
huge trade this rule exists to catch drags an average towards itself, which
partly hides it. The median does not move, and the trade furthest from it is the
one the violation names.

**One-sided bets needs both halves.** Trading one direction across twenty
instruments is a bias, and that is a strategy. Trading one direction in one
instrument fifty times is a bet on a single move. Only the second fires.

**Oversized risk is the same calculation as the risk limit on your challenge
phase.** The difference is that this one you can set per rule instead of per
phase, and it can monitor or flag instead of always refusing. If a phase already
caps risk and a rule covers it too, both fire and the trader gets the stricter
of the two; the editor warns you when you build that.

## Where a rule applies

Three widths, and the most specific one wins for each pattern:

- Every account you have.
- The challenges you pick, one or several. The rule covers every phase of them.
- The phases you pick, one or several, from any challenge.

A rule on every account can leave out whole challenges or single phases: every
account except your instant funding product, or everything except funded
phases. A challenge left out whole also leaves out phases you add to it later.
A rule on chosen challenges can leave out single phases of them.

So you set a house rule once and override it where a product needs different
terms. An instant funding account does not have to be held to the same hold time
as a two step evaluation.

Narrowing overrides per pattern rather than wholesale, so a phase rule about
hold time does not switch off your house rule about martingale. A rule that
leaves a challenge or phase out does not reach it at all, so it does not
override anything there either.

### On the challenge editor

Below the phases, the challenge editor lists every trading rule that reaches
that challenge, with a chip per phase. A rule that covers more than this
challenge can be switched off per phase right there, and the change is saved
with the challenge. Switching off every phase of a rule on every account leaves
the whole challenge out. A rule that names its phases is set for exactly those
and is changed on its own screen. Where a more specific rule takes over a
pattern on a phase, the chip turns amber and the editor names the rule that
replaces it. **New rule for this challenge** opens the rule editor with the
challenge already picked.

## What happens when one fires

| Action | What the trader experiences |
| --- | --- |
| Monitor | Nothing. The violation is recorded and that is all |
| Flag for review | Nothing immediate. A review flag appears for your team |
| Block | The order is rejected, with the reason, in their own language. On a rule that runs at a phase pass or a payout, that is what gets held instead |
| Void the profit | The profit is taken off the offending trade and the balance corrected |
| Breach the account | The account is failed, its positions closed, and the run is over |

Only the actions that can work at that moment are offered. An order cannot be
refused hours after it closed, so a rule that runs on the hourly sweep will not
let you pick Block for it.

Two things about these worth saying plainly. **Void never touches a loss**,
because voiding a losing trade would be paying somebody for breaking a rule; the
original figure is kept on the trade and in the activity log. And **a trading
rule never suspends a login**. It can end a challenge account, which is a
trading decision; locking somebody out of their account is a fraud decision and
stays on the fraud screen.

## Building up before acting

A rule can act from the first violation or from the third. The ones before that
are still recorded, marked as having done nothing, and that is the point: a
trader who disputes the third finds the first two already written down. Nobody
is ambushed.

The count runs on the behaviour rather than on the rule that caught it, so
retuning a threshold or replacing a rule does not hand somebody a clean slate.
You can also count over a window rather than forever, because "three times this
week" and "three times ever" are different rules and both get meant.

**What counts as a violation is one offence, not one measurement.** The three
patterns on the hourly sweep measure the shape of a whole run rather than a
single trade, and that shape is still there an hour later. Sweeping again does
not find a second offence, so it does not record one: a run whose lot sizes
scatter is one violation until the trader trades again and the numbers move.
Otherwise a rule set to act on the third violation would reach three overnight
without anybody having placed a trade. A refused order is the other way round.
Each attempt is its own offence and each one counts.

## What it caught

**Violations** is every time a rule fired, also the times it only watched. It
opens from the count of violations in the rulebook's header and from a rule's
Caught tab, and its address is `/admin/trading-rules/violations`.

The list is newest first. Each row shows the trader and the account, the
pattern, what it led to, the rule that caught it and the instrument, what was
measured against the limit, and when. For a rule that waits for several
violations before it acts, the row also says which one of them this was. Under
the title it counts what matches, what happened in the last 7 days, what was
acted on in the last 30 days and how many traders that touched. The counts of 7
and 30 days are also filters.

The search box finds a violation by trader name or email address, account
number, the sentence the trader was given, or a `viol_`, `usr_` or `acct_` id.
The filter menu sorts newest or oldest first, and narrows to a period or to
days you choose, to one pattern, to one outcome or everything that did more than
watch, and to one rule or the rules that were deleted since. A right click on a row opens the trader, the
account, the rule or the review flag it raised, narrows the list to that trader,
account or rule, and copies what happened, its id or its link. When the list is
narrowed to one rule, one trader, one account or chosen days, a line under the
header says so, and a click on each part takes it off again. The list holds fifty to a
page, searched and paged by the server.

Picking a violation slides it in beside the list with its own address,
`/admin/trading-rules/violations/viol_...`. It shows when it happened, the
trader and the account, the outcome and its severity, then the sentence the
trader was shown with the number that was measured, the limit it broke, the
instrument and the trade. Below that: the rule as it is now, and whether a flag
was raised for your team and where it stands in the review queue.

A trader or an account deleted since keeps its name and number here, marked as
deleted, because the record of what happened outlives them.

All of the measurement is frozen at the moment it happened. Renaming a rule,
retuning it or deleting it afterwards changes none of it, because that record
is what a dispute is argued over.

The same violations appear in two more places, so you find them whether you went
looking or not: on the trader's profile, beside the fraud flags, and on the
trading account, next to the rules that were in force on it.

## What the trader sees

Their account page lists the rules they are actually held to, in the same words
your editor showed you, along with anything of theirs those rules have recorded.

**Rules set to monitor are not shown to them.** Monitoring is how you try a
threshold out, and a threshold still being tuned is not yet a rule anybody is
bound by. If setting a rule to monitor published it, you could not evaluate a
detector without announcing it, and in practice you would skip that step and
enforce from day one, which is worse for the trader than not knowing.

**Violations building towards a consequence are shown.** A rule that acts on the
third violation shows the trader the first two, which is what stops the third
being a surprise. So is anything that already happened to them: a refused order,
a voided profit, a failed account, even if you have since deleted the rule.

## If you ticked the old boxes

Your challenge phases used to carry a row of prohibited strategy checkboxes.
They never detected anything: the platform stored the tick and traded on as
before. Anything you had ticked is now a rule on this screen, at the threshold
you typed where you typed one and at ours where you did not.

**They arrive switched off.** Those boxes changed nothing for as long as they
existed, so turning them on for you would start flagging traders for behaviour
they were effectively allowed until that moment, at a number you never chose.
Open each one, check the threshold, and switch it on when it says what you meant.

Three of the old boxes have no rule waiting. Gambling was always the risk per
trade on the phase itself, which has been enforced all along. Reverse trading is
picked up by the fraud screen, which looks across accounts, where it actually
happens. Latency arbitrage is gone: we are the broker, so our feed is the price,
and the only thing to arbitrage against is our own lag, which is our bug to fix.

## Starting safely

Set a new rule to monitor and leave it a week. The list shows how often each rule
fired in the last 30 days and when it last did, and its Caught tab shows who it
caught, so you can see what it would have caught before it catches anybody. Turn
it up once the number looks like what you expected.

Switching a rule off keeps it and its history and stops it applying. Deleting it
keeps the violations it already caught, so a trader disputing one still has the
record and so do you.

## In the older designs

A firm on Propper - OG or Tactical keeps the screens it launched with. Trading
rules there is a page with three counters and a table of rules, each with a
switch, an edit button and a delete button. A rule is written on a page of its
own at `/admin/trading-rules/create` or `/admin/trading-rules/trule_.../edit`,
with the same warnings beside the form and a save button at the bottom. A link
to a rule, from the command palette or a violation, opens that editor. There is
no Caught or Activity tab and no duplicate.

Violations there is one table with filters for the pattern, the outcome and the
days, and a row opens the measurement in a dialog. A link to a single violation
opens that table.