# Pyramid Momentum

> Pyramid Momentum is a strategy that trades NAS100 on 1-hour bars. It takes long trades only, adds up to 3 entries in the same direction, keeps at leas

Source: https://algobarsx.com/docs/ex-48-pyramid-momentum/

```algobarsx
strategy "Pyramid Momentum"
    market: NAS100
    bars: 1h
    direction: long
    pyramiding: 3
    min_distance: 100 points
    max_total_risk: 3%

state adds = 0

when crosses_above(close, ema(close, 50)) and trades.open().len == 0:
    buy risk: 1%, stop: 3 * atr(14), tag: "core"
    adds = 0

when trades.open().len > 0 and adds < 2 and close > trades.last().entry_price + 2 * atr(14):
    buy risk: 0.5%, stop: 3 * atr(14), tag: "add"
    adds += 1

when crosses_below(close, ema(close, 50)):
    close_all
```
What this script says

Pyramid Momentum is a strategy that trades NAS100 on 1-hour bars. It takes long trades only, adds up to 3 entries in the same direction, keeps at least 100 points between entries and never risks more than 3% across open trades.

It remembers `adds` from one bar to the next.

When the close crosses above the 50-bar EMA of the close and the number of open trades is 0, it buys at market, risking 1% of the balance, with a stop 3 × the 14-bar ATR from the entry and tagged "core"; it also sets `adds` to 0.

When the number of open trades is above 0 and `adds` is below 2 and the close is above `trades.last().entry_price` plus 2 × the 14-bar ATR, it buys at market, risking 0.5% of the balance, with a stop 3 × the 14-bar ATR from the entry and tagged "add"; it also adds 1 to `adds`.

When the close crosses below the 50-bar EMA of the close, it closes all trades.
