请求协助:在MFI与RSI数值旁添加涨跌箭头标识
解决Pine Script中给MFI/RSI数值添加涨跌箭头的问题
你已经正确计算了MFI和RSI的涨跌状态,但需要把这些状态对应的箭头符号和指标文本、数值拼接起来,才能在表格中显示。以下是修改后的完整代码:
//MFI*******RSI********** mif = ta.mfi(close,14) ris1 = ta.rising(mif,14) fal1 = ta.falling(mif,14) //**********RSI********** rsi = ta.rsi(close,14) ris2 = ta.rising(rsi,14) fal2 = ta.falling(rsi,14) // 根据涨跌状态生成箭头符号 mfi_arrow = ris1 ? " ↑" : fal1 ? " ↓" : "" rsi_arrow = ris2 ? " ↑" : fal2 ? " ↓" : "" //Table************ co1 = (mif > 50)? color.rgb(0, 118, 4) : (mif > 20) ? color.rgb(223, 120, 40) : color.rgb(199, 0, 0) Co2 = (rsi >= 60)? color.rgb(0, 118, 4) : (rsi > 35)? color.rgb(223, 120, 40) : color.rgb(199, 0, 0) var table tbl = table.new(position.middle_right,1, 2,border_width = 2,frame_color = color.rgb(7, 7, 7)) if barstate.islastconfirmedhistory // 将箭头拼接到文本末尾 table.cell(table_id = tbl, column = 0, row = 0, text = "MFI " + str.tostring(mif,format.mintick) + mfi_arrow, text_size = size.normal, text_color = color.white, bgcolor = co1) table.cell(table_id = tbl, column = 0, row = 1, text = "RSI " + str.tostring(rsi,format.mintick) + rsi_arrow, text_size = size.normal, text_color = color.white, bgcolor = Co2)
关键修改说明:
- 新增
mfi_arrow和rsi_arrow变量,用三元运算符判断指标的涨跌状态,分别赋值对应的Unicode箭头(上涨↑、下跌↓,无涨跌则为空字符串) - 在表格单元格的文本拼接中,把箭头字符串加到数值后面,实现箭头和数值的关联显示
- 如果你想要更醒目的箭头样式,可以替换成其他Unicode符号,比如
🔼(上涨)、🔽(下跌)
内容的提问来源于stack exchange,提问作者baders
相关产品推荐
相关产品推荐

