نمونهها: الگوهای کندلی
برنامههای نمونهای که الگوهای کندلی را از روی تعریفشان پیدا میکنند: پوشا، دوجی، چکش، کندلهای پشتسرهم، گپ، کندل بیرونی و جای بستهشدن.
الگوی کندلی قاعدهای است دربارهٔ قیمت بازشدن، بالاترین، پایینترین و بستهشدن یک کندل و کندلهای پیش از آن. هر برنامهٔ این صفحه قاعده را به شکل یک شرط مینویسد و کندلهایی را که شرط در آنها درست است علامت میزند. الگو توصیف میکند که قیمت چه کرده است؛ پیشبینی نمیکند که چه خواهد کرد. پیش از آنکه بر اساس یک الگو معامله کنید، نتیجههایی که زیادی خوب به نظر میرسند را بخوانید.
کندلهای پوشا#
کندلی که بدنهاش تمام بدنهٔ کندل قبلی را میپوشاند و در جهت مخالف بسته میشود.
// Engulfing bars: a bar whose body covers the whole body of the bar before it, in the other direction.
// A bullish engulfing bar is up and its body runs from below the previous open to above the previous close.
indicator "Engulfing bars"
edition = 1
display = price
let body_top = math.max(open, close)
let body_bottom = math.min(open, close)
let bullish = close > open
and close[1] < open[1]
and body_top >= body_top[1]
and body_bottom <= body_bottom[1]
let bearish = close < open
and close[1] > open[1]
and body_top >= body_top[1]
and body_bottom <= body_bottom[1]
mark.shape(
bullish,
name = "Bullish engulfing",
shape = triangle_up,
place = below,
color = color.green,
)
mark.shape(
bearish,
name = "Bearish engulfing",
shape = triangle_down,
place = above,
color = color.red,
)چه چیزی یاد میدهد: بدنهٔ کندل با math.max(open, close) و math.min(open, close)، مقایسه با کندل قبلی از راه [1]، و دو علامت از دو شرط.
دوجی#
کندلی که بدنهاش در برابر کل دامنهاش بسیار کوچک است.
// Doji: a bar whose body is very small next to its whole range, so the open and the close are almost the same price.
indicator "Doji"
edition = 1
display = price
input ratio: float = 0.1,
name = "Largest body (share of the range)",
min = 0.01,
max = 0.5,
step = 0.01
let range = high - low
let body = math.abs(close - open)
let doji = range > 0 and body <= range * ratio
mark.char(doji, name = "Doji", char = "+", place = above, color = color.gray)چه چیزی یاد میدهد: یک ورودی float که به شکل سهم به کار میرود، math.abs، و یک محافظ (range > 0) تا کندلی که هیچ دامنهای ندارد هرگز شمرده نشود.
چکش و ستارهٔ دنبالهدار#
بدنهای کوچک در یک سر کندل و سایهای بلند در سر دیگر.
// Hammer and shooting star: a small body at one end of the bar and a long shadow at the other end.
// The shadow must be at least `factor` times the body, and the shadow on the body's side must be short.
indicator "Hammer and shooting star"
edition = 1
display = price
input factor: float = 2.0, name = "Shadow over body", min = 1.0, step = 0.5
let body = math.abs(close - open)
let lower_shadow = math.min(open, close) - low
let upper_shadow = high - math.max(open, close)
let hammer = body > 0 and lower_shadow >= body * factor and upper_shadow <= body
let star = body > 0 and upper_shadow >= body * factor and lower_shadow <= body
mark.shape(hammer, name = "Hammer", shape = triangle_up, place = below, color = color.teal)
mark.shape(star, name = "Shooting star", shape = triangle_down, place = above, color = color.orange)چه چیزی یاد میدهد: سایهٔ بالا و پایین یک کندل، و اینکه چطور یک ورودی (factor) همزمان دو الگو را تنظیم میکند.
کندلهای پشتسرهم#
علامتی بعد از چند بستهشدن صعودی پشتسرهم، یا چند بستهشدن نزولی پشتسرهم.
// Runs of bars: a mark after `count` up closes in a row, or `count` down closes in a row.
// tech.bars_since counts the bars since the last time the condition was true.
indicator "Bars in a row"
edition = 1
display = price
input count: int = 3, name = "Bars in a row", min = 2, max = 10
let up = close > close[1]
let down = close < close[1]
let up_run = tech.bars_since(not up)
let down_run = tech.bars_since(not down)
mark.shape(
up_run == count,
name = "Up run",
shape = triangle_up,
place = below,
color = color.green,
)
mark.shape(
down_run == count,
name = "Down run",
shape = triangle_down,
place = above,
color = color.red,
)چه چیزی یاد میدهد: tech.bars_since که تعداد کندلها را از آخرین باری که یک شرط درست بوده میشمارد. اینجا از آخرین کندلی میشمارد که صعودی بسته نشده، و این همان طول رشتهٔ صعودی فعلی است.
گپها#
کندلی که بالاتر از بالاترین قیمت قبلی یا پایینتر از پایینترین قیمت قبلی باز شود، یک گپ به جا میگذارد. یک باکس فضای خالی را نشان میدهد.
// Gaps: the bar opens above the previous high or below the previous low, so no trade happened in between.
// A box marks the empty space; the boxes of the last gaps are kept.
indicator "Gaps"
edition = 1
display = price
max_boxes = 50
let gap_up = low > high[1]
let gap_down = high < low[1]
if gap_up
box.new(
bar.index - 1,
low,
bar.index,
high[1],
border_color = color.green,
background = color.fade(color.green, 80),
)
if gap_down
box.new(
bar.index - 1,
low[1],
bar.index,
high,
border_color = color.red,
background = color.fade(color.red, 80),
)
plot(close, name = "Close", color = color.gray)چه چیزی یاد میدهد: box.new با دو گوشه (شمارهٔ کندل و قیمت)، max_boxes در سرآیند، و ترسیمی که داخل یک if ساخته میشود. در بازاری که شبانهروزی معامله میشود، گپ در طول روز کمیاب است و بیشتر بعد از تعطیلی آخر هفته یا یک وقفه دیده میشود.
کندلهای بیرونی#
کندلی که بالاترینش بالاتر و پایینترینش پایینتر از کندل قبلی است، با رنگی که جهت بستهشدنش را نشان میدهد.
// Outside bar: a bar whose high is above and whose low is below the bar before it. Its colour says which way it closed.
indicator "Outside bars"
edition = 1
display = price
let outside = high > high[1] and low < low[1]
let tint = if close > open then color.green else color.red
chart.candles(if outside then tint else na, name = "Outside bars")
mark.char(outside, name = "Outside bar", char = "o", place = above, color = color.gray)چه چیزی یاد میدهد: chart.candles برای رنگ کردن فقط بعضی از کندلها (na بقیه را همانطور که هستند میگذارد) و mark.char با یک حرف.
جای بستهشدن در کندل#
جای قیمت بستهشدن در دامنهٔ کندل، از 0 در پایینترین تا 100 در بالاترین، همراه با یک خط هموارشده.
// Close position in the bar: 100 when the bar closed at its high, 0 at its low.
// A long run of high readings means buyers kept the price near the top of each bar.
indicator "Close position in the bar"
edition = 1
display = pane
input length: int = 10, name = "Smoothing", min = 1
let range = high - low
let position = if range > 0 then 100 * (close - low) / range else 50
let smoothed = tech.sma(position, length)
plot(position, name = "Position", style = columns, color = color.fade(color.blue, 60))
plot(smoothed, name = "Smoothed", color = color.orange, width = 2)
level(50, name = "Middle", color = color.gray, style = dashed)چه چیزی یاد میدهد: یک if ... then ... else که از یک تقسیم محافظت میکند (کندلی که دامنه ندارد مقدار 50 میگیرد)، سبک columns و یک رنگ کمرنگشده.