【问题标题】:Trying to plot shape when value of the indicator ema first increases or decreases当指标 ema 的值首先增加或减少时尝试绘制形状
【发布时间】:2022-11-25 14:48:15
【问题描述】:

我是松树的新手,对此遇到了麻烦。它可能是语法或不正确的计算。代码如下:

buySignal = input.bool(true,title='Buy Signal')
sellSignal = input.bool(true,title='Sell Signal')

plotshape(buySignal ? lenema > lenema[1] and lenema[1] < lenema[2]: na,title='Buy Shape', style=shape.triangleup,color=color.green, location=location.belowbar,size=size.large)

plotshape(sellSignal ? lenema < lenema[1] and lenema[1] > lenema[2]: na,title='Sell Shape',style=shape.triangledown,color=color.red, location=location.abovebar,size=size.large)


当指标 ema 的值首先增加或减少时尝试绘制形状

以前的代码是:

// RSI code
rsi = ta.rsi(close, len)
plot(rsi, color=color.new(color.white, 0), linewidth=3)
plot(rsi)


lenema = input.int(200, minval=1, title='RSI EMA Length')
out = ta.ema(rsi, lenema)
col = out >= out[1] ? color.lime : color.red
plot(out, title='RSI EMA', color=col, linewidth=2)

【问题讨论】:

  • 我忘了澄清代码正在编译,但没有显示三角形。

标签: pine-script


【解决方案1】:

看起来您正在比较lengthlenemainput.int 并且它将保持不变,这就是为什么您的比较不起作用的原因。

你可能想要:

plotshape(buySignal ? (out > out[1] and out[1] < out[2]) : na,title='Buy Shape', style=shape.triangleup,color=color.green, location=location.belowbar,size=size.large)

plotshape(sellSignal ? (out < out[1] and out[1] > out[2]) : na,title='Sell Shape',style=shape.triangledown,color=color.red, location=location.abovebar,size=size.large)

在 RSI 线上打印三角形:

plotshape((buySignal and (out > out[1] and out[1] < out[2])) ? rsi : na,title='Buy Shape', style=shape.triangleup,color=color.green, location=location.absolute,size=size.large)

plotshape((sellSignal and (out < out[1] and out[1] > out[2])) ? rsi : na,title='Sell Shape',style=shape.triangledown,color=color.red, location=location.abovebar,size=size.large)

【讨论】:

  • 我还将栏上方和栏下方的位置切换到顶部和底部,因为上方栏和下方栏将它们打印在我的图表上方。三角形以价格而不是 RSI ema 的值打印。我很高兴它现在可以工作了。
  • 您可以设置location=location.absolute并使用rsi作为您的价格水平。这样三角形将打印在 RSI 线上。请看我的编辑。我还没有测试过,但它应该可以工作。
  • 谢谢。我弄错的逻辑还有更多。当我这样做时,箭头不断地打印在图表底部的每个条上。可能是因为代码覆盖在已经创建的脚本上。我将尝试将其单独放置并查看其进展情况。
  • 也使用 location.above 或 below bar 导致三角形打印高于线
  • 这是我的指标标题。是否缺少某些输入?
【解决方案2】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-30
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多