多-TF音量表(Pine脚本)
我正在制作一个指标来计算两个EMA,比较一个更大的emas,然后将用户带来看涨或看跌的偏见(通过为表的第二行着色)。我已经能够成功地为一个TF做到这一点,但是目标是使其显示多个TF(特别是6 [D1,H4,H1,M15,M5,M1)的计算偏置。
我试图将函数中的计算和表格包含在功能中,以方便重复和可读性。
在编译和运行时,它没有显示错误,但是由于某种原因,图表上实际上没有任何实际显示(即使在图表中添加到图表之后),
任何帮助都将不胜感激!
代码:
// 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)
I'm making an indicator to calculate two EMAs, compare which one is greater, and then deliver the user a bias of bullish or bearish (by coloring the second row of a table). I've been able to do this successfully for a single TF, but the goal is to have it display the calculated bias for multiple TFs (specifically 6 [D1, H4, H1, M15, M5, M1) at once.
I'm trying to contain the calculations and table population within a function for easy reiteration and readability.
When compiling and running, it shows no errors, but for some reason nothing actually shows on the chart (even after I add it to the chart)
Any help would be highly appreciated!
Code:
// 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在图表上的指示名称旁边,您将有一个红色的感叹号,如果单击它,它将显示一条错误消息,说明该分辨率无效。
Pine期望不同的时间范围/分辨率为特定格式。 1d,2d,240(用于H4)等
Next to the indicator name on the chart you would have had a red exclamation mark, if you click on it, it would display an error message explaining that the resolution was invalid.
Pine expects the different timeframe/resolution to be in a specific format. 1D, 2D, 240 (for H4) etc