'Multi-TF Volume Table (Pine Script)
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)
Solution 1:[1]
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
master_function("1D", 0)
master_function("240", 1)
master_function("60", 2)
master_function("15", 3)
master_function("5", 4)
master_function("1", 5)```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rumpypumpydumpy |