Untitled

 avatar
EBTURK
plain_text
a year ago
1.3 kB
7
Indexable
//@version=5
indicator('MACD Profit Candles', overlay=false, precision=4       ,     timeframe="",   timeframe_gaps=true)

lenFast = input.int(12, title='MACD Fast EMA Length', minval=1)
lenSlow = input.int(29, title='MACD Slow EMA Length', minval=1)
lenSig = input.int(9, title='MACD Signal Length', minval=1)
src = input(close, title='Source')
plotSig = input(false, title='Plot MACD Signal Line?')

getMACD(s, fastLen, slowLen, sigLen) =>
    fast = ta.ema(s, fastLen)
    slow = ta.ema(s, slowLen)
    macd = fast - slow
    sig = ta.ema(macd, sigLen)
    [macd, sig, macd - sig]

[mac, signal, macHist] = getMACD(src, lenFast, lenSlow, lenSig)

candleColor = mac >= mac[1] ? color.lime : color.red
sigColor = signal > signal[1] ? color.lime : color.fuchsia

// Plotting the candles
plotcandle(open=mac[1], close=mac, high=mac, low=mac[1], color=candleColor)

// Plotting the MACD Signal Line
plot(plotSig ? signal : na, title='Signal Line', color=sigColor, style=plot.style_circles, linewidth=2)

// Adding background color when sigColor changes
//bgcolor(candleColor, transp=90)

// Labeling when crossover and crossunder occur
bgcolor(ta.crossunder(mac, signal) ? color.red : na, transp=90)
bgcolor(ta.crossover(mac, signal) ? color.green : na, transp=90)

Editor is loading...
Leave a Comment