Full Examples
Ten complete scripts — three indicators and seven strategies — from a fixed-scale oscillator to multi-symbol dashboards, pending OCO orders, basket grids and a timer-driven equity guard. Each one compiles as shown: copy it into a .tdsl file in your indicators or strategies folder. The comment at the top of every script says what it shows and what to expect on the chart and in the Journal.
Note
The Multi-Symbol examples read other symbols with
close(symbol, timeframe, shift), Bars.Shift and Symbol.Bid(symbol). They run on live charts; the strategy tester runs on the chart symbol only and has no data of other symbols yet. Another symbol through a Custom.Init proxy is not supported yet either — use Native.Init(otherSymbol, Timeframe.H1) or the price accessors.Tip
Every strategy uses its own magic number and filters each position loop by symbol and magic, so several examples can run side by side on one account. The equity guard is the exception by design: with its defaults it closes every position on the account at the drawdown limit.
examples_rsi_signal.tdslTDSL
// Docs / Full Examples — RSI with signal line, price-source dropdown, fixed scale and levels.
// Shows: enum parameter dropdown, global series buffers, Wilder smoothing, EMA signal,
// incremental loop with Chart.resume_index, display scale fixed(0, 100) + levels.
// Expect: one separate window fixed 0..100 with a blue RSI line, a dashed orange signal line
// and chart level lines at 30 / 50 / 70. Changing "Price Source" changes the line.
about {
author: "CoreXTrader";
version: "1.0.0";
about: "Wilder RSI on a selectable source with an EMA signal line";
}
enum Source {
Close = 0, // Close
Median = 1, // (High + Low) / 2
Typical = 2 // (High + Low + Close) / 3
}
parameters {
string _RSI_ = "====== RSI ======";
int period = 14; // RSI Period
Source src = Source.Close; // Price Source
string _Signal_ = "====== Signal ======";
int signal_len = 9; // Signal EMA Length
}
struct RSISignal {
double rsi;
double signal;
}
display {
separate_window: true;
scale: fixed(0, 100);
levels: [30, 50, 70];
outputs: 2
RSISignal.rsi { type: "line"; color: "#3b82f6"; name: "RSI"; width: 2; };
RSISignal.signal { type: "line"; color: "#f59e0b"; name: "Signal"; width: 1; style: "dashed"; };
}
series double rs_price[];
series double rs_up[];
series double rs_dn[];
series double rs_rsi[];
series double rs_sig[];
calculate() {
double closes[] = close();
double highs[] = high();
double lows[] = low();
int len = length(closes);
rs_price[] = create_array(len);
rs_up[] = create_array(len);
rs_dn[] = create_array(len);
rs_rsi[] = create_array(len);
rs_sig[] = create_array(len);
double pd = period;
double pm = pd - 1.0;
double sl = signal_len;
double alpha = 2.0 / (sl + 1.0);
int start = Chart.resume_index;
if (start > 0) {
start = start - 1; // recalculate the previous bar too
} else {
start = 0;
}
for (int i = start; i < len; i = i + 1) {
// price source from the dropdown
rs_price[i] = closes[i];
if (src == Source.Median) { rs_price[i] = (highs[i] + lows[i]) / 2.0; }
if (src == Source.Typical) { rs_price[i] = (highs[i] + lows[i] + closes[i]) / 3.0; }
if (i < period) {
rs_rsi[i] = 50.0;
rs_sig[i] = 50.0;
} else {
if (i == period) {
// seed: simple average of the first `period` gains / losses
double g = 0.0;
double l = 0.0;
for (int j = 1; j <= period; j = j + 1) {
double d0 = rs_price[j] - rs_price[j - 1];
if (d0 > 0.0) { g = g + d0; } else { l = l - d0; }
}
rs_up[i] = g / pd;
rs_dn[i] = l / pd;
} else {
// Wilder smoothing
double d = rs_price[i] - rs_price[i - 1];
double up = 0.0;
double dn = 0.0;
if (d > 0.0) { up = d; } else { dn = 0.0 - d; }
rs_up[i] = (rs_up[i - 1] * pm + up) / pd;
rs_dn[i] = (rs_dn[i - 1] * pm + dn) / pd;
}
rs_rsi[i] = rs_dn[i] == 0.0 ? 100.0 : 100.0 - (100.0 / (1.0 + rs_up[i] / rs_dn[i]));
// EMA of the RSI, seeded with the first RSI value
if (i == period) {
rs_sig[i] = rs_rsi[i];
} else {
rs_sig[i] = rs_sig[i - 1] + alpha * (rs_rsi[i] - rs_sig[i - 1]);
}
}
}
return RSISignal { rsi: rs_rsi, signal: rs_sig };
}