OPEN-SOURCE SCRIPT

HADC Indicator with Buy/Hold/Sell - AK

//version=5
indicator("HADC Indicator with Buy/Hold/Sell", overlay=true)

// Heikin Ashi Candle Calculation
ha_close = (open + high + low + close) / 4
var float ha_open = na
ha_open := na(ha_open[1]) ? (open + close) / 2 : (ha_open[1] + ha_close[1]) / 2
ha_high = math.max(high, math.max(ha_close, ha_open))
ha_low = math.min(low, math.min(ha_close, ha_open))

// Trend Direction
ha_trend = ha_close > ha_open ? 1 : -1
trend_change = ha_trend != ha_trend[1]

// Buy, Sell, and Hold Signals
buy_signal = trend_change and ha_trend == 1
sell_signal = trend_change and ha_trend == -1
hold_signal = not trend_change // HOLD when there's no trend change

// Label Positioning
label_position_buy = low - ta.atr(14) * 0.5
label_position_sell = high + ta.atr(14) * 0.5
label_position_hold = (high + low) / 2 // HOLD appears in the middle

// Plot Labels
if buy_signal
label.new(x=bar_index, y=label_position_buy, text="BUY", color=color.rgb(76, 175, 79, 100), textcolor=color.white, size=size.small, style=label.style_label_down)

if sell_signal
label.new(x=bar_index, y=label_position_sell, text="SELL", color=color.rgb(255, 82, 82, 100), textcolor=color.white, size=size.small, style=label.style_label_up)

if hold_signal
label.new(x=bar_index, y=label_position_hold, text="HOLD", color=color.rgb(6, 6, 6, 100), textcolor=color.white, size=size.small, style=label.style_label_up)

// Plot Heikin Ashi Candles
plotcandle(ha_open, ha_high, ha_low, ha_close, title="Heikin Ashi", color=ha_trend == 1 ? color.green : color.red)

Pernyataan Penyangkalan