Am următorul cod.
//@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)
După cum puteți vedea, este codul histogramei macd cu un cod de grafic pentru a reprezenta grafic săgețile din apropierea histogramei. Am configurat locația lor ca mai sus și mai jos. Cu toate acestea, ele sunt afișate departe de grafic.
Cum pot trasa săgețile deasupra și dedesubtul barelor macdh?