# Hurst Regime Switch

> Hurst Regime Switch is a strategy that trades EURUSD on 4-hour bars. It holds at most 1 open trade.

Source: https://algobarsx.com/docs/ex-49-hurst-regime-switch/

```algobarsx
strategy "Hurst Regime Switch"
    market: EURUSD
    bars: 4h
    max_open: 1

input window = 200

h = hurst(close, window)
trending = h > 0.55
mean_reverting = h < 0.45
z = zscore(close, 50)

when trending and crosses_above(close, kama(close, 20)):
    buy risk: 1%, stop: 2 * atr(14), target: 3R, tag: "trend"

when mean_reverting and z < -2:
    buy risk: 0.5%, stop: 1.5 * atr(14), target: mean(close, 50), tag: "revert"

when mean_reverting and z > 2:
    sell risk: 0.5%, stop: 1.5 * atr(14), target: mean(close, 50), tag: "revert"
```
What this script says

Hurst Regime Switch is a strategy that trades EURUSD on 4-hour bars. It holds at most 1 open trade.

You can change one input: `window` (default 200).

It calculates `h` as the hurst (source the close, length `window`), `trending` as whether `h` is above 0.55, `mean_reverting` as whether `h` is below 0.45 and `z` as the 50-bar z-score of the close.

When `trending` and the close crosses above the 20-bar KAMA of the close, it buys at market, risking 1% of the balance, with a stop 2 × the 14-bar ATR from the entry, with a target 3R from the entry and tagged "trend".

When `mean_reverting` and `z` is below -2, it buys at market, risking 0.5% of the balance, with a stop 1.5 × the 14-bar ATR from the entry, with a target at the 50-bar average of the close and tagged "revert".

When `mean_reverting` and `z` is above 2, it sells at market, risking 0.5% of the balance, with a stop 1.5 × the 14-bar ATR from the entry, with a target at the 50-bar average of the close and tagged "revert".
