微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rising() 没有产生预期的结果

如何解决Rising() 没有产生预期的结果

我在使用 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,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,"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,color.yellow)

解决方法

好的,问题是 if (barstate.islast) 调用。尽管 TradingView 建议使用它来减少计算负载和加速脚本,但如果将它们放入其中,许多函数就会中断。

我们在进入 if 块之前调用 atr(14) 以便它在每个柱上求值。如果我们在 if 块中使用 tostring(atr(14)) ,该函数将无法正确评估,因为它会在数据集的最后一根柱线上被调用,而没有从之前的柱线中计算出必要的值。 Tables - Pine Script

因此,解决方案是将所有对“rising”等的调用放在 if 块之外。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?