Native Indicators
CoreXTrader includes 25 built-in indicator engines implemented in optimised Rust. Use Native.Source(i.Name) to select one, Native.Init(symbol, timeframe) to choose its series, pass its parameters positionally (in the order listed below) with Native.Parameter(…), and Native.Fetch(index, buf) to retrieve output buffers. For an EMA/WMA/… use i.MA with an MA.* type: Native.Parameter(50, MA.EMA, Price.Close). Bind another timeframe with Native.Init(Symbol(), Timeframe.H4), another symbol with Native.Init("EURUSD.r", Timeframe.H1). Native engines are available in strategies (files with a Tick() function).
Indicator Registry
Parameters in Native.Parameter order, then the output buffers by Native.Fetch index. source is a Price.* value.
i.MAperiod, ma_type (MA.*), source0 → Valuei.Bollingerperiod, std_dev, source0 Middle · 1 Upper · 2 Loweri.Ichimokutenkan, kijun, senkou, displacement0 Tenkan · 1 Kijun · 2 SpanA · 3 SpanB · 4 Chikoui.SARstep, max_step0 → Valuei.Supertrendperiod, multiplier0 Value · 1 Direction (+1/-1)i.Pivotmethod (Pivot.*), period (Pivot.Daily/Weekly/Monthly)0 Pivot · 1 R1 · 2 S1 · 3 R2 · 4 S2 · 5 R3 · 6 S3i.ZigZagdeviation, depth, backstep0 → Valuei.Fractalsbars_each_side (default 2)0 Up (price over a swing high) · 1 Down (price under a swing low)i.MACrossfast_period, fast_type, slow_period, slow_type, source0 Fast MA · 1 Slow MAi.RSIperiod, source0 → Value (0–100)i.MACDfast, slow, signal, source0 MACD · 1 Signal · 2 Histogrami.Stochastick_period, d_period, slowing0 %K · 1 %Di.Momentumperiod, source0 → Valuei.DeMarkerperiod0 → Value (0–1)i.WilliamsRperiod0 → Value (−100–0)i.RVIperiod0 → Valuei.BullsPowerperiod0 → Valuei.BearsPowerperiod0 → Valuei.ROCperiod, source0 → Valuei.ATRperiod0 → Valuei.StdDevperiod, source0 → Valuei.OBV—0 → Valuei.MFIperiod0 → Value (0–100)i.CMFperiod0 → Value (−1–+1)i.ForceIndexperiod0 → Valuei.EMA / i.SMA / i.WMA engine for Native.Source — they are i.MA with MA.EMA / MA.SMA / MA.WMA. The lower-case direct calls i.ema(n), i.sma(n), i.wma(n) do exist (see Direct Calls).Price Source & MA Type Enums
Price.ClosePrice.OpenPrice.HighPrice.LowPrice.MedianPrice.TypicalPrice.WeightedMA.SMAMA.EMAMA.WMAMA.HMAMA.DEMAMA.TEMAMA.TMAPivot.TraditionalPivot.FibonacciPivot.WoodiePivot.DailyPivot.WeeklyPivot.MonthlyMedian = (High + Low) / 2, Typical = (High + Low + Close) / 3, Weighted = (High + Low + 2 × Close) / 4. The constants are plain integers, so they can also come from your own enum parameter.
Symbol & Timeframe
| Function / Property | Description |
|---|---|
Native.Init(Symbol(), Timeframe) | The chart’s symbol and timeframe — one value per chart bar. |
Native.Init(Symbol(), Timeframe.H4) | Another timeframe of the chart symbol. Values are drawn one per chart bar (stepped); Name.value(0) is the newest value of the H4 series. |
Native.Init("EURUSD.r", Timeframe.H1) | Another symbol (and timeframe). Its history is loaded in the background (about 500 bars) and kept updated; the symbol joins Market Watch while the script runs and counts toward the plan’s symbol limit. |
The timeframe is a typed value (Timeframe, Timeframe.M1 … Timeframe.MN or bare H4); Native.Init(Symbol(), "H4") is a compile error. Use the standard timeframes M1, M5, M15, M30, H1, H4, D1, W1, MN (see Timeframes).
Custom.Init) on another symbol are not supported yet.Direct Calls
For a single value without a proxy, call an engine directly by its lower-case name: i.rsi(14), or the bare form rsi(14). A direct call returns buffer 0 on the current bar of the chart symbol and timeframe, with the parameters in the registry order. Use a proxy when you need older bars, other buffers, another timeframe or another symbol, or a line on the chart.
| Function / Property | Returns | Description |
|---|---|---|
i.sma(period, source?) / i.ema(…) / i.wma(…) | double | Moving averages (source defaults to Price.Close). |
i.ma(period, MA.*, Price.*) | double | Any MA type, e.g. i.ma(20, MA.HMA, Price.Close). |
i.rsi(period) / rsi(period) | double | RSI of the current bar. |
i.atr(period) | double | ATR of the current bar. |
i.macd(fast, slow, signal, source) | double | MACD line (buffer 0) — fetch Signal / Histogram through a proxy. |
i.<name>(params…) | double | Same for every engine in the registry: buffer 0, current bar. |
// DOCS natives — Direct indicator calls: one value (buffer 0, current bar) without a proxy. NO TRADING.
// Uses: i.ema, i.sma, i.wma, i.rsi, rsi (bare), i.atr, i.ma(period, MA.*, Price.*), i.macd.
// Expect (Journal) once per new bar, real numbers (not NaN):
// [DIRECT] ema=.. sma=.. wma=.. ma_hma=.. (four different averages near the price)
// [DIRECT] rsi=.. rsi_bare=.. (equal, 0..100) atr=.. (> 0) macd=.. (MACD line, around 0)
about {
author: "CoreXTrader";
version: "1.0.0";
about: "Docs natives: direct indicator calls";
}
parameters {
int len_ma = 20; // MA Period
int len_rsi = 14; // RSI Period
}
Init() {
Print("[INIT] direct calls on " + Symbol());
}
Tick() {
if (!Time.IsNewBar()) { return; }
double v_ema = i.ema(len_ma);
double v_sma = i.sma(len_ma);
double v_wma = i.wma(len_ma);
double v_hma = i.ma(len_ma, MA.HMA, Price.Close);
Print("[DIRECT] ema=" + ToString(v_ema) + " sma=" + ToString(v_sma) + " wma=" + ToString(v_wma) + " ma_hma=" + ToString(v_hma));
double v_rsi = i.rsi(len_rsi);
double v_rsi_bare = rsi(len_rsi);
double v_atr = i.atr(14);
double v_macd = i.macd(12, 26, 9, Price.Close);
Print("[DIRECT] rsi=" + ToString(v_rsi) + " rsi_bare=" + ToString(v_rsi_bare) + " atr=" + ToString(v_atr) + " macd=" + ToString(v_macd));
}Signal Helpers
| Function / Property | Parameters | Returns | Description |
|---|---|---|---|
highest(arr,n) | double[] arr, int n | double[] | Rolling maximum: element i = max of arr[i-n+1 .. i]. |
lowest(arr,n) | double[] arr, int n | double[] | Rolling minimum: element i = min of arr[i-n+1 .. i]. |
Crosses are written directly from proxy values on closed bars: Fast.value(2) < Slow.value(2) && Fast.value(1) > Slow.value(1). Comparing bars 1 and 2 (instead of 0 and 1) means the signal cannot appear and vanish inside the forming bar.
Wiring Reference — Ichimoku
Native engines are bound in strategies only (files with Tick()). The proxy name in Native.Bind(Ichi) is the name of its Ichi.calculate() block and of its fields in display and Tick().
// DOCS natives — Ichimoku: full native wiring + a Tenkan / Kijun cross entry above the cloud.
// Uses: Native.Source(i.Ichimoku), Native.Init, Native.Parameter, Native.Bind, Native.Fetch (4 buffers).
// Expect:
// - Tenkan (red) and Kijun (blue) on the price chart, Span A / Span B (green / orange) with a
// light fill between them (the cloud).
// - A BUY (magic 9001, comment "Ichimoku") when Tenkan crosses above Kijun on a closed bar
// while the bid is above the cloud, max one position.
// - Journal once per new bar: [ICHI] tenkan=.. kijun=.. span_a=.. span_b=.. (real numbers).
about {
author: "CoreXTrader";
version: "1.0.0";
about: "Docs natives: Ichimoku wiring";
}
parameters {
int tenkan_p = 9; // Tenkan
int kijun_p = 26; // Kijun
int senkou_p = 52; // Senkou B
int shift_p = 26; // Displacement
double Lot = 0.1; // Lot Size
int Magic = 9001; // Magic Number
}
struct IchiResult { double tenkan; double kijun; double span_a; double span_b; }
display {
outputs: 4
Ichi.tenkan { type: "line"; color: "#dc2626"; name: "Tenkan"; width: 1; };
Ichi.kijun { type: "line"; color: "#3b82f6"; name: "Kijun"; width: 1; };
Ichi.span_a { type: "line"; color: "#16a34a"; name: "Span A"; width: 1; };
Ichi.span_b { type: "line"; color: "#f59e0b"; name: "Span B"; width: 1; };
fill { buffer_a: 2; buffer_b: 3; color: "rgba(34,197,94,0.12)"; };
}
Init() {
Native.Source(i.Ichimoku);
Native.Init(Symbol(), Timeframe);
Native.Parameter(tenkan_p, kijun_p, senkou_p, shift_p); // tenkan, kijun, senkou, displacement
Native.Bind(Ichi);
Print("[INIT] Ichimoku on " + Symbol());
}
// Fetch targets are series buffers (they keep their history between ticks), unique names
Ichi.calculate() {
int len = candle_count();
series double ich_tenkan[]; series double ich_kijun[]; series double ich_span_a[]; series double ich_span_b[];
ich_tenkan[] = create_array(len); ich_kijun[] = create_array(len);
ich_span_a[] = create_array(len); ich_span_b[] = create_array(len);
Native.Fetch(0, ich_tenkan);
Native.Fetch(1, ich_kijun);
Native.Fetch(2, ich_span_a);
Native.Fetch(3, ich_span_b);
return IchiResult { tenkan: ich_tenkan, kijun: ich_kijun, span_a: ich_span_a, span_b: ich_span_b };
}
Tick() {
if (!Time.IsNewBar()) { return; }
Print("[ICHI] tenkan=" + ToString(Ichi.tenkan(1)) + " kijun=" + ToString(Ichi.kijun(1))
+ " span_a=" + ToString(Ichi.span_a(1)) + " span_b=" + ToString(Ichi.span_b(1)));
double cloud_top = Ichi.span_a(1);
if (Ichi.span_b(1) > cloud_top) { cloud_top = Ichi.span_b(1); }
bool above_cloud = Symbol.Bid() > cloud_top;
bool tk_cross = Ichi.tenkan(2) < Ichi.kijun(2) && Ichi.tenkan(1) > Ichi.kijun(1);
if (tk_cross && above_cloud && Position.Count(Symbol(), Magic) == 0) {
int t = Trade.Buy(Symbol(), Lot, 0, 0, "Ichimoku", Magic);
if (t < 0) { Print("[ENTRY] refused (" + ToString(Trade.LastError()) + "): " + Trade.LastErrorText()); }
}
}Multi-Timeframe — H4 Trend, Chart Entry
Three engines in one strategy: an EMA on H4 as the trend filter, RSI and ATR on the chart timeframe for the entry and the stops. Each proxy has its own struct and uniquely named series buffers.
// DOCS natives — Multi-timeframe: H4 EMA trend filter + chart RSI pullback entry + ATR stops.
// Uses: three native proxies — i.MA on Timeframe.H4, i.RSI and i.ATR on the chart timeframe.
// Run it on M15 .. H1.
// Expect:
// - The H4 EMA(50) on the price chart (orange, stepped: one H4 value per chart bar);
// RSI in its own window (blue), ATR in its own window (grey).
// - A BUY (magic 5101) when the bid is above the H4 EMA and RSI crosses back above
// rsi_low; a SELL when the bid is below the H4 EMA and RSI crosses back below
// rsi_high. SL = atr_sl x ATR, TP = atr_tp x ATR. One position at a time.
// - Journal once per new bar: [MTF] h4_ema=.. rsi=.. atr=.. trend=up/down
about {
author: "CoreXTrader";
version: "1.0.0";
about: "Docs natives: H4 trend filter, chart RSI entry";
}
parameters {
int Magic = 5101; // Magic Number
double Lot = 0.1; // Lot Size
int trend_period = 50; // H4 EMA Period
int rsi_period = 14; // RSI Period
double rsi_low = 35.0; // Buy when RSI rises back above
double rsi_high = 65.0; // Sell when RSI falls back below
int atr_period = 14; // ATR Period
double atr_sl = 1.5; // SL (x ATR)
double atr_tp = 3.0; // TP (x ATR)
}
struct MAResult { double value; }
struct RSIResult { double value; }
struct ATRResult { double value; }
display {
outputs: 3
H4Trend.value { type: "line"; color: "#f59e0b"; name: "H4 EMA"; width: 2; };
ChartRSI.value { type: "line"; color: "#3b82f6"; name: "RSI"; width: 2; separate_window: true; };
ChartATR.value { type: "line"; color: "#9ca3af"; name: "ATR"; width: 1; separate_window: true; };
}
Init() {
Native.Source(i.MA);
Native.Init(Symbol(), Timeframe.H4); // EMA calculated on H4
Native.Parameter(trend_period, MA.EMA, Price.Close); // period, type, source
Native.Bind(H4Trend);
Native.Source(i.RSI);
Native.Init(Symbol(), Timeframe); // the chart's own timeframe
Native.Parameter(rsi_period, Price.Close);
Native.Bind(ChartRSI);
Native.Source(i.ATR);
Native.Init(Symbol(), Timeframe);
Native.Parameter(atr_period);
Native.Bind(ChartATR);
Print("[INIT] MTF trend pullback on " + Symbol());
}
H4Trend.calculate() {
int len = candle_count();
series double mtf_ema[];
mtf_ema[] = create_array(len);
Native.Fetch(0, mtf_ema);
return MAResult { value: mtf_ema };
}
ChartRSI.calculate() {
int len = candle_count();
series double mtf_rsi[];
mtf_rsi[] = create_array(len);
Native.Fetch(0, mtf_rsi);
return RSIResult { value: mtf_rsi };
}
ChartATR.calculate() {
int len = candle_count();
series double mtf_atr[];
mtf_atr[] = create_array(len);
Native.Fetch(0, mtf_atr);
return ATRResult { value: mtf_atr };
}
Tick() {
if (!Time.IsNewBar()) { return; }
double h4_ema = H4Trend.value(0);
double atr_v = ChartATR.value(1);
double bid = Symbol.Bid();
double ask = Symbol.Ask();
bool up = bid > h4_ema;
string trend = "down";
if (up) { trend = "up"; }
Print("[MTF] h4_ema=" + ToString(h4_ema) + " rsi=" + ToString(ChartRSI.value(1))
+ " atr=" + ToString(atr_v) + " trend=" + trend);
if (Position.Exists(Symbol(), Magic)) { return; }
if (atr_v <= 0.0 || h4_ema <= 0.0) { return; }
bool rsi_up = ChartRSI.value(2) < rsi_low && ChartRSI.value(1) > rsi_low;
bool rsi_down = ChartRSI.value(2) > rsi_high && ChartRSI.value(1) < rsi_high;
int t = 0;
if (up && rsi_up) {
t = Trade.Buy(Symbol(), Lot, Symbol.NormalizePrice(ask - atr_sl * atr_v), Symbol.NormalizePrice(ask + atr_tp * atr_v), "MTF Long", Magic);
}
if (!up && rsi_down) {
t = Trade.Sell(Symbol(), Lot, Symbol.NormalizePrice(bid + atr_sl * atr_v), Symbol.NormalizePrice(bid - atr_tp * atr_v), "MTF Short", Magic);
}
if (t < 0) { Print("[ENTRY] refused (" + ToString(Trade.LastError()) + "): " + Trade.LastErrorText()); }
}Another Symbol
The same engine twice: once on another symbol's H1, once on the chart. Run it on a chart of a different symbol; on the first run the other symbol's values may be NaN for a moment while its history loads. For raw prices of another symbol use close(sym, tf, n) and Bars.* (see Market Data).
// DOCS natives — A native indicator on ANOTHER symbol and timeframe, next to the chart's own. NO TRADING.
// Uses: Native.Init(other, Timeframe.H1) and Native.Init(Symbol(), Timeframe), Symbol.Bid(other).
// Run it on a chart of a DIFFERENT symbol (e.g. XAUUSD.r M5).
// Expect:
// - EURUSD.r appears in Market Watch while the strategy runs.
// - Two separate windows: EURUSD.r H1 RSI(14) (blue) and the chart's own RSI(14) (orange),
// both between 0 and 100.
// - Journal once per new chart bar: [RSI2] other=.. chart=.. eur_bid=..
// other = the last value of a native RSI(14) on a EURUSD.r H1 chart.
about {
author: "CoreXTrader";
version: "1.0.0";
about: "Docs natives: native on another symbol";
}
parameters {
string other = "EURUSD.r"; // Other Symbol
int rsi_period = 14; // RSI Period
}
struct OtherRSIResult { double value; }
struct ChartRSIResult { double value; }
display {
outputs: 2
OtherRSI.value { type: "line"; color: "#3b82f6"; name: "Other H1 RSI"; width: 2; separate_window: true; };
ChartRSI.value { type: "line"; color: "#f59e0b"; name: "Chart RSI"; width: 2; separate_window: true; };
}
Init() {
Native.Source(i.RSI);
Native.Init(other, Timeframe.H1); // another symbol AND another timeframe
Native.Parameter(rsi_period, Price.Close);
Native.Bind(OtherRSI);
Native.Source(i.RSI);
Native.Init(Symbol(), Timeframe);
Native.Parameter(rsi_period, Price.Close);
Native.Bind(ChartRSI);
Print("[INIT] " + Symbol() + " with " + other + " H1 RSI");
}
OtherRSI.calculate() {
int len = candle_count();
series double os_rsi_other[];
os_rsi_other[] = create_array(len);
Native.Fetch(0, os_rsi_other);
return OtherRSIResult { value: os_rsi_other };
}
ChartRSI.calculate() {
int len = candle_count();
series double os_rsi_chart[];
os_rsi_chart[] = create_array(len);
Native.Fetch(0, os_rsi_chart);
return ChartRSIResult { value: os_rsi_chart };
}
Tick() {
if (!Time.IsNewBar()) { return; }
Print("[RSI2] other=" + ToString(OtherRSI.value(0)) + " chart=" + ToString(ChartRSI.value(0))
+ " eur_bid=" + ToString(Symbol.Bid(other)));
}