多 TF 卷 Table(Pine 脚本)

Multi-TF Volume Table (Pine Script)

我正在制作一个指标来计算两个 EMA,比较哪个更大,然后向用户提供看涨或看跌的偏见(通过为 table 的第二行着色)。我已经能够为单个 TF 成功执行此操作,但目标是让它一次显示多个 TF(特别是 6 [D1、H4、H1、M15、M5、M1)的计算偏差。

我试图将计算和 table 填充包含在一个函数中,以便于重复和提高可读性。

编译和 运行 时,它没有显示任何错误,但由于某种原因,图表上实际上没有显示任何内容(即使我将其添加到图表中)

非常感谢任何帮助!

代码:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tonemontgomery

//@version=5
indicator("MA Volume Bias", overlay = true)


src = input.source(defval = close, title= "Source", inline = "1", group = "EMA Settings")

len1 = input(defval = 25, title = "Period", inline = "2", group = "EMA Settings")
len2 = input(defval = 50, title = "", inline = "2", group = "EMA Settings")

color_bull = input.color(color.blue, "Bullish", group = "Table Settings")
color_bear = input.color(color.red, "Bearish", group = "Table Settings")

D1_show = input.bool(false, "Show D1 EMAs")
H4_show = input.bool(false, "Show H4 EMAs")
H1_show = input.bool(false, "Show H1 EMAs")
m15_show = input.bool(false, "Show M15 EMAs")
m5_show = input.bool(false, "Show M5 EMAs")
m1_show = input.bool(false, "Show M1 EMAs")


bias_table = table.new(position = position.top_right, columns = 6, rows = 2, frame_width 
= 1, frame_color = color.black, border_color = color.black,  border_width = 2, bgcolor = color.new(#9598a1, 84))

 
master_function(_TF, _column) =>
    data = request.security("", _TF, src)
    ema1 = ta.ema(data, len1)
    ema2 = ta.ema(data, len2)
    volume_bias = ema1 > ema2
    color_bias = volume_bias == true ? color_bull : color_bear
    if barstate.islast
        table.cell(table_id = bias_table, column = _column, row = 0, text = _TF, width = 3, height = 4, text_size = size.auto)
        table.cell(table_id = bias_table, column = _column, row = 1, text = "", width = 3, height = 4, bgcolor = color_bias)
    [color_bias, ema1, ema2]
    
    
master_function("D1", 0)
master_function("H4", 1)
master_function("H1", 2)
master_function("15", 3)
master_function("5", 4)
master_function("1", 5)

在图表上的指标名称旁边会有一个红色感叹号,如果您单击它,它会显示一条错误消息,说明分辨率无效。

Pine 期望不同的 timeframe/resolution 具有特定的格式。一维、二维、240(对于 H4)等

master_function("1D", 0)
master_function("240", 1)
master_function("60", 2)
master_function("15", 3)
master_function("5", 4)
master_function("1", 5)```