# The cheat sheet

> Most of the language on one screen. It compiles.

Source: https://algobarsx.com/docs/cheat-sheet/

One script that touches the header, inputs, constants, state, history, another bar size, confirmations, a rule with timing, a managed order, an event and a plot. Copy it into the Terminal and start deleting what you do not need.

```algobarsx
algobarsx 1
strategy "Cheat Sheet"                  # or: indicator, alert, library
    market: EURUSD                      # several: markets: EURUSD, GBPUSD
    bars: 15m                           # 1m 5m 1h 4h 1d, or renko(5), xray(20)
    max_open: 1
    max_daily_loss: 3%

input length = 20, min: 5, max: 200     # a setting in the panel
const BUFFER = 2 pips                   # fixed value
state wins = 0                          # survives between bars

fast = ema(close, length)               # worked out again on every bar
prev_close = close[1]                   # history: one bar back
h4 = bars(bars: 4h)                     # another bar size, closed candles only
uptrend = h4.close > ema(h4.close, 50)

confirmations setup:                    # named conditions
    trend: uptrend
    momentum: rsi(close, 14) between 50 and 70
    require: all

when setup.passed and crosses_above(close, fast) max 2 per day cooldown 30m:
    buy risk: 1%, stop: low - BUFFER, target: 2R:
        breakeven at: 1R
        partial 50% at: 1.5R
        trail by: atr(14) * 2, after: 1.5R

when crosses_below(close, fast):
    close_all

on exit(trade):
    if trade.r > 0:
        wins += 1
    log "{trade.tag} closed at {trade.r:0.00}R, {wins} wins so far"

plot fast, color: if uptrend then green else red
```

For the long version, see the [Language Tour](https://algobarsx.com/docs/ex-08-language-tour/) example, which uses nearly every construct in the language.
