Visuals, Tables & Alerts
Kafal scripts can emit visual primitives, data tables, and alerts. Output records are serialized directly into the JSON response contract for frontend rendering.
Line Plots & Horizontal Levels
plot() renders continuous time-series curves, while hline() renders fixed price levels across the chart canvas.
// Basic Plots & Horizontal Lines
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
plot(close, title="Price", color="black")
plot(fast, title="Fast SMA", color="blue", width=2)
plot(slow, title="Slow SMA", color="red", width=2)
// Draw fixed price levels
hline(100.0, title="Support", color="green", linestyle="dashed")Fills, Background Colors & Shapes
Use fill() to shade regions between two time-series, bgcolor() for conditional chart background highlighting, and shape() to place signal icons relative to candles.
// Background Shading, Band Fills, and Condition Markers
upper, basis, lower = ta.bbands(close, 20, 2.0, 2.0)
// Fill region between Bollinger Bands
fill(upper, lower, title="Bollinger Band Region", color="purple", alpha=0.1)
// Highlight bullish trend regions in background
bgcolor(close > basis, color="green", alpha=0.05)
// Mark crossover signals on chart
bull_signal = crossover(fast, slow)
shape(bull_signal, title="Buy Signal", shape="triangle_up", location="belowbar", color="green", size="medium")Tables & Alerts
table() constructs tabular metric views. alert() captures condition triggers along with message strings and severity tags.
// Status Tables & Real-Time Alerts
rsi_val = ta.rsi(close, 14)
// Output a key-value metric table for UI rendering
table(
"RSI Status",
"Current RSI", rsi_val,
position="top_right", theme="dark", compact=true
)
// Trigger structured alert payloads
alert(rsi_val > 70.0, message="RSI Overbought Warning", severity="warning")
alert(rsi_val < 30.0, message="RSI Oversold Signal", severity="info")Supported Style Attributes
| Command | Valid Attribute Keys |
|---|---|
| plot() | color, width, title, linestyle, style, marker |
| shape() | color, size, text, location, shape |
| hline() | color, width, linestyle, title |
| fill() | color, alpha, title |
| bgcolor() | color, alpha |
| alert() | message, severity |
| table() | position, theme, compact |