Trading view Custom Chart Using Pine Script Code



//@version=5
indicator("Custom MACD Chart", shorttitle="MACDLong", overlay=false)

// Get the input data
length = 50
src = close
ema_26 = ta.ema(src, 20)
ema_50 = ta.ema(src, 40)
signal_line3 = ema_26 - ema_50

// Plot the signal line
plot(signal_line3, color=#bb08da, title="Signal Line3", linewidth=2, style=plot.style_line)

// Get the previous value of the signal line
prev_signal_line3 = nz(signal_line3[1])

// Determine the color based on the comparison with the previous value
color_hist = signal_line3 > prev_signal_line3 ? color.new(#00ff00, 50) : color.new(#ff0000, 50)

// Plot the histogram
hist_plot = plot(signal_line3, title="Histogram", style=plot.style_histogram, linewidth=6, color=color_hist)

// Add a zero line for reference
plot_zero = plot(0, title="Zero Line", color=color.new(color.gray, 100))

// Fill the histogram with color based on its value
fill(hist_plot, plot_zero, color=color_hist)