feature
Forward return
For each EMA-cross event, measures close-to-close return over a horizon, then publishes a distribution.
What it studies
Distribution of forward returns after ema-cross-up events.
Key decisions
Piece | Why it matters |
|---|---|
| Trader-tunable look-ahead without editing code. |
| One bar at/after the horizon (see Code IntelliSense for other shapes). |
Entry from | Must match what the definition emitted. |
| Result UI expects an array of numeric samples. |
Full script
meta({
name: "EMA cross forward return",
kind: "study",
params: {
horizonMin: { type: "number", def: 60, min: 1, max: 1440 },
},
});
flows.declare({
slug: "ema-cross-up",
as: "xup",
});
results.declare({
id: "fwd_ret",
kind: "distribution",
title: "Forward returns",
});
results.declare({
id: "n",
kind: "metric",
title: "Samples",
});
export function onEvent(ctx) {
if (ctx.event.flow !== "xup") return;
const entry = Number(ctx.event.payload.close);
if (!Number.isFinite(entry) || entry === 0) return;
const after = ctx.candles.forward({ minutes: ctx.params.horizonMin });
if (!after || after.close == null) return;
const ret = (after.close - entry) / entry;
ctx.collect("rets", ret);
}
export function onFinish(ctx) {
const rets = ctx.collected("rets");
ctx.publish("n", { value: rets.length, label: "Samples" });
ctx.publish("fwd_ret", rets);
}Heavy per-event candle work can hit study budgets — see Budgets and limits.
