求助:如何在Pine Script中实现MACD高点突破时绘制plotshape?
需求:MACD金叉后突破跟踪高点时用plotshape绘制标记
我已经通过代码实现了跟踪MACD金叉后的价格高点,但不清楚如何存储之前的高点,以便判断K线何时突破该高点,希望有人协助实现:当这个高点被突破时,使用plotshape绘制标记。
以下是我的代码:
//@version=5 indicator("break high", overlay = true) // === MACD === fastMA = input.int(title="Fast moving average", defval = 12, minval = 7) slowMA = input.int(title="Slow moving average", defval = 26, minval = 7) signalLength = input.int(9, minval=1) MacdControl = input(true, title="MACD/Histogram Control") [currMacd,,] = ta.macd(close[0], fastMA, slowMA, signalLength) [prevMacd,,] = ta.macd(close[1], fastMA, slowMA, signalLength) signal = ta.ema(currMacd, signalLength) [macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9) //Zero Line crossoverbull = ta.crossover(macdLine, signalLine) crossoverbear = ta.crossover(signalLine, macdLine) var can_find = false condstart = crossoverbull condstop = crossoverbear can_find := condstop ? false : condstart ? true : can_find var float highesthigh = na highesthigh := if (condstart) high else if (can_find) if (high > highesthigh) high else highesthigh else na plot(highesthigh, color=color.blue, style=plot.style_linebr)
参考示意图:显示MACD金叉后跟踪价格高点,突破该高点时添加标记的效果
内容的提问来源于stack exchange,提问作者Bob Cot
相关产品推荐
相关产品推荐

