نمونهها: سشنها، الگوها و حجم
برنامههای نمونه برای سشنها، الگوهای کندلی و حجم: باکس سشن، بازهٔ آغازین، کندل درونی، سوئینگها، OBV، جهش حجم و یک جدول.
این برنامهها با ساعت روز، شکل کندلها و حجم کار میکنند. برنامههای سشن روی نمودار درونروزی بیشترین معنا را دارند.
باکسهای بازهٔ سشن#
یک باکس روی هر سشن تمامشدهٔ توکیو، از سقف تا کف آن.
// A box over every finished session, from its high to its low. The members of a declared session tell where the bar stands in it:
// .start is true on its first bar, .end on its last, .active while the bar is inside, .index counts the sessions, and .high and .low are the extremes so far.
indicator "Session range boxes"
edition = 1
display = price
max_boxes = 100
session asia = 00:00 .. 08:00 @ "Asia/Tokyo"
state first_bar = 0
if asia.start
first_bar = bar.index
if asia.end
box.new(
first_bar,
asia.high,
bar.index,
asia.low,
border_color = color.purple,
background = color.fade(color.purple, 90),
)
plot(
if asia.active then asia.high - asia.low else na,
name = "Range so far",
style = histogram,
color = color.purple,
)
plot(asia.index, name = "Session number", display = none)چه چیزی یاد میدهد: یک session نامدار با ساعتها و منطقهٔ زمانیاش، و عضوهای آن: .start و .end روی اولین و آخرین کندل، .active تا وقتی کندل داخل سشن است، .high و .low تا این لحظه، و .index.
بازهٔ آغازین#
سقف و کف ساعت اول سشن لندن، و یک علامت جایی که قیمت بعداً در همان روز بیرون از این بازه بسته میشود.
// The opening range: the high and low of the first hour of the London session, and a mark where the price closes outside it later that day.
// The crossing tests keep a state, so they are worked out on every bar first and only then combined with "not in the range hour".
indicator "Opening range"
edition = 1
display = price
session opening = 08:00 .. 09:00 @ "Europe/London"
state top: float = na
state bottom: float = na
if opening.start
top = high
bottom = low
else if opening.active
top = math.max(top, high)
bottom = math.min(bottom, low)
let crossed_up = tech.crosses_above(close, top)
let crossed_down = tech.crosses_below(close, bottom)
let after = not opening.active
plot(if after then top else na, name = "Range high", color = color.green, style = step_break)
plot(if after then bottom else na, name = "Range low", color = color.red, style = step_break)
mark.shape(
crossed_up and after,
name = "Break up",
shape = triangle_up,
place = below,
color = color.green,
)
mark.shape(
crossed_down and after,
name = "Break down",
shape = triangle_down,
place = above,
color = color.red,
)چه چیزی یاد میدهد: مقدارهای state که در شروع سشن مقدار میگیرند و تا وقتی سشن ادامه دارد پهنتر میشوند، و اینکه چرا آزمونهای عبور پیش از ترکیب شدن با یک شرط در خطهای جداگانه نوشته میشوند (ببینید خواندن پیامهای ویرایشگر).
کندلهای درونی#
کندل درونی سقفش پایینتر و کفش بالاتر از کندل قبلی است. اسکریپت روی هر کدام علامت میگذارد، و وقتی قیمت بستهٔ بعدی از بازهٔ کندل قبل از آن بیرون برود، یک شکست را علامت میزند.
// 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)چه چیزی یاد میدهد: شرط روی کندلهای قبلی با [1] و [2]، mark.char با یک حرف و mark.shape با یک مثلث.
پیوتهای سوئینگ#
یک برچسب با قیمت روی هر سقف سوئینگ و کف سوئینگ.
// Swing structure: a swing high is a bar whose high is the highest of `left` bars before it and `right` bars after it.
// The pivot is only known `right` bars later, so the label is placed back on the bar where the swing happened.
indicator "Swing pivots"
edition = 1
display = price
max_labels = 200
input left: int = 5, name = "Bars on the left", min = 1
input right: int = 5, name = "Bars on the right", min = 1
let swing_high = tech.pivot_high(high, left, right)
let swing_low = tech.pivot_low(low, left, right)
if not is_na(swing_high)
label.new(
bar.index - right,
swing_high,
f"{swing_high:price}",
style = label_down,
color = color.red,
)
if not is_na(swing_low)
label.new(
bar.index - right,
swing_low,
f"{swing_low:price}",
style = label_up,
color = color.green,
)
plot(close, name = "Close", color = color.gray)چه چیزی یاد میدهد: tech.pivot_high و tech.pivot_low، label.new، و max_labels در هدر. سوئینگ فقط right کندل بعد از وقوعش شناخته میشود، برای همین برچسب به عقب، روی کندل سوئینگ گذاشته میشود؛ صفحهٔ نتیجههایی که زیادی خوب به نظر میرسند توضیح میدهد این برای یک سیگنال چه معنایی دارد. اسکریپت جدیدترین 200 برچسب را نگه میدارد (max_labels = 200)؛ روی نموداری با کندلهای زیاد، قدیمیترینها حذف میشوند و موتور این را با اخطار W-OBJECT-LIMIT میگوید. max_labels را بالا ببرید (نمودار تا 500 اجازه میدهد) یا از تایمفریم بلندتری استفاده کنید.
حجم تعادلی (OBV)#
جمع جاریای که حجم را در بسته شدن صعودی اضافه و در بسته شدن نزولی کم میکند، با یک خط سیگنال هموارشده.
// On-Balance Volume: add the volume on an up close, subtract it on a down close, and smooth the running total.
indicator "On-balance volume"
edition = 1
display = pane
input length: int = 20, name = "Signal length", min = 1
let direction = math.sign(close - close[1])
let obv = tech.cum_sum(direction * volume)
plot(obv, name = "OBV", color = color.blue)
plot(tech.ema(obv, length), name = "Signal", color = color.orange)چه چیزی یاد میدهد: math.sign، tech.cum_sum و volume.
جهشهای حجم#
کندلهایی که حجمشان خیلی بالاتر از میانگین اخیر است علامت میخورند و ستونشان رنگ میگیرد.
// Volume spikes: a bar whose volume is far above its recent average is marked and its column is coloured.
indicator "Volume spikes"
edition = 1
display = pane
input length: int = 20, name = "Average length", min = 2
input factor: float = 2.0, name = "Spike factor", min = 1.0, step = 0.1
let average = tech.sma(volume, length)
let spike = volume > average * factor
plot(volume, name = "Volume", style = columns, color = if spike then color.orange else color.gray)
plot(average, name = "Average", color = color.blue)
mark.shape(spike, name = "Spike", shape = circle, place = top, color = color.orange)چه چیزی یاد میدهد: سبک columns با رنگ جدا برای هر کندل، و یک علامت در top (بالای) پنل.
جدول وضعیت#
یک جدول کوچک در گوشهٔ نمودار با قیمت بسته، RSI و ATR، که فقط روی جدیدترین کندل نوشته میشود.
// A small table in the corner of the chart, written on the last bar only.
indicator "Status table"
edition = 1
display = price
input length: int = 14, name = "Length", min = 2
let strength = tech.rsi(close, length)
let volatility = tech.atr(length)
if bar.is_last
let t = table.new(
top_right,
2,
3,
background = color.fade(color.black, 70),
border_color = color.gray,
border_width = 1,
)
table.cell(t, 0, 0, "Close", text_color = color.silver, h_align = left)
table.cell(t, 1, 0, f"{close:price}", text_color = color.white)
table.cell(t, 0, 1, "RSI", text_color = color.silver, h_align = left)
table.cell(t, 1, 1, f"{strength:.1f?'n/a'}", text_color = color.white)
table.cell(t, 0, 2, "ATR", text_color = color.silver, h_align = left)
table.cell(t, 1, 2, f"{volatility:price?'n/a'}", text_color = color.white)
plot(close, name = "Close", color = color.gray)چه چیزی یاد میدهد: table.new و table.cell، و f-textهایی مثل f"{close:price}" که عدد را با تعداد اعشار خود نماد مینویسند؛ تا وقتی مقدار na است، ?'n/a' نوشته میشود.