millionchart
English

نمونه‌ها: کانال‌ها و سطوح

برنامه‌های نمونه‌ای که باند، کانال و سطح قیمت رسم می‌کنند: باندهای بولینگر، کانال ATR، دانچیان، پیوت روزانه، سطوح کلیدی و باکس بازه.

این اسکریپت‌ها روی نمودار قیمت رسم می‌کنند (display = price): باندهایی دور یک میانگین، سقف و کف یک پنجره، و سطوحی که از روزهای قبل گرفته می‌شوند.

باندهای بولینگر#

یک میانگین متحرک ساده با باندهایی به اندازهٔ چند انحراف معیار بالا و پایین آن، با رنگ بین آن‌ها.

Cuprel
// Bollinger Bands: a simple moving average and bands a number of standard deviations above and below it.
indicator "Bollinger bands"
    edition = 1
    display = price

input length: int = 20, name = "Length", min = 2
input mult: float = 2.0, name = "Deviations", min = 0.1, step = 0.1
let basis = tech.sma(close, length)
let deviation = mult * tech.stdev(close, length)
let upper = basis + deviation
let lower = basis - deviation
let top = plot(upper, name = "Upper", color = color.blue)
let bottom = plot(lower, name = "Lower", color = color.blue)
plot(basis, name = "Basis", color = color.orange)
shade(top, bottom, color = color.fade(color.blue, 92), name = "Band")

چه چیزی یاد می‌دهد: tech.stdev، نگه داشتن دو خط رسم‌شده در نام، و shade بین آن‌ها.

کانال ATR#

میانگینی که به اندازهٔ ضریبی از میانگین دامنهٔ واقعی (اندازهٔ معمول یک کندل) پهن شده است.

Cuprel
// Average True Range: the Wilder mean of max(high - low, |high - previous close|, |low - previous close|).
// The channel is a moving average of the close, widened by a multiple of the ATR.
indicator "ATR channel"
    edition = 1
    display = price

input length: int = 20, name = "Length", min = 2
input mult: float = 2.0, name = "Multiple", min = 0.1, step = 0.1
let basis = tech.ema(close, length)
let range = tech.atr(length)
let upper = basis + mult * range
let lower = basis - mult * range
plot(upper, name = "Upper", color = color.red)
plot(lower, name = "Lower", color = color.green)
plot(basis, name = "Basis", color = color.gray)

چه چیزی یاد می‌دهد: tech.atr و یک ورودی float با step.

کانال دانچیان#

بالاترین سقف و پایین‌ترین کف length کندل آخر، و خط وسط آن دو.

Cuprel
// Donchian Channel: the highest high and the lowest low of the last `length` bars, and their middle.
indicator "Donchian channel"
    edition = 1
    display = price

input length: int = 20, name = "Length", min = 1
let upper = tech.highest(high, length)
let lower = tech.lowest(low, length)
let middle = (upper + lower) / 2
plot(upper, name = "Upper", color = color.green)
plot(lower, name = "Lower", color = color.red)
plot(middle, name = "Middle", color = color.gray)

چه چیزی یاد می‌دهد: tech.highest و tech.lowest روی سقف و کف.

سطوح پیوت روزانه#

پیوت‌های کلاسیک فلور، حساب‌شده از سقف، کف و قیمت بستهٔ روز قبل.

Cuprel
// Classic floor pivots from the previous day: P = (H + L + C) / 3, R1 = 2P - L, S1 = 2P - H.
// `prior(day, 1)` reads the last finished day, so the levels are known from the first bar of the new day.
indicator "Daily pivot levels"
    edition = 1
    display = price

let prior_high = prior(day, 1).high
let prior_low = prior(day, 1).low
let prior_close = prior(day, 1).close
let pivot = (prior_high + prior_low + prior_close) / 3
plot(pivot, name = "Pivot", color = color.gray)
plot(2 * pivot - prior_low, name = "R1", color = color.red)
plot(2 * pivot - prior_high, name = "S1", color = color.green)

چه چیزی یاد می‌دهد: prior(day, 1)، آخرین روزی که تمام شده، که از کندل‌های خود نمودار خوانده می‌شود. آن را روی نمودار درون‌روزی به کار ببرید: روی نمودار روزانه، prior(day) اسکریپت را با E-PERIOD-TF متوقف می‌کند.

سطوح کلیدی#

سقف و کف دیروز و قیمت باز شدن این هفته، با یک علامت جایی که قیمت بسته از سقف یا کف دیروز عبور می‌کند.

Cuprel
// Three levels many traders watch: yesterday's high and low, and the open of the current week.
// prior(day) is the last finished trading day; current(week) is the week that is still forming.
indicator "Key levels"
    edition = 1
    display = price

let day_high = prior(day).high
let day_low = prior(day).low
let week_open = current(week).open
plot(day_high, name = "Yesterday's high", color = color.green, style = step_break)
plot(day_low, name = "Yesterday's low", color = color.red, style = step_break)
plot(week_open, name = "Week open", color = color.blue, style = step_break)
let above = tech.crosses_above(close, day_high)
let below = tech.crosses_below(close, day_low)
mark.shape(
    above,
    name = "Above yesterday's high",
    shape = triangle_up,
    place = below,
    color = color.green,
)
mark.shape(
    below,
    name = "Below yesterday's low",
    shape = triangle_down,
    place = above,
    color = color.red,
)

چه چیزی یاد می‌دهد: prior(day) و current(week)، سبک step_break، و عبور از یک سطح. این هم مثل پیوت‌ها نمودار درون‌روزی می‌خواهد.

رسم بازهٔ اخیر#

یک باکس دور بازهٔ کندل‌های آخر، یک خط‌چین روی قیمت بسته و یک برچسب روی سقف، که فقط یک بار روی جدیدترین کندل رسم می‌شوند.

Cuprel
// Drawing objects on the last bar: a box around the recent range, a dashed line at the close and a label at the high.
indicator "Recent range"
    edition = 1
    display = price

input length: int = 30, name = "Length", min = 2
let top = tech.highest(high, length)
let bottom = tech.lowest(low, length)
if bar.is_last
    box.new(
        bar.index - length + 1,
        top,
        bar.index,
        bottom,
        border_color = color.blue,
        background = color.fade(color.blue, 90),
    )
    line.new(
        bar.index - length + 1,
        close,
        bar.index,
        close,
        extend = right,
        style = dashed,
        color = color.orange,
    )
    label.new(bar.index, top, f"High {top:price}", style = label_down)
plot(close, name = "Close", color = color.gray)

چه چیزی یاد می‌دهد: ترسیم‌ها (box.new، line.new، label.new) که با شمارهٔ کندل و قیمت جا گذاشته می‌شوند، و bar.is_last برای این‌که فقط یک بار رسم شوند.