# Performance Throttle

> Performance Throttle is a strategy that trades EURUSD on 30-minute bars. It holds at most 1 open trade and stops for the day after losing $500.

Source: https://algobarsx.com/docs/ex-44-performance-throttle/

```algobarsx
strategy "Performance Throttle"
    market: EURUSD
    bars: 30m
    max_open: 1
    max_daily_loss: $500

input base_risk = 1%

week = history.this_week
recent_r = trades.closed(tag: "trend").keep_last(10).map(t => t.r).sum()
risk_scale = if week.profit_factor < 1 or recent_r < -3 then 0.5 else 1.0

when crosses_above(ema(close, 20), ema(close, 50)):
    buy risk: base_risk * risk_scale, stop: 25 pips, target: 2R, tag: "trend"

on exit(trade):
    if trade.reason == "stop" and trade.r <= -1:
        log "Stopped out; recent R total is {recent_r:0.0}"
```
What this script says

Performance Throttle is a strategy that trades EURUSD on 30-minute bars. It holds at most 1 open trade and stops for the day after losing $500.

You can change one input: `base_risk` (default 1%).

It calculates `week` as `history.this_week`, `recent_r` as `trades.closed(tag: "trend").keep_last(10).map(t => t.r).sum()` and `risk_scale` as 0.5 when `week.profit_factor` is below 1 or `recent_r` is below -3, otherwise 1.0.

When the 20-bar EMA of the close crosses above the 50-bar EMA of the close, it buys at market, risking `base_risk` × `risk_scale` of the balance, with a stop 25 pips from the entry, with a target 2R from the entry and tagged "trend".

When a trade closes, it checks whether `trade.reason` is "stop" and `trade.r` is at or below -1 and, if so, logs "Stopped out; recent R total is {recent_r:0.0}".
