Coinray Strategy SDK
Write indicators and trading strategies in TypeScript. The same script draws on the chart in your browser, fires alerts on the server, and runs in backtests, with identical results in all three places.
import { src, ta, param, plot, alert, isNewBar } from "@coinray/strategy";
const fast = param.int("Fast EMA", 9, 2, 200);
const slow = param.int("Slow EMA", 21, 2, 400);
export function onBar(): void {
const f = ta.ema(src.close, fast);
const s = ta.ema(src.close, slow);
plot("fast", f);
plot("slow", s);
if (isNewBar() && f[1] > s[1] && f[2] <= s[2]) {
alert("golden_cross", "{{ticker}} fast EMA crossed above slow at {{close}}");
}
}
What you can build
- Indicators: plots in the price pane or in their own panes, with declared colors, styles, fills and horizontal levels.
- Drawings: markers, lines, boxes, labels, polylines and circles, with Pine
style options such as
extend, arrow heads and label callouts. - Alerts: named alerts with
{{placeholder}}messages, delivered to the app, webhooks and Altrady signal bots. - Strategies: order groups with multiple entries, take-profit legs, a stop loss and a trailing stop, backtested with TradingView-style statistics.
- Multi-timeframe logic: higher-timeframe series built from the chart's own bars.
- Crypto data Pine does not have: aggressive buy and sell volume, CVD, funding rate and open interest.
How it runs
Scripts are written in TypeScript against the @coinray/strategy SDK and
compiled to WebAssembly. The compiled module runs in a sandbox with a fixed
compute, memory and event budget per bar (see Limits), so a
script cannot slow down the chart or the scanner.
The language is AssemblyScript, a strict
subset of TypeScript with explicit number types (i32, i64, f64). Most
TypeScript you would write for a trading script works unchanged. The
differences that matter are listed in Getting started.
Where to go next
- Getting started: the shape of a script, inputs, plots.
- The bar model: the one concept to understand before writing anything stateful.
- Examples: three complete scripts using most features.
- Porting from Pine Script: a name-by-name mapping.
- API Reference: every function, class and enum, generated from the SDK.