# Hedged Breakout

> Hedged Breakout is a strategy that trades EURUSD on 1-hour bars. It holds at most 2 open trades (1 per side) and hedges on an opposite signal.

Source: https://algobarsx.com/docs/ex-46-hedged-breakout/

```algobarsx
strategy "Hedged Breakout"
    market: EURUSD
    bars: 1h
    opposite: hedge
    max_open: 2
    max_open_per_side: 1

when crosses_above(close, highest(high, 24)[1]):
    buy risk: 0.5%, stop: 40 pips, target: 80 pips, tag: "up"

when crosses_below(close, lowest(low, 24)[1]):
    sell risk: 0.5%, stop: 40 pips, target: 80 pips, tag: "down"

for trade in trades.open():
    if trade.bars_open >= 48:
        close trade
```
What this script says

Hedged Breakout is a strategy that trades EURUSD on 1-hour bars. It holds at most 2 open trades (1 per side) and hedges on an opposite signal.

When the close crosses above the previous bar's highest high of the last 24 bars, it buys at market, risking 0.5% of the balance, with a stop 40 pips from the entry, with a target 80 pips from the entry and tagged "up".

When the close crosses below the previous bar's lowest low of the last 24 bars, it sells at market, risking 0.5% of the balance, with a stop 40 pips from the entry, with a target 80 pips from the entry and tagged "down".

On each bar, it goes through each `trade` in open trades and checks whether `trade.bars_open` is at or above 48 and, if so, closes `trade`.
