BUILD YOUR OWN PERSPECTIVE
Your logic.
Your chart.
The developer reference for custom Omnyvra indicators. Calculate in the browser and draw on your chart with JavaScript, TypeScript, Lua or Python.
Quick start
This reference and its downloads are public. Sign in to save an indicator or use it in your workspace. The contracts described here are implemented by Omnyvra; they are not the MetaTrader or TradingView programming interface.
The SDK is the set of functions and data formats your indicator uses inside the browser. No external API subscription or API key is required to write an indicator. The chart supplies its available market data.
- Open Setting → Indicators → Add indicator.
- Select JavaScript and load the EMA template, or upload the JavaScript EMA source from Examples.
- Confirm the template settings: Pane = Price chart, Calculate on = Live candles, Calculation method = Full window, Minimum candles = 1 and Required volume = None.
- Under Plots and inputs, confirm an integer input named
period, range 1–500, default 20; confirm a line plot namedema. - Choose Validate & preview, then Save version.
- Open Market → Indicators, add the saved indicator, and adjust its instance settings.
function calculate({ bars, inputs }, sdk) {
return { ema: sdk.ema(bars.map(bar => bar.close), inputs.period) };
}
Uploading a file imports its source and selects its language/name. It does not import a manifest JSON file. Configure Display, Plots and Inputs to match the example. Downloadable manifests are configuration references.
The editor preview uses simulated XAU/USD 1m candles and synthetic volume when requested. Passing preview confirms execution against that sample, not agreement with a broker. Verify the result against the actual chart feed as well.
Supported capabilities
| Field | Reference |
|---|---|
| JavaScript (.js) | Runs in QuickJS. Recommended for ready-to-run indicator code. Entry points must be synchronous. |
| TypeScript (.ts) | Strict type checking, then compilation to JavaScript. SDK types are available without imports. |
| Lua (.lua) | Runs through Wasmoon. Arrays start at 1; use sdk.na for missing plot values. |
| Python (.py) | Runs through Pyodide. Input is dict/list data; use None for missing plot values. |
| Chart output | Line, histogram and band boundaries; labels, boxes, lines and signal markers. Plots can use the price pane or a separate pane. |
| Not supported directly | .mq5, .ex5 or .pine files; automatic conversion; DLLs; order submission; SDK requests for additional symbols or timeframes. |
All languages must follow the same Omnyvra contract. An arbitrary script that depends on external packages is not automatically compatible. Calculations run on the viewer’s device and pause when the page is hidden or the workspace is inactive. This is not an unattended service that continues calculating after the browser closes.
Manifest & settings
A manifest declares the language, inputs and output contract. It is saved with the source in each version. The indicator editor is the supported way to configure it.
{
"sdkVersion": 1,
"name": "My EMA",
"language": "javascript",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "batch"
}| Field | Reference |
|---|---|
| sdkVersion | Required. Must be 1. |
| name | Required. 1–80 characters after trimming surrounding whitespace. |
| language | Required. javascript | typescript | lua | python. |
| execution | batch or incremental. Optional; omission means batch. |
| pane | price draws plots on the price chart; separate creates an indicator pane. |
| bars | live includes the unconfirmed trailing candle; closed excludes it. |
| volume | none does not require volume. tick or real requires a matching volume kind on every supplied candle. |
| minBars | Integer 1–20,000. Below this count, execution stops with Insufficient history. |
| inputs | Up to 12 definitions. Each requires id, label, default, min, max and integer. |
| plots | Up to 8 definitions. Each requires id, label, type and color. An empty array is allowed for drawing-only indicators. |
Input definitions
Only finite numeric inputs are supported. Set min ≤ default ≤ max. When integer is true, min, max, default and the selected value must all be integers. String, boolean, enum and color inputs are not available as formula parameters.
Input and plot IDs must match ^[a-zA-Z][a-zA-Z0-9_]{0,31}$. Names owned by Object.prototype, such as constructor and toString, are rejected. IDs must be unique within their group. Labels contain 1–60 trimmed characters. Colors use six-digit #RRGGBB. Manifest objects are strict: do not add undocumented fields.
Instance settings
Each chart instance has inputs keyed by input ID, colors keyed by plot ID, a boolean visible flag and an integer width from 1 to 4. Input values must remain within their declared ranges. Settings can change without altering the saved source version.
Candle data
| Field | Reference |
|---|---|
| bars: Bar[] | Oldest to newest. Index 0 is the oldest candle in the supplied window, not the newest candle as in MQL series indexing. |
| time: number | Unix timestamp in milliseconds. Use this timestamp to anchor output; do not multiply or divide it by 1,000 again. |
| open / high / low / close | Numeric prices from the supplied feed. Calculate from this data instead of fetching additional data. |
| closed: boolean | Candle-close status supplied by the feed/context. Do not infer it from the viewer’s local clock. |
| volume?: number | Optional. Do not silently substitute zero for missing volume unless that is explicitly part of your formula. |
| volumeKind?: "tick" | "real" | The volume type. Tick volume is not traded monetary value. |
| inputs: Record<string, number> | Selected numeric values, keyed by the input IDs in the manifest. |
| symbol / timeframe / timeZone | Context strings, for example XAU/USD, 1m and UTC. Metadata, not functions for requesting additional data. |
You receive the history currently available to the chart, capped at 20,000 candles. This does not promise 20,000 candles from every feed. The current MT5 integration supports 1m, 5m, 15m, 30m and 1h; prices and volume depend on the broker/account. timeZone describes context and does not change the timestamp unit.
In closed mode, an unconfirmed last candle is removed before calculation. In live mode, the trailing candle may be replaced repeatedly at the same timestamp. Handle OHLC updates without treating them as new candles. Avoid wall-clock time and randomness if your output must be reproducible.
calculate() · Batch
Define calculate(data, sdk) to process the entire supplied candle window. Return an object with one array per configured plot ID. Every array must have exactly bars.length entries, aligned by index.
function calculate({ bars, inputs }, sdk) {
const closes = bars.map(bar => bar.close);
return { ema: sdk.ema(closes, inputs.period) };
}To return drawings as well, use the envelope { plots, drawings }:
// Configure a line plot with ID "close" for this example.
function calculate({ bars }, sdk) {
return {
plots: { close: bars.map(bar => bar.close) },
drawings: bars.length ? [{
type: "label", id: "latest", time: bars[bars.length - 1].time,
value: bars[bars.length - 1].high, text: "Latest"
}] : []
};
}Batch execution has no persistent state between calls. Recalculate from the supplied window. Do not use async, Promise, export default or imports in the source file. Return sdk.na at warm-up positions; do not shorten arrays or use undefined.
onBar() · Incremental
Set execution to incremental and define onBar(data, sdk). The runtime visits candles from oldest to newest. Each call receives bar (one candle), state, inputs, symbol, timeframe and timeZone. There is no bars array.
// Configure a line plot with ID "close".
function onBar({ bar, state }, sdk) {
const count = (state?.count ?? 0) + 1;
return {
state: { count },
plots: { close: bar.close },
drawings: []
};
}Each plot contains a single value for the current candle, not an array. Return all configured plot IDs on every call, using sdk.na when unavailable. Return state as a JSON object or null.
State and replay semantics
- Initial execution, or a change to history before the trailing candle, resets state to null and replays the window.
- When the trailing candle changes, the runtime restores the state from before that candle and recalculates it. A count must not increase once per tick.
- When a new candle arrives, calculation continues from the preceding candle’s state. A rolling window may drop old candles while retaining this state. A fresh reset can therefore produce a different seed-dependent value from a long-running incremental instance; account for this when comparing EMA results.
- Do not rely on globals or closures surviving between runs. Persist through the returned state field.
- State is limited to 16 KiB and nesting depth 16. Use JSON-compatible objects, arrays, strings, booleans, null and finite numbers. Avoid Date, Map, functions, BigInt and circular references.
- beforeTail belongs to the runtime’s internal aggregate result; do not return it from onBar.
The last step’s drawings are the entire displayed drawing set. Drawings do not accumulate automatically. To retain historical markers, keep a bounded list in state and return it again. See the Levels and Signals template.
SDK formulas
SDK v1 exposes four public helpers. Supply finite numeric values and a positive integer period. Constrain period through your manifest: helpers do not validate it for you. They do not automatically skip missing values inside the input array.
| API | Result and calculation |
|---|---|
| sdk.na | Missing plot value: null in JavaScript/TypeScript, None in Python, false in Lua. |
| sdk.sma(values, period) | Same-length array. Arithmetic mean of the trailing period values. First populated index: period − 1 (JavaScript/Python). |
| sdk.ema(values, period) | Seed with the SMA of the first period values. Then previous + 2/(period+1) × (value − previous). Earlier positions are na. |
| sdk.rsi(values, period) | Seed average gain/loss from period price changes, then apply Wilder smoothing. First populated index: period. Zero loss with positive gain gives 100; both zero gives 50. |
Reference vector: values = [1,2,3,4], period = 3 produces SMA = [null,null,2,3], EMA = [null,null,2,3] and RSI = [null,null,null,100]. Constant values [5,5,5,5] produce a final RSI of 50. Lua uses false in place of null.
ATR, MACD, Bollinger Bands, crossover and request.security are not built-in helpers. Implement any additional formula from the supplied candle data. Be explicit about seeds, warm-up periods and smoothing when comparing implementations.
Plots & panes
| Field | Reference |
|---|---|
| line | Finite number or na per candle. Connected as a line in the selected pane. |
| histogram | Finite number or na per candle. Bars use zero as the baseline. |
| band | An object with exactly low and high, both finite and low ≤ high, or na. Rendered as two boundary lines; no filled area. |
| pane: price | Plots share the main price chart. Prefer this for overlays such as moving averages. |
| pane: separate | Creates an instance pane (initial height 140 px, minimum 80 px). Suitable for oscillators. |
The result must match the manifest’s plot IDs exactly. Extra or missing plots are rejected. Colors and width come from instance settings. A missing value creates a gap; it is not a zero price.
// Configure range (band) and momentum (histogram).
function calculate({ bars }, sdk) {
return {
range: bars.map(b => ({ low: b.low, high: b.high })),
momentum: bars.map((b, i) => i ? b.close - bars[i - 1].close : sdk.na)
};
}This example demonstrates both output shapes. In practice, a price range and a small momentum value usually belong in separate indicators because their scales differ.
Drawing API
Return up to 100 drawing objects with unique IDs per result. Reuse an ID to update the same object; objects omitted from the next result are removed. Coordinates are timestamps and prices on the price chart, not browser pixels.
| type | Required fields | Optional fields |
|---|---|---|
| label | id, time, value, text | color, background |
| box | id, from, to, low, high | color |
| line | id, from, to, fromValue, toValue | extend: none/right; style: solid/dashed/dotted; width: 1–4; text; color |
| marker | id, time, signal: buy/sell/neutral | position: above/below/at; value; shape: arrow/triangle/circle/diamond; color; text; showText |
IDs contain 1–48 characters from A–Z, a–z, 0–9, underscore or hyphen. Times are integer milliseconds between January 2, 1970 and January 1, 2100. Price coordinates must be finite and within ±10¹². Lines and boxes require from < to; boxes require low < high. A marker positioned at a price requires value.
Defaults and rendering behavior
- Labels default to white text (#ffffff) on #304977. Boxes default to #40a9ff with a translucent fill.
- Lines default to #7db7fc, width 1, solid, without extension. extend = right preserves the slope and reaches the visible chart’s right edge.
- BUY markers default below the candle low, with an arrow and #35e6ac. SELL markers default above the high, with an arrow and #ff7584. Neutral markers default above, with a diamond and #e6bc68.
- A supplied marker value overrides its candle-price anchor. above/below still adds a visual offset; use position = at to center on that price.
- BUY/SELL text appears by default. Neutral markers have no default text. Supply text to customize it or showText = false to hide it.
- Drawing anchors must lie within the loaded chart history. Markers need a candle at their timestamp. Off-window drawings are skipped; use line extension instead of inventing future anchor timestamps.
Text contains 1–80 trimmed characters, without control or bidirectional-control characters. Colors must be #RRGGBB. The chart adapter draws these data objects; custom HTML, CSS and event handlers are not supported.
// Return these objects inside drawings. Replace t1/t2 with candle
// timestamps (t1 < t2) and use prices relevant to your chart.
[
{ type: "label", id: "note", time: t2, value: 2400, text: "Resistance" },
{ type: "box", id: "zone", from: t1, to: t2, low: 2380, high: 2400,
color: "#d4af37" },
{ type: "line", id: "level", from: t1, to: t2,
fromValue: 2400, toValue: 2400, extend: "right",
style: "dashed", width: 2, color: "#d4af37" },
{ type: "marker", id: "buy-1", time: t2, signal: "buy",
position: "below", shape: "triangle", color: "#35e6ac",
text: "BUY", showText: true }
]This is a data-shape illustration, not a standalone source file. The downloadable templates below contain complete entry points and matching manifests.
Language requirements
JavaScript and TypeScript
Declare calculate or onBar in one source file. Use plain objects and ordinary numbers. The indicator environment does not provide DOM, window, fetch, localStorage, Node.js or npm imports. It is separate from the page’s JavaScript context.
TypeScript uses strict checking, target ES2017 and lib.es5 declarations. Do not assume types for Promise, DOM or every modern API are available. Use the supplied SDK types without importing them. The declaration download can support authoring in an external IDE.
Lua
Read data.bars and data.inputs. Call sdk.ema(values, period) with a dot, not a colon. Arrays start at 1. Use false or sdk.na for missing plot entries; nil creates holes and must not appear inside a plot array. State is a table with named fields, or nil. Base, Table, String, Math and UTF8 libraries are enabled. io, os and package are unavailable; dofile, loadfile, load, print, warn and collectgarbage are disabled.
Python
Use data["bars"], bar["close"], data["inputs"] and sdk.ema(...). Return dict/list data with None for missing values. This is Pyodide in the browser, not Python on your server. The SDK offers no pip installation workflow or guarantee that pandas/numpy are available. Do not access the viewer’s files or account data. Returned state must serialize to JSON.
Working examples
These examples use the same source and manifests as the editor templates. Download the source, then configure the editor to match its manifest. Each of the three templates is available in all four languages.
01 · Batch EMA
Live candles; price pane; minBars 1. Line plot: ema. Integer period input: 1–500, default 20.
JavaScript
function calculate({ bars, inputs }, sdk) {
return { ema: sdk.ema(bars.map(bar => bar.close), inputs.period) };
}
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "javascript",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "batch"
}TypeScript
function calculate({ bars, inputs }: Calculation, sdk: IndicatorSDK): Plots {
return { ema: sdk.ema(bars.map(bar => bar.close), inputs.period) };
}
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "typescript",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "batch"
}Lua
function calculate(data, sdk)
local closes = {}
for i, bar in ipairs(data.bars) do closes[i] = bar.close end
return { ema = sdk.ema(closes, data.inputs.period) }
end
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "lua",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "batch"
}Python
def calculate(data, sdk):
closes = [bar["close"] for bar in data["bars"]]
return {"ema": sdk.ema(closes, data["inputs"]["period"])}
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "python",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "batch"
}02 · Incremental EMA with label and box
Live candles; price pane; minBars 1. Line plot: ema. Integer period input: 1–500, default 20.
JavaScript
function onBar({ bar, state, inputs }, sdk) {
const period = inputs.period;
const count = (typeof state?.count === "number" ? state.count : 0) + 1;
const previous = typeof state?.ema === "number" ? state.ema : 0;
const ema = count < period ? previous + bar.close
: count === period ? (previous + bar.close) / period
: previous + 2 / (period + 1) * (bar.close - previous);
const drawings = [
{ type: "label", id: "latest", time: bar.time, value: bar.high, text: "Latest candle" }
];
const from = typeof state?.time === "number" ? state.time : bar.time;
const low = Math.min(typeof state?.low === "number" ? state.low : bar.low, bar.low);
const high = Math.max(typeof state?.high === "number" ? state.high : bar.high, bar.high);
if (from < bar.time && low < high) drawings.push(
{ type: "box", id: "range", from, to: bar.time, low, high, color: "#40a9ff" }
);
return { state: { count, ema, time: bar.time, high: bar.high, low: bar.low },
plots: { ema: count >= period ? ema : sdk.na }, drawings };
}
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "javascript",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "incremental"
}TypeScript
function onBar({ bar, state, inputs }: BarInput, sdk: IndicatorSDK): IndicatorStep {
const period = inputs.period;
const count = (typeof state?.count === "number" ? state.count : 0) + 1;
const previous = typeof state?.ema === "number" ? state.ema : 0;
const ema = count < period ? previous + bar.close
: count === period ? (previous + bar.close) / period
: previous + 2 / (period + 1) * (bar.close - previous);
const drawings: IndicatorDrawing[] = [
{ type: "label", id: "latest", time: bar.time, value: bar.high, text: "Latest candle" }
];
const from = typeof state?.time === "number" ? state.time : bar.time;
const low = Math.min(typeof state?.low === "number" ? state.low : bar.low, bar.low);
const high = Math.max(typeof state?.high === "number" ? state.high : bar.high, bar.high);
if (from < bar.time && low < high) drawings.push(
{ type: "box", id: "range", from, to: bar.time, low, high, color: "#40a9ff" }
);
return { state: { count, ema, time: bar.time, high: bar.high, low: bar.low },
plots: { ema: count >= period ? ema : sdk.na }, drawings };
}
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "typescript",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "incremental"
}Lua
function onBar(data, sdk)
local bar, prev, period = data.bar, data.state or {}, data.inputs.period
local count, previous = (prev.count or 0) + 1, prev.ema or 0
local ema
if count < period then ema = previous + bar.close
elseif count == period then ema = (previous + bar.close) / period
else ema = previous + 2 / (period + 1) * (bar.close - previous) end
local drawings = {
{ type = "label", id = "latest", time = bar.time, value = bar.high, text = "Latest candle" }
}
local low = math.min(prev.low or bar.low, bar.low)
local high = math.max(prev.high or bar.high, bar.high)
if prev.time and prev.time < bar.time and low < high then
drawings[2] = { type = "box", id = "range", from = prev.time, to = bar.time,
low = low, high = high, color = "#40a9ff" }
end
return { state = { count = count, ema = ema, time = bar.time, high = bar.high, low = bar.low },
plots = { ema = count >= period and ema or sdk.na }, drawings = drawings }
end
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "lua",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "incremental"
}Python
def onBar(data, sdk):
bar, prev, period = data["bar"], data["state"] or {}, data["inputs"]["period"]
count, previous = prev.get("count", 0) + 1, prev.get("ema", 0)
if count < period:
ema = previous + bar["close"]
elif count == period:
ema = (previous + bar["close"]) / period
else:
ema = previous + 2 / (period + 1) * (bar["close"] - previous)
drawings = [
{"type": "label", "id": "latest", "time": bar["time"], "value": bar["high"], "text": "Latest candle"}
]
low = min(prev.get("low", bar["low"]), bar["low"])
high = max(prev.get("high", bar["high"]), bar["high"])
if prev.get("time", bar["time"]) < bar["time"] and low < high:
drawings.append({"type": "box", "id": "range", "from": prev["time"], "to": bar["time"],
"low": low, "high": high, "color": "#40a9ff"})
return {"state": {"count": count, "ema": ema, "time": bar["time"], "high": bar["high"], "low": bar["low"]},
"plots": {"ema": ema if count >= period else sdk.na}, "drawings": drawings}
Manifest configuration
{
"sdkVersion": 1,
"name": "My EMA",
"language": "python",
"pane": "price",
"bars": "live",
"volume": "none",
"minBars": 1,
"inputs": [
{
"id": "period",
"label": "Period",
"min": 1,
"max": 500,
"default": 20,
"integer": true
}
],
"plots": [
{
"id": "ema",
"label": "EMA",
"type": "line",
"color": "#40a9ff"
}
],
"execution": "incremental"
}03 · Levels and breakout signals
Closed candles; price pane; minBars 2; no plots. Integer lookback input: 2–100, default 8. Keeps up to 32 recent signals. Does not submit orders.
JavaScript
function onBar({ bar, state, inputs }) {
const previous = state;
const history = previous?.history ?? [];
const signals = (previous?.signals ?? []).slice();
const lines = [];
if (history.length === inputs.lookback) {
const from = history[0][0];
let support = history[0][1];
let resistance = history[0][2];
for (let i = 1; i < history.length; i++) {
support = Math.min(support, history[i][1]);
resistance = Math.max(resistance, history[i][2]);
}
lines.push(
{ type: "line", id: "support", from, to: bar.time, fromValue: support, toValue: support,
extend: "right", style: "dashed", color: "#35e6ac", text: "Support" },
{ type: "line", id: "resistance", from, to: bar.time, fromValue: resistance, toValue: resistance,
extend: "right", style: "dashed", color: "#ff7584", text: "Resistance" }
);
const signal = bar.close > resistance ? "buy" : bar.close < support ? "sell" : null;
if (bar.closed && signal) signals.push({ type: "marker", id: "signal-" + bar.time, signal, time: bar.time });
}
const entry = [bar.time, bar.low, bar.high];
const recent = signals.slice(-32);
return { state: { history: history.concat([entry]).slice(-inputs.lookback), signals: recent },
plots: {}, drawings: lines.concat(recent) };
}
Manifest configuration
{
"sdkVersion": 1,
"name": "Levels and Signals",
"language": "javascript",
"execution": "incremental",
"pane": "price",
"bars": "closed",
"volume": "none",
"minBars": 2,
"plots": [],
"inputs": [
{
"id": "lookback",
"label": "Lookback",
"min": 2,
"max": 100,
"default": 8,
"integer": true
}
]
}TypeScript
type SignalMarker = Extract<IndicatorDrawing, { type: "marker" }>;
type LevelState = { history: [number, number, number][]; signals: SignalMarker[] };
function onBar({ bar, state, inputs }: BarInput): IndicatorStep {
const previous = state as LevelState | null;
const history = previous?.history ?? [];
const signals = (previous?.signals ?? []).slice();
const lines: IndicatorDrawing[] = [];
if (history.length === inputs.lookback) {
const from = history[0][0];
let support = history[0][1];
let resistance = history[0][2];
for (let i = 1; i < history.length; i++) {
support = Math.min(support, history[i][1]);
resistance = Math.max(resistance, history[i][2]);
}
lines.push(
{ type: "line", id: "support", from, to: bar.time, fromValue: support, toValue: support,
extend: "right", style: "dashed", color: "#35e6ac", text: "Support" },
{ type: "line", id: "resistance", from, to: bar.time, fromValue: resistance, toValue: resistance,
extend: "right", style: "dashed", color: "#ff7584", text: "Resistance" }
);
const signal = bar.close > resistance ? "buy" : bar.close < support ? "sell" : null;
if (bar.closed && signal) signals.push({ type: "marker", id: "signal-" + bar.time, signal, time: bar.time });
}
const entry: [number, number, number] = [bar.time, bar.low, bar.high];
const recent = signals.slice(-32);
return { state: { history: history.concat([entry]).slice(-inputs.lookback), signals: recent },
plots: {}, drawings: lines.concat(recent) };
}
Manifest configuration
{
"sdkVersion": 1,
"name": "Levels and Signals",
"language": "typescript",
"execution": "incremental",
"pane": "price",
"bars": "closed",
"volume": "none",
"minBars": 2,
"plots": [],
"inputs": [
{
"id": "lookback",
"label": "Lookback",
"min": 2,
"max": 100,
"default": 8,
"integer": true
}
]
}Lua
function onBar(data, sdk)
local bar, lookback = data.bar, data.inputs.lookback
local prev = data.state or {}
local history, signals = prev.history or {}, prev.signals or {}
local drawings = {}
if #history == lookback then
local support, resistance = math.huge, -math.huge
for _, candle in ipairs(history) do
support = math.min(support, candle[2])
resistance = math.max(resistance, candle[3])
end
local from = history[1][1]
drawings[1] = { type = "line", id = "support", from = from, to = bar.time, fromValue = support, toValue = support,
extend = "right", style = "dashed", color = "#35e6ac", text = "Support" }
drawings[2] = { type = "line", id = "resistance", from = from, to = bar.time, fromValue = resistance, toValue = resistance,
extend = "right", style = "dashed", color = "#ff7584", text = "Resistance" }
local signal
if bar.close > resistance then signal = "buy" elseif bar.close < support then signal = "sell" end
if bar.closed and signal then
signals[#signals + 1] = { type = "marker", id = "signal-" .. bar.time, signal = signal, time = bar.time }
end
end
history[#history + 1] = { bar.time, bar.low, bar.high }
if #history > lookback then table.remove(history, 1) end
if #signals > 32 then table.remove(signals, 1) end
for _, marker in ipairs(signals) do drawings[#drawings + 1] = marker end
return { state = { history = history, signals = signals }, plots = {}, drawings = drawings }
end
Manifest configuration
{
"sdkVersion": 1,
"name": "Levels and Signals",
"language": "lua",
"execution": "incremental",
"pane": "price",
"bars": "closed",
"volume": "none",
"minBars": 2,
"plots": [],
"inputs": [
{
"id": "lookback",
"label": "Lookback",
"min": 2,
"max": 100,
"default": 8,
"integer": true
}
]
}Python
def onBar(data, sdk):
bar, lookback = data["bar"], data["inputs"]["lookback"]
prev = data["state"] or {}
history, signals = prev.get("history") or [], list(prev.get("signals") or [])
lines = []
if len(history) == lookback:
start = history[0][0]
support = min(candle[1] for candle in history)
resistance = max(candle[2] for candle in history)
for key, value, color in (("support", support, "#35e6ac"), ("resistance", resistance, "#ff7584")):
lines.append({"type": "line", "id": key, "from": start, "to": bar["time"],
"fromValue": value, "toValue": value, "extend": "right", "style": "dashed",
"color": color, "text": key.title()})
signal = "buy" if bar["close"] > resistance else "sell" if bar["close"] < support else None
if bar["closed"] and signal:
signals.append({"type": "marker", "id": "signal-" + str(bar["time"]), "signal": signal, "time": bar["time"]})
next_history = (history + [[bar["time"], bar["low"], bar["high"]]])[-lookback:]
recent = signals[-32:]
return {"state": {"history": next_history, "signals": recent}, "plots": {}, "drawings": lines + recent}
Manifest configuration
{
"sdkVersion": 1,
"name": "Levels and Signals",
"language": "python",
"execution": "incremental",
"pane": "price",
"bars": "closed",
"volume": "none",
"minBars": 2,
"plots": [],
"inputs": [
{
"id": "lookback",
"label": "Lookback",
"min": 2,
"max": 100,
"default": 8,
"integer": true
}
]
}TypeScript reference
These are the declarations used by the editor’s TypeScript compiler. Download them for reference in your IDE. Inside the Omnyvra editor they are already present: do not paste or import them again.
Download omnyvra-sdk.d.ts ↓Complete TypeScript API
type Bar = {time: number; open: number; high: number; low: number; close: number; closed: boolean;
volume?: number; volumeKind?: "tick" | "real"};
type Calculation = {bars: readonly Bar[]; inputs: Record<string, number>; symbol: string; timeframe: string; timeZone: string};
type PlotValue = number | null | {low: number; high: number};
type Plots = Record<string, PlotValue[]>;
type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
type IndicatorState = { [key: string]: JsonValue } | null;
type BarInput = Omit<Calculation, "bars"> & { bar: Bar; state: IndicatorState };
type IndicatorDrawing =
| { type: "label"; id: string; time: number; value: number; text: string; color?: string; background?: string }
| { type: "box"; id: string; from: number; to: number; low: number; high: number; color?: string }
| { type: "line"; id: string; from: number; to: number; fromValue: number; toValue: number;
extend?: "none" | "right"; style?: "solid" | "dashed" | "dotted"; width?: number; color?: string; text?: string }
| { type: "marker"; id: string; time: number; signal: "buy" | "sell" | "neutral";
position?: "above" | "below" | "at"; value?: number; shape?: "arrow" | "triangle" | "circle" | "diamond";
color?: string; text?: string; showText?: boolean };
type IndicatorStep = { state: IndicatorState; plots: Record<string, PlotValue>; drawings?: IndicatorDrawing[] };
type IndicatorBatch = { plots: Plots; drawings?: IndicatorDrawing[] };
type IndicatorSDK = {readonly na: null;
sma(values: number[], period: number): (number | null)[];
ema(values: number[], period: number): (number | null)[];
rsi(values: number[], period: number): (number | null)[];
};
Signals & alerts
A buy/sell marker on a confirmed closed candle can feed Chart alerts. The user must create an Indicator signal on candle close rule and select the instance and BUY/SELL direction. Returning a marker does not immediately send a notification or order. neutral markers are visual only.
The alert adapter evaluates markers on the latest confirmed closed candle. Returning historical markers does not replay every historical alert. With MT5, alert evaluation pauses when the feed is stale or disconnected. The indicator must remain enabled and visible. Source code has no API to send network notifications itself.
Use bars = closed and check bar.closed before generating confirmed signals. Historical corrections, stale data and the feed’s candle-close policy still matter. The SDK does not guarantee that every indicator is non-repainting.
Sandbox & limits
| Field | Reference |
|---|---|
| Source file | Non-empty UTF-8 text, no NUL, at most 256 KiB. No ZIP or binary uploads. |
| Candle window | At most 20,000 candles. |
| Result | Serialized result limited by a 4 × 1024 × 1024 string-length guard. Keep output well below this threshold; it is not a UTF-8 byte quota. |
| State | JSON object/null, at most 16 KiB, nesting depth at most 16. |
| Chart layout | Up to 6 indicator instances. |
| Output configuration | Up to 12 inputs, 8 plots and 100 drawing objects per result. |
| Execution time | Initial/reset and editor preview: up to 10 seconds. Normal update: 500 ms. Runtime loading timeout: 30 seconds. |
| Scheduling | Up to 2 calculation jobs concurrently; starts throttled by approximately 250 ms. This does not promise a fixed refresh rate. |
| Memory | QuickJS/Lua: 32 MiB. QuickJS stack: 512 KiB. These limits are not a statement about Pyodide’s memory footprint. |
| Library storage | Up to 100 entries per owner, 100 versions per entry, and 20 MiB total source per owner. |
Code executes in a Worker inside an origin-isolated iframe, under a network-blocking content security policy. It receives candle data and inputs, not MT5 credentials or the website session. Use pure calculations and schema-compatible output, without side effects or background timers.
A timeout, execution error or invalid result stops that instance’s work and removes its rendered output. Correct the source or settings and reload the instance after addressing the cause. Bound loops, retained state and historical markers instead of increasing work without a limit.
Versions & sharing
Save version records source and manifest together. Editing a draft does not automatically change a version already in use. An instance is pinned to a versionId and its own settings. Before updating, check compatibility of input and plot IDs.
Private entries belong to their owner. Sharing makes the published source available to other signed-in Omnyvra users; it is not source-code protection. Unsharing stops later access through the system but cannot recall previously downloaded copies. Conflicting saves from another editor window are rejected rather than silently overwriting changes.
Indicator settings and drawings are scoped to chart context. MT5 context includes connection, generation, symbol and timeframe. Do not reuse state from a different account, instrument or timeframe as though its candles were unchanged.
Troubleshooting & testing
| Symptom or message | What to check |
|---|---|
| Define calculate / onBar | Match the function name to Calculation method. Do not use a default export. |
| Result does not match the configured plots | Match every plot ID exactly, including warm-up results. |
| one value per candle | Batch arrays must match bars.length. Incremental steps return one value per plot, not arrays. |
| invalid value | Check division by zero, NaN and Infinity. Return sdk.na when no value exists. |
| Insufficient history | Wait for more history or choose an appropriate minBars. Do not assume a full history window. |
| feed does not identify … volume | Match tick/real to the feed, or use none when volume is not needed. Preview volume is synthetic. |
| Check drawing IDs… | Check duplicate IDs, time order, price bounds, hex colors, milliseconds and valid text. |
| state exceeds / nested too deeply | Bound history buffers; do not store the entire candle window in state. |
| time limit / worker stopped | Replace quadratic work with incremental or rolling calculations. Reduce drawings and bound loops. |
| TypeScript line/column error | Fix the reported position. Use SDK types and remove external imports. |
| changed / storage limit | Reload after a revision conflict; inspect entry count, version count and source size. |
| Values differ from another platform | Compare the same OHLC feed, timestamp alignment, seed, warm-up, volume kind and close policy. |
Pre-release checklist
- Test hand-calculable data, fewer candles than period, flat prices, rising/falling prices and absent volume.
- Verify SMA/EMA/RSI seeds and the first populated index against the definitions above.
- Compare batch and incremental versions on identical candles with an explicit numeric tolerance.
- Replace the trailing candle several times, then append a new candle. Confirm state and signals are not duplicated.
- Change timeframe and inputs, reload history, and correct an older candle.
- Check millisecond timestamps, gaps, stable drawing IDs and the 100-object limit.
- Validate against actual chart data after preview. Record the source version, feed and parameters used.
- Check responsiveness with multiple instances on desktop and mobile.
Porting existing indicators
Port formulas manually to JavaScript, TypeScript, Lua or Python using this SDK. An automatic MQL5/Pine importer is not currently available. Renaming a source-file extension does not translate its language or platform APIs.
| Original concept | Omnyvra equivalent or limitation |
|---|---|
| MQL OnCalculate / indicator buffer | calculate with one array per plot, or onBar with state. |
| MQL series index 0 = newest | bars is oldest → newest; the newest is bars[bars.length − 1]. |
| Pine plot / plotshape | manifest.plots with calculated output / marker drawings. |
| Pine var / persistent MQL globals | Explicit state returned from onBar. |
| Pine na / MQL EMPTY_VALUE | sdk.na. Do not use a very large numeric sentinel for missing output. |
| request.security / iCustom / CopyBuffer | No equivalent data-request API. Prepare a formula using the current chart’s supplied data. |
| strategy / OrderSend / CTrade | No order submission from the indicator runtime. |
| EX5 or closed-source Pine | Source and permission to adapt it are required. Binary decompilation is not supported. |
Separate the mathematical formula from platform-specific calls first. Port the formula and parameters, map results to plots/drawings, then compare both implementations using identical candles before use.