I modified stochastic indicator to multi-timeframe with ability to plot last 3 stochastic D values as table on top right of the chart but I am getting error of The 'symbol' and 'timeframe' arguments are incompatible with functions that have side effects.
Error message is showing on highlighted line. Can someone help with what is missing?
//MTF coding from ChrisMoody's CM Stochastic MTF indicator
//@version=5
indicator(title="Stochastic MTF Full", shorttitle="Stoch MTF", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
periodK = input.int(14, title="%K Length", minval=1)
smoothK = input.int(1, title="%K Smoothing", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
//MTF Stochastics
periodK2 = input.int(14, minval=1, title="2nd Stoch %K Length")
smoothK2 = input.int(1, minval=1, title="SmoothK for 2nd Stoch")
periodD2 = input.int(3, minval=1, title="SmoothD for 2nd Stoch")
resCustom = input.timeframe(title = "Current chart stochastic", defval = '30')
resCustom2 = input.timeframe(title = "Higher timeframe stochastic", defval = "D")
useCurrentRes = input.bool(true, title="Use Current Chart Resolution?")
useCurrentRes2 = input.bool(false, title="Use 2nd Stoch Plot On Same Timeframe?")
res = useCurrentRes ? timeframe.period : resCustom
res2 = useCurrentRes2 ? timeframe.period : resCustom2
//Primary timeframe stochastics
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
outK = request.security(syminfo.tickerid, resCustom, k)
outD = request.security(syminfo.tickerid, resCustom, d)
//Higher timeframe stochastics
k2 = ta.sma(ta.stoch(close, high, low, periodK2), smoothK2)
d2 = ta.sma(k2, periodD2)
outK2 = request.security(syminfo.tickerid, resCustom2, k2)
outD2 = request.security(syminfo.tickerid, resCustom2, d2)
//code for table on right side for last 3 D values
bgcolor1 = input.color(defval=color.new(color.black,40), title = "Table Col 1",group = "Tables")
bgcolor2 = input.color(defval=color.new(color.blue,40), title = "Table Col 2",group = "Tables")
textcol = input.color(defval=color.rgb(255,255,255), title = "Table Text Col",group = "Tables")
textsize1 = size.small
**var table Dvalue = table.new(position = position.top_right, columns = 5, rows = 3, border_width = 1, border_color = color.aqua, frame_color = color.aqua, frame_width = 1)**
table.cell(table_id = Dvalue, column = 1, row = 1, text = "Last 3 StochD : ", bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
table.cell(table_id = Dvalue, column = 2, row = 1, text = str.tostring(math.round(d,2)), bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
table.cell(table_id = Dvalue, column = 3, row = 1, text = str.tostring(math.round(d[1],2)), bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
table.cell(table_id = Dvalue, column = 4, row = 1, text = str.tostring(math.round(d[2],2)), bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
//Higher TF Stochastic values on table
table.cell(table_id = Dvalue, column = 1, row = 2, text = "HTF prev 3 StochD : ", bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
table.cell(table_id = Dvalue, column = 2, row = 2, text = str.tostring(math.round(outD2,2)), bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
table.cell(table_id = Dvalue, column = 3, row = 2, text = str.tostring(math.round(outD2[1],2)), bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
table.cell(table_id = Dvalue, column = 4, row = 2, text = str.tostring(math.round(outD2[2],2)), bgcolor=bgcolor1, text_color=textcol, text_size = textsize1)
plot(outK, title="%K", color=#2962FF)
plot(outD, title="%D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
I tried to modify the code and checked documentation for indicator table examples and not quite sure if I understood what was missing with my very limited coding experience.