本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Multi Timeframe Simple Bias", overlay=true)
// ─────────────────────────────────────────────────────────────────────────────
// SETTINGS
// ─────────────────────────────────────────────────────────────────────────────
emaLength = 50
showEma = input.bool(false, title="Show EMA on Chart", display=display.none)
tableSize = input.string("Small", title="Table Size", options=["Tiny", "Small", "Normal", "Large", "Huge"])
// ─────────────────────────────────────────────────────────────────────────────
// ORIGINAL BIAS ENGINE — UNCHANGED
// ─────────────────────────────────────────────────────────────────────────────
f_get_bias(_tf) =>
price_tf = request.security(syminfo.tickerid, _tf, close)
ema_tf = request.security(syminfo.tickerid, _tf, ta.ema(close, emaLength))
bias = price_tf > ema_tf ? "UP" : "DOWN"
color = price_tf > ema_tf ? color.rgb(1, 85, 4) : color.rgb(247, 4, 4)
[bias, color]
[bias_1m, color_1m] = f_get_bias("1")
[bias_5m, color_5m] = f_get_bias("5")
[bias_15m, color_15m] = f_get_bias("15")
[bias_1h, color_1h] = f_get_bias("60")
[bias_4h, color_4h] = f_get_bias("240")
[bias_d, color_d] = f_get_bias("D")
[bias_w, color_w] = f_get_bias("W")
// ─────────────────────────────────────────────────────────────────────────────
// TABLE VISUALS
// ─────────────────────────────────────────────────────────────────────────────
f_table_text_size(_size) =>
switch _size
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
=> size.huge
headerBg = color.rgb(24, 24, 24)
labelBg = color.rgb(52, 52, 52)
frameCol = color.rgb(92, 92, 92)
textCol = color.white
txtSize = f_table_text_size(tableSize)
var biasTable = table.new(
position.top_center,
8,
2,
bgcolor=color.new(color.black, 100),
frame_color=frameCol,
frame_width=1,
border_color=color.rgb(70, 70, 70),
border_width=1)
if barstate.islast
table.cell(biasTable, 0, 0, "TF", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 1, 0, "1M", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 2, 0, "5M", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 3, 0, "15M", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 4, 0, "1H", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 5, 0, "4H", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 6, 0, "1D", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 7, 0, "1W", text_color=textCol, bgcolor=headerBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 0, 1, "BIAS", text_color=textCol, bgcolor=labelBg, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 1, 1, bias_1m, text_color=textCol, bgcolor=color_1m, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 2, 1, bias_5m, text_color=textCol, bgcolor=color_5m, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 3, 1, bias_15m, text_color=textCol, bgcolor=color_15m, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 4, 1, bias_1h, text_color=textCol, bgcolor=color_1h, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 5, 1, bias_4h, text_color=textCol, bgcolor=color_4h, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 6, 1, bias_d, text_color=textCol, bgcolor=color_d, text_size=txtSize, text_halign=text.align_center)
table.cell(biasTable, 7, 1, bias_w, text_color=textCol, bgcolor=color_w, text_size=txtSize, text_halign=text.align_center)
// ─────────────────────────────────────────────────────────────────────────────
// EMA DISPLAY
// ─────────────────────────────────────────────────────────────────────────────
plot(showEma ? ta.ema(close, emaLength) : na, color=color.rgb(247, 247, 248), linewidth=1, title="EMA", display=display.all - display.status_line - display.price_scale)