本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator('DFS-HAMA', overlay = true)
src = input(close, title = 'Source')
//haLength = input(30, title='Heikin Ashi Length')
smaLength = input(30, title = 'SMA Length') // Add this input for SMA length
haClose = (open + high + low + close) / 4
var float haOpen = na
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))
//ma = ta.sma(src, smaLength) // Use the user-defined SMA length
avg = math.avg(haOpen, haHigh, haLow, haClose)
HA_MA30 = ta.wma(avg, smaLength)
// Determine the current Heikin Ashi bar color
var color currentHAColor = na
currentHAColor := haClose > haOpen ? color.green : color.red
plot(HA_MA30, title = 'Moving Average', color = currentHAColor, linewidth = 1, offset = 0)