【发布时间】:2021-06-19 20:28:55
【问题描述】:
我在使用 Pine Script/TradingView 中的rising() 函数时遇到问题。下面是代码。我希望在图表下方有一个表格,其中包含一些基于信号是看跌还是看涨的关键指标颜色代码,以及指示最近变化方向的箭头。
当我覆盖这个测试脚本时,正如预期的那样,fastTema 在上升时以绿色绘制,在下降时绘制为红色。但是,在汇总表中,即使上面以绿色绘制,它也显示为红色并带有下降箭头。似乎rising(fastTema,1) 在 plot() 调用中返回“真”结果,而在表格中返回错误结果。
我在这里错过了什么?
//@version=4
study("Test", overlay=true)
// TEMA Calculation with alerts (Based on TEMA With Alert by BerkSay)
fTEMA(temaSource, temaLength) =>
Tema1 = ema(temaSource, temaLength)
Tema2 = ema(Tema1, temaLength)
Tema3 = ema(Tema2, temaLength)
3 * Tema1 - 3 * Tema2 + Tema3
showTEMA = input(true, "Show TEMA?")
temaFastLength = input(title="TEMA Fast length", defval=13, minval=1)
temaSlowLength = input(title="TEMA Slow length", defval=34, minval=1)
temaSource = input(title="TEMA Source", defval=close, type=input.source)
temaSlow = fTEMA(temaSource, temaSlowLength)
temaFast = fTEMA(temaSource, temaFastLength)
colortemaSlow = #ff0000
colortemaFast = #00ff00
plottemaSlow = plot(showTEMA ? temaSlow: na, color=color.new(colortemaSlow,20), title="TEMA Slow plot", linewidth=2)
plottemaFast = plot(showTEMA ? temaFast: na, color=rising(temaFast,1) ? color.new(color.green,20) : color.new(color.red,20), title="TEMA Fast plot", linewidth=2)
// Summary Table
// Shows red for bearish signals, green for bullish signals.
tablePosition = input(title="Summary Table Position", defval=position.bottom_left,
options=[position.bottom_left,
position.top_left, position.bottom_right, position.top_right])
var table summaryTable = table.new(tablePosition, 1, 1)
if (barstate.islast)
temaDirection = rising(temaFast,1) ? "↑" : "↓"
table.cell(summaryTable, 0, 0, "TEMA" + temaDirection,text_size=size.tiny, bgcolor = temaFast > temaSlow and rising(temaFast,1) ? color.green : color.red)
// See if temaFast has increased over the last two periods.
if (rising(temaFast,2) and temaFast < temaSlow)
table.cell_set_bgcolor(summaryTable, 0, 0, color.yellow)
【问题讨论】:
-
阅读控制台警告信息
标签: pine-script