如何在以下指标中去除连续的蜡烛高亮?

huangapple go评论63阅读模式
英文:

How to remove consecutive candle highlight in the following indicator?

问题

我已经在Pine Script中创建了一个指标,如下所示,它将突出显示在9EMA上关闭的蜡烛和stok %k超过80的蜡烛。

//@version=5
indicator("ASK - Algo Short", overlay=true)

// 定义输入
length = input(9, "EMA Length")
stochLength = input(14, "Stochastic Length")
stochSmoothK = input(3, "Stochastic %K Smoothing")

// 计算EMA
ema = ta.ema(close, length)

// 计算上一个蜡烛的Stochastic %K
stoK = ta.stoch(close[1], high[1], low[1], stochLength)
stoKSmoothed = ta.sma(stoK, stochSmoothK)

// 检查是否突破了上一个蜡烛的低点,并且在9 EMA上方
isBreakOfLow = (low < ta.highest(low[1], 1)) and (low[1] > ema)
isStochAbove80 = stoKSmoothed > 80

// 检查上一个蜡烛是否是红色的并且在9 EMA上方
isPreviousCandleRed = close[1] < open[1]

// 检查上一个蜡烛是否被突出显示
prevCandleHighlighted = ta.valuewhen(isBreakOfLow and isStochAbove80, isBreakOfLow and isStochAbove80, 1)

// 如果满足条件,则绘制突出显示
highlightedCandle = isBreakOfLow and isStochAbove80 and not prevCandleHighlighted
plotshape(highlightedCandle, title="Break of Previous Candle Low Above 9 EMA", location=location.abovebar, color=color.rgb(6, 0, 6), style=shape.arrowdown, size=size.tiny, textcolor=color.white, transp=0)

// 绘制EMA
plot(ema, color=color.blue, title="9 EMA")

当我绘制一个向下的箭头时,代码将检查上一个蜡烛是否被向下的箭头突出显示。如果是的话,这个蜡烛就不会绘制一个向下的箭头。

英文:

I have created an indicator in pinescript as following which will highlight a candle that is closed above 9EMA and stok %k above 80.

//@version=5
indicator(&quot;ASK - Algo Short&quot;, overlay=true)

// Define inputs
length = input(9, &quot;EMA Length&quot;)
stochLength = input(14, &quot;Stochastic Length&quot;)
stochSmoothK = input(3, &quot;Stochastic %K Smoothing&quot;)

// Calculate EMA
ema = ta.ema(close, length)

// Calculate Stochastic %K of previous candle
stoK = ta.stoch(close[1], high[1], low[1], stochLength)
stoKSmoothed = ta.sma(stoK, stochSmoothK)

// Check for break of previous candle low above 9 EMA
isBreakOfLow = (low &lt; ta.highest(low[1], 1)) and (low[1] &gt; ema)
isStochAbove80 = stoKSmoothed &gt; 80

// Check for red candle low above 9 EMA
isPreviousCandleRed = close[1] &lt; open[1]

// Check if the previous candle was highlighted
prevCandleHighlighted = ta.valuewhen(isBreakOfLow and isStochAbove80, isBreakOfLow and isStochAbove80, 1)

// Plot a highlight if condition is met
highlightedCandle = isBreakOfLow and isStochAbove80 //and isPreviousCandleRed
plotshape(highlightedCandle, title=&quot;Break of Previous Candle Low Above 9 EMA&quot;, location=location.abovebar, color=color.rgb(6, 0, 6), style=shape.arrowdown, size=size.tiny, textcolor=color.white, transp=0)


// Plot the EMA
plot(ema, color=color.blue, title=&quot;9 EMA&quot;)

The output is as following
enter image description here

When I draw a down arrow, code should check if previous candle is highlighted with down arrow. if yes then this candle should not draw a down arrow.

Can anyone help me please?

I added following code but entire highlight was gone. no candle got highlighted.

// Check if the previous candle was highlighted
prevCandleHighlighted = ta.valuewhen(isBreakOfLow and isStochAbove80, isBreakOfLow and isStochAbove80, 1)

答案1

得分: 0

我更新了你的plotshape,包括not highlightedCandle[1]。这可以防止信号在连续的两根K线上发生。

plotshape(highlightedCandle and not highlightedCandle[1], title="突破前一根K线的低点,位于9 EMA之上", location=location.abovebar, color=color.rgb(6, 0, 6), style=shape.arrowdown, size=size.tiny, textcolor=color.white)
英文:

I updated your plotshape to include not highlightedCandle[1]. This prevents the signal from occurring on back to back bars.

plotshape(highlightedCandle and not highlightedCandle[1], title=&quot;Break of Previous Candle Low Above 9 EMA&quot;, location=location.abovebar, color=color.rgb(6, 0, 6), style=shape.arrowdown, size=size.tiny, textcolor=color.white)

huangapple
  • 本文由 发表于 2023年7月18日 01:17:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定