# Turtle Channels

> Turtle Channels is a strategy that trades XAUUSD on daily bars. It adds up to 4 entries in the same direction, keeps at least 500 points between entri

Source: https://algobarsx.com/docs/ex-33-turtle-channels/

```algobarsx
strategy "Turtle Channels"
    market: XAUUSD
    bars: 1d
    pyramiding: 4
    min_distance: 500 points
    max_drawdown: 20%

input entry_length = 20
input exit_length = 10
input unit_risk = 0.5%

entry_channel = donchian(entry_length)
exit_channel = donchian(exit_length)

when crosses_above(close, entry_channel.upper[1]):
    buy risk: unit_risk, stop: atr(20) * 2, tag: "turtle"

when crosses_below(close, exit_channel.lower[1]):
    close_all side: long, tag: "turtle"

plot entry_channel.upper, color: green
plot exit_channel.lower, color: red
```
What this script says

Turtle Channels is a strategy that trades XAUUSD on daily bars. It adds up to 4 entries in the same direction, keeps at least 500 points between entries and stops trading after a 20% drawdown.

You can change 3 inputs: `entry_length` (default 20), `exit_length` (default 10) and `unit_risk` (default 0.5%).

It calculates `entry_channel` as the Donchian Channels (length `entry_length`) and `exit_channel` as the Donchian Channels (length `exit_length`).

When the close crosses above the previous bar's `entry_channel.upper`, it buys at market, risking `unit_risk` of the balance, with a stop 2 × the 20-bar ATR from the entry and tagged "turtle".

When the close crosses below the previous bar's `exit_channel.lower`, it closes all long trades tagged "turtle".

On the chart, it plots `entry_channel.upper` and `exit_channel.lower`.
