英文:
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("ASK - Algo Short", overlay=true)
// Define inputs
length = input(9, "EMA Length")
stochLength = input(14, "Stochastic Length")
stochSmoothK = input(3, "Stochastic %K Smoothing")
// 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 < ta.highest(low[1], 1)) and (low[1] > ema)
isStochAbove80 = stoKSmoothed > 80
// Check for red candle low above 9 EMA
isPreviousCandleRed = close[1] < 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="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)
// Plot the EMA
plot(ema, color=color.blue, title="9 EMA")
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="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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论