سریها و کندلها
قیمتها سریاند، یک مقدار برای هر کندل، و `close[1]` بستهشدن کندل قبلی است. این مثالها اندیکاتورها را از روی تعریفشان میسازند.
قیمتها سریاند، یعنی برای هر کندل یک مقدار. خواندن close[1] قیمت بستهشدن کندل قبلی را میدهد، و تابعی مثل tech.ema حافظهٔ خودش را از کندلی به کندل بعد نگه میدارد.
جفت EMA با علامت تقاطع#
دو میانگین متحرک نمایی و یک علامت در جایی که همدیگر را قطع میکنند.
Cuprel
// Two exponential moving averages and a mark where the fast one crosses the slow one.
// EMA(t) = alpha * price + (1 - alpha) * EMA(t - 1), with alpha = 2 / (length + 1).
indicator "EMA pair"
edition = 1
display = price
input fast_length: int = 12, name = "Fast length", min = 1
input slow_length: int = 26, name = "Slow length", min = 2
let fast = tech.ema(close, fast_length)
let slow = tech.ema(close, slow_length)
plot(fast, name = "Fast", color = color.green)
plot(slow, name = "Slow", color = color.red)
mark.shape(
tech.crosses_above(fast, slow),
name = "Up",
shape = triangle_up,
place = below,
color = color.green,
)
mark.shape(
tech.crosses_below(fast, slow),
name = "Down",
shape = triangle_down,
place = above,
color = color.red,
)RSI نوشتهشده با دست#
RSI وایلدر، ساختهشده از سودها، زیانها و میانگین جاری، همراه با سطحها.
Cuprel
// Wilder's Relative Strength Index written out: RS = average gain / average loss and RSI = 100 - 100 / (1 + RS).
// The averages are Wilder's running means (tech.rma), the same smoothing the built-in tech.rsi uses.
indicator "RSI by hand"
edition = 1
display = pane
input length: int = 14, name = "Length", min = 2
let change = close - close[1]
let gain = math.max(change, 0)
let loss = math.max(-change, 0)
let average_gain = tech.rma(gain, length)
let average_loss = tech.rma(loss, length)
let strength = average_gain / average_loss
let value = 100 - 100 / (1 + strength)
plot(value, name = "RSI", color = color.purple)
level(70, name = "Overbought", color = color.red, style = dashed)
level(30, name = "Oversold", color = color.green, style = dashed)کندلهای درونی#
یک الگوی کندلی از روی تعریفش، با استفاده از مقدار کندلهای قبلی.
Cuprel
// A candlestick pattern from its definition: an inside bar has a high below and a low above the bar before it.
// A close above the mother bar's high after an inside bar is marked as a break.
indicator "Inside bars"
edition = 1
display = price
let inside = high < high[1] and low > low[1]
let broke_up = inside[1] and close > high[2]
let broke_down = inside[1] and close < low[2]
mark.char(inside, name = "Inside bar", char = "i", place = above, color = color.gray)
mark.shape(broke_up, name = "Break up", shape = triangle_up, place = below, color = color.green)
mark.shape(broke_down, name = "Break down", shape = triangle_down, place = above, color = color.red)تعداد کندل از آخرین سقف#
حالتی که بین کندلها نگه داشته میشود و با انتساب از نوع mut تغییر میکند.
Cuprel
// A value the script keeps between bars: `state` starts once, `mut` changes it.
// This counts the bars since the close last made a 20-bar high, and resets it on every new high.
indicator "Bars since a high"
edition = 1
display = pane
input length: int = 20, name = "Length", min = 2
state count = 0
let new_high = close >= tech.highest(close, length)
if new_high
count = 0
else
count += 1
plot(count, name = "Bars since", style = histogram, color = color.teal)