# Cheat sheet

> One printable page of the Pine you write most often on Tradequix, from the script skeleton to strategies.

## Skeleton

```pine
//@version=6
indicator("Name", overlay = true)
len = input.int(20, "Length", minval = 1)
x = ta.ema(close, len)
plot(x, "EMA", color = color.orange)
```

## Series and history

| Write | Means |
| --- | --- |
| `close`, `open`, `high`, `low`, `volume` | This bar's values (volume = tick count) |
| `hl2`, `hlc3`, `ohlc4` | Averages of the above |
| `close[1]` | Previous bar's close |
| `na(x)`, `nz(x)` | Test for, or replace, no value |
| `var float x = na` | Keep x between bars |
| `x := 1` | Reassign |

## Studies

| Write | Gives |
| --- | --- |
| `ta.sma/ema/wma/hma(src, len)` | Averages |
| `ta.rsi(src, len)`, `ta.atr(len)` | RSI, ATR |
| `[m, u, l] = ta.bb(src, len, 2)` | Bollinger Bands |
| `[macd, sig, hist] = ta.macd(src, 12, 26, 9)` | MACD |
| `[st, dir] = ta.supertrend(3, 10)` | Supertrend (dir < 0 is up) |
| `ta.crossover(a, b)` | true on the cross bar |
| `ta.highest(high, n)`, `ta.lowest(low, n)` | Range extremes |
| `ta.valuewhen(cond, src, 0)` | Value when cond last held |

## Drawing

| Write | Draws |
| --- | --- |
| `plot(x, style = plot.style_columns)` | Line, histogram, columns, area… |
| `plotshape(cond, style = shape.triangleup, location = location.belowbar)` | Markers where true or non-zero |
| `hline(70)` | A fixed level |
| `fill(p1, p2, color.new(color.purple, 85))` | Shade between plots |
| `bgcolor(c)`, `barcolor(c)` | Tint the background, recolour candles |
| `if barstate.islast` + `label.new(...)` | Draw once at the end |

## Other timeframes

```pine
htf = request.security(syminfo.tickerid, "60", close[1], lookahead = barmerge.lookahead_on)
```

Feed timeframes: `5S 10S 15S 30S 1 2 3 5 10 15 30 60 240 D`.

## Strategy

```pine
//@version=6
strategy("Name", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
if ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
    strategy.entry("Long", strategy.long)
strategy.exit("Exit", "Long", stop = close * 0.99, limit = close * 1.02)
```

## Limits to remember

8 s per run · 40 `request.*` · 3,600 candles per request · 100,000 elements · 50 indicators per chart.
