Pine 中的条形图下方或上方不显示绘制的箭头
Plotted arrows aren't displayed below or above bar graph in Pine
我有下一个代码。
//@version=4
study(title="MACD", shorttitle="MACD")
// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=11)
slow_length = input(title="Slow Length", type=input.integer, defval=22)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)
// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
// Calculating
fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
plot(macd, title="MACD", color=col_macd, transp=0)
plot(signal, title="Signal", color=col_signal, transp=0)
currMacd = hist[0]
prevMacd = hist[1]
buy = currMacd > 0 and prevMacd <= 0
sell = currMacd < 0 and prevMacd >= 0
timetobuy = buy==1
timetosell = sell==1
tup = barssince(timetobuy[1])
tdn = barssince(timetosell[1])
long = tup>tdn?1:na
short = tdn>tup?1:na
plotshape(long==1?buy:na, color=#26A69A, location=location.abovebar, style=shape.arrowup, title="Buy Arrow", transp=0)
plotshape(short==1?sell:na, color=#EF5350, location=location.belowbar, style=shape.arrowdown, title="Sell Arrow", transp=0)
如您所见,它是 macd 直方图代码和一些绘图代码,用于在直方图附近绘制箭头。我将它们的位置配置为上面和下面。但是,它们显示得离图表很远。
如何绘制 macdh 柱上方和下方的箭头?
通过使用 location=location.abovebar
,该函数会影响交易品种的价格水平,这会破坏指标的比例。解决方案是使用 location=location.top
代替:
plotshape(long==1?buy:na, color=#26A69A, location=location.top, style=shape.arrowup, title="Buy Arrow", transp=0)
plotshape(short==1?sell:na, color=#EF5350, location=location.bottom, style=shape.arrowdown, title="Sell Arrow", transp=0)
我有下一个代码。
//@version=4
study(title="MACD", shorttitle="MACD")
// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=11)
slow_length = input(title="Slow Length", type=input.integer, defval=22)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)
// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
// Calculating
fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
plot(macd, title="MACD", color=col_macd, transp=0)
plot(signal, title="Signal", color=col_signal, transp=0)
currMacd = hist[0]
prevMacd = hist[1]
buy = currMacd > 0 and prevMacd <= 0
sell = currMacd < 0 and prevMacd >= 0
timetobuy = buy==1
timetosell = sell==1
tup = barssince(timetobuy[1])
tdn = barssince(timetosell[1])
long = tup>tdn?1:na
short = tdn>tup?1:na
plotshape(long==1?buy:na, color=#26A69A, location=location.abovebar, style=shape.arrowup, title="Buy Arrow", transp=0)
plotshape(short==1?sell:na, color=#EF5350, location=location.belowbar, style=shape.arrowdown, title="Sell Arrow", transp=0)
如您所见,它是 macd 直方图代码和一些绘图代码,用于在直方图附近绘制箭头。我将它们的位置配置为上面和下面。但是,它们显示得离图表很远。
如何绘制 macdh 柱上方和下方的箭头?
通过使用 location=location.abovebar
,该函数会影响交易品种的价格水平,这会破坏指标的比例。解决方案是使用 location=location.top
代替:
plotshape(long==1?buy:na, color=#26A69A, location=location.top, style=shape.arrowup, title="Buy Arrow", transp=0)
plotshape(short==1?sell:na, color=#EF5350, location=location.bottom, style=shape.arrowdown, title="Sell Arrow", transp=0)