Full Examples
Five production-ready scripts covering the most common TDSL patterns. Copy any example directly into a .tbc file.
RSI_MeanReversion.tbcTDSL
about { author: "CoreXTrader"; version: "1.0.0"; }
parameters { int period = 14; double overbought = 70.0; double oversold = 30.0; }
struct RSIResult { double value; double level_ob; double level_os; }
display {
separate_window: true; outputs: 3
RSIResult.value { type: "line"; color: "#dc2626ff"; name: "RSI"; width: 2; };
RSIResult.level_ob { type: "line"; color: "#f97316aa"; name: "Overbought"; width: 1; };
RSIResult.level_os { type: "line"; color: "#22c55eaa"; name: "Oversold"; width: 1; };
}
series double rsi_vals[]; series double ob_line[]; series double os_line[];
calculate() {
double closes[] = close();
int len = length(closes);
int start = Chart.resume_index > 0 ? Chart.resume_index - 1 : period;
rsi_vals[] = create_array(len); ob_line[] = create_array(len); os_line[] = create_array(len);
for (int i = start; i < len; i = i + 1) {
double gain = 0.0; double loss = 0.0;
for (int j = 1; j <= period; j = j + 1) {
double diff = closes[i - j + 1] - closes[i - j];
if (diff > 0.0) { gain = gain + diff; } else { loss = loss - diff; }
}
double avg_gain = gain / period; double avg_loss = loss / period;
rsi_vals[i] = avg_loss == 0.0 ? 100.0 : 100.0 - (100.0 / (1.0 + avg_gain / avg_loss));
ob_line[i] = overbought; os_line[i] = oversold;
}
return RSIResult { value: rsi_vals, level_ob: ob_line, level_os: os_line };
}