# Active Trade Manager

> Active Trade Manager is a strategy that trades XAUUSD on 5-minute bars. It holds at most 1 open trade.

Source: https://algobarsx.com/docs/ex-47-active-trade-manager/

```algobarsx
strategy "Active Trade Manager"
    market: XAUUSD
    bars: 5m
    max_open: 1

when crosses_above(close, vwap()) and rsi(close, 7) > 55:
    buy risk: 1%, stop: 2 * atr(14), target: 3R, tag: "managed"

for trade in trades.open(tag: "managed"):
    if trade.r >= 1 and trade.stop < trade.entry_price:
        modify trade, stop: trade.entry_price
    elif trade.r >= 2:
        close trade, size: 50%
        modify trade, target: trade.entry_price + atr(14) * 6
```
What this script says

Active Trade Manager is a strategy that trades XAUUSD on 5-minute bars. It holds at most 1 open trade.

When the close crosses above VWAP and the 7-bar RSI is above 55, 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 "managed".

On each bar, it goes through each `trade` in open trades tagged "managed" and checks whether `trade.r` is at or above 1 and `trade.stop` is below `trade.entry_price` and, if so, moves the stop to `trade.entry_price` for `trade`; otherwise, if `trade.r` is at or above 2, closes `trade` (50% of it) and moves the target to `trade.entry_price` plus 6 × the 14-bar ATR for `trade`.
