The Crow Programming Language

chart

Technical indicators for the chart element, computed by the kernel so both execution modes draw the same numbers.

Import with use chart. Technical indicators for the chart element, computed by the runtime (crow_runtime::indicators, over the kernels in crow_runtime::ta) so the interpreter and compiled programs draw the same numbers. Every function takes series — frame columns or arrays of numbers — and returns a series of the same length, NaN where the value is not yet defined (a 14-period RSI has no value on row 3), so a chart draws a gap instead of a guess. Write a result into the frame (df.name = series) and name the column in lines = [...] or panes = [...].

FunctionDescriptionExample
sma[values, n]Simple moving average over the last n rowsCharts and Styling
ema[values, n]Exponential moving average, smoothing 2/(n+1), seeded by the first n rows' meanCharts and Styling
rsi[values, n]Wilder's relative strength index over n deltas (0–100), from the second row on: until n deltas have come, of the mean gain and the mean loss of those there are (the line shows from the open, as a scanner reading the first minutes needs); from the nth, each new delta smoothed in by (n−1)/n, as Wilder's is. 100 where there are gains and no losses, 0 where there are losses and no gains, 50 where there are neither (a flat series); a row that is no number is NaN and passed overCharts and Styling
rsi[ts, values, n, secs]RSI on clock-aligned buckets of secs seconds over finer rows — a 14-period RSI on 3-minute candles drawn over 1-second bars: completed buckets feed the smoothing once, and rows inside the forming bucket see a provisional value from the latest close, so history never changes and the newest value moves with the tapeCharts and Styling
macd[values, fast, slow, signal]A frame with columns line (fast EMA − slow EMA), signal (its EMA), hist (their difference)Charts and Styling
vwap[price, vol]Cumulative volume-weighted average price from the first rowCharts and Styling
vwap[ts, price, vol, secs]VWAP over the trailing secs seconds (rows with ts >= t − secs)Charts and Styling
rolling_sum[ts, values, secs]Sum over the trailing secs secondsCharts and Styling

A trailing window — rolling_sum, vwap over seconds, rsi on buckets — reads its times in order, each at least the one before, and its seconds are 0 or more: a time that goes back stops the program, saying where (rolling_sum: the times go back at row 1 (1 after 3)), as a negative window does. | cvd[close, vol] | Cumulative volume delta: volume counted positive when the close rose, negative when it fell | Charts and Styling |

ts is a column of moments (seconds). A window is 1 row or more, a trailing window 0 seconds or more and a bucket more than 0, and the series an indicator reads row by row are one length; anything else stops the program with the reason (see When a Program Stops), as does a wrong number of arguments, naming the counts the function takes (rsi[] takes 2 or 4 arguments, got 3). A negative window had been a huge one compiled and one row interpreted, and a shorter series cut the others.

use chart, frame

bars = frame.new[]
bars.ts = [0.0, 60.0, 120.0, 180.0, 240.0, 300.0]
bars.c = [10.0, 11.0, 10.5, 11.5, 12.0, 11.0]
bars.vol = [100.0, 200.0, 150.0, 300.0, 250.0, 100.0]
bars.sma3 = sma[bars.c, 3]
bars.rsi3 = rsi[bars.c, 3]
bars.vwap = vwap[bars.c, bars.vol]
log[bars.sma3[5]]      --- 11.5
log[bars.rsi3[5]]      --- 50
log[bars.vwap[1]]      --- 10.666666666666666

In a view, the columns become panes with reference levels:

chart[bars, candles = ['o', 'hi', 'lo', 'c'], lines = ['vwap'], bars_y = 'vol',
      panes = [['rsi3'], ['cvd']], levels = map[rsi3 = [30, 70], cvd = [0]],
      points = fills, seek = jump, marker = clock, tz = 'America/New_York']

Generated by crow test --docs --write from the language specification, section 11 and 13. Edit the spec, not this page.