# Supertrend Trend Rider

> Supertrend Trend Rider is a strategy that trades XAUUSD on 1-hour bars. It takes long trades only, adds up to 2 entries in the same direction and keep

Source: https://algobarsx.com/docs/ex-14-supertrend-trend-rider/

```algobarsx
strategy "Supertrend Trend Rider"
    market: XAUUSD
    bars: 1h
    direction: long
    pyramiding: 2
    min_distance: 300 points

input atr_length = 10
input factor = 3.0

trend = supertrend(atr_length, factor)

when trend.direction == 1 and crosses_above(close, ema(close, 21)):
    buy risk: 0.75%, stop: trend.line, target: 4R, tag: "rider":
        breakeven at: 1R, offset: 50 points
        partial 25% at: 2R
        trail by: atr(14) * 2, after: 2R
        exit when: trend.direction == -1

plot trend.line, color: if trend.direction == 1 then green else red, width: 2
```
What this script says

Supertrend Trend Rider is a strategy that trades XAUUSD on 1-hour bars. It takes long trades only, adds up to 2 entries in the same direction and keeps at least 300 points between entries.

You can change 2 inputs: `atr_length` (default 10) and `factor` (default 3.0).

It calculates `trend` as the Supertrend (length `atr_length`, multiplier `factor`).

When `trend.direction` is 1 and the close crosses above the 21-bar EMA of the close, it buys at market, risking 0.75% of the balance, with a stop at `trend.line`, with a target 4R from the entry and tagged "rider"; once open, it moves the stop to breakeven at 1R plus 50 points, closes 25% at 2R, trails the stop by 2 × the 14-bar ATR once the trade reaches 2R and exits when `trend.direction` is -1.

On the chart, it plots `trend.line`.
