OPEN-SOURCE SCRIPT
ALMA HẰNG DIỄM

//version=5
indicator("ALMA Đa khung thời gian", overlay=true)
// Hàm ALMA tùy chỉnh
f_alma(src, len, offset, sigma) =>
m = math.floor(offset * (len - 1))
s = len > 1 ? len - 1 : 1
norm = 0.0
sum = 0.0
for i = 0 to len - 1
w = math.exp(-(math.pow(i - m, 2)) / (2 * math.pow(sigma, 2)))
norm := norm + w
sum := sum + src * w
sum / norm
// Tham số người dùng
alma_len_short = input.int(9, title="Chu kỳ ngắn")
alma_len_long = input.int(50, title="Chu kỳ dài")
alma_offset = input.float(0.85, title="Offset")
alma_sigma = input.float(6.0, title="Sigma")
// ALMA hiện tại (khung đang xem)
alma_short = f_alma(close, alma_len_short, alma_offset, alma_sigma)
alma_long = f_alma(close, alma_len_long, alma_offset, alma_sigma)
// ALMA khung D1
alma_d1_short = request.security(syminfo.tickerid, "D", f_alma(close, alma_len_short, alma_offset, alma_sigma))
alma_d1_long = request.security(syminfo.tickerid, "D", f_alma(close, alma_len_long, alma_offset, alma_sigma))
// ALMA khung W1
alma_w1_short = request.security(syminfo.tickerid, "W", f_alma(close, alma_len_short, alma_offset, alma_sigma))
alma_w1_long = request.security(syminfo.tickerid, "W", f_alma(close, alma_len_long, alma_offset, alma_sigma))
// Vẽ biểu đồ
plot(alma_short, color=color.orange, title="ALMA Ngắn (Hiện tại)")
plot(alma_long, color=color.blue, title="ALMA Dài (Hiện tại)")
plot(alma_d1_short, color=color.green, title="ALMA Ngắn (D1)", linewidth=1)
plot(alma_d1_long, color=color.red, title="ALMA Dài (D1)", linewidth=1)
plot(alma_w1_short, color=color.purple, title="ALMA Ngắn (W1)", linewidth=1)
plot(alma_w1_long, color=color.gray, title="ALMA Dài (W1)", linewidth=1)
// Chênh lệch ALMA hiện tại
plot(alma_short - alma_long, title="Chênh lệch ALMA", color=color.fuchsia, style=plot.style_columns)
indicator("ALMA Đa khung thời gian", overlay=true)
// Hàm ALMA tùy chỉnh
f_alma(src, len, offset, sigma) =>
m = math.floor(offset * (len - 1))
s = len > 1 ? len - 1 : 1
norm = 0.0
sum = 0.0
for i = 0 to len - 1
w = math.exp(-(math.pow(i - m, 2)) / (2 * math.pow(sigma, 2)))
norm := norm + w
sum := sum + src * w
sum / norm
// Tham số người dùng
alma_len_short = input.int(9, title="Chu kỳ ngắn")
alma_len_long = input.int(50, title="Chu kỳ dài")
alma_offset = input.float(0.85, title="Offset")
alma_sigma = input.float(6.0, title="Sigma")
// ALMA hiện tại (khung đang xem)
alma_short = f_alma(close, alma_len_short, alma_offset, alma_sigma)
alma_long = f_alma(close, alma_len_long, alma_offset, alma_sigma)
// ALMA khung D1
alma_d1_short = request.security(syminfo.tickerid, "D", f_alma(close, alma_len_short, alma_offset, alma_sigma))
alma_d1_long = request.security(syminfo.tickerid, "D", f_alma(close, alma_len_long, alma_offset, alma_sigma))
// ALMA khung W1
alma_w1_short = request.security(syminfo.tickerid, "W", f_alma(close, alma_len_short, alma_offset, alma_sigma))
alma_w1_long = request.security(syminfo.tickerid, "W", f_alma(close, alma_len_long, alma_offset, alma_sigma))
// Vẽ biểu đồ
plot(alma_short, color=color.orange, title="ALMA Ngắn (Hiện tại)")
plot(alma_long, color=color.blue, title="ALMA Dài (Hiện tại)")
plot(alma_d1_short, color=color.green, title="ALMA Ngắn (D1)", linewidth=1)
plot(alma_d1_long, color=color.red, title="ALMA Dài (D1)", linewidth=1)
plot(alma_w1_short, color=color.purple, title="ALMA Ngắn (W1)", linewidth=1)
plot(alma_w1_long, color=color.gray, title="ALMA Dài (W1)", linewidth=1)
// Chênh lệch ALMA hiện tại
plot(alma_short - alma_long, title="Chênh lệch ALMA", color=color.fuchsia, style=plot.style_columns)
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.