예스스탁
예스스탁 답변
2025-06-25 14:53:44
안녕하세요
예스스탁입니다
함수는 별도로 사용자함수로 만드셔야 합니다.
1 사용자함수
함수명 : HullMA
반환값형 : 숫자형
input : price(Numeric),length(Numeric);
Vars: wma1(0), wma2(0), diff(0), sqrtLen(0), result(0);
wma1 = WMA(price, length / 2);
wma2 = WMA(price, length);
diff = 2 * wma1 - wma2;
sqrtLen = MaxList(1, SquareRoot(length));
result = WMA(diff, sqrtLen);
HullMA = result;
2
plot3은 기본차트와 Y축이 다른 지표이므로 별도로 만드셔야 합니다.
Inputs:
max_length(50),
accel_multiplier(5.0),
tbl_(true),
lookback_period(100),
candle(true),
collen(100),
up_col(RGB(0,255,0)),
dn_col(RGB(255,0,0)),
up_hist_col(RGB(130,255,195)),
up_hist_col_(RGB(0,255,0)),
dn_hist_col(RGB(255,0,0)),
dn_hist_col_(RGB(247,140,140)),
start_date(20200101),
timer("From start");
Vars:
counts_diff(0), max_abs_counts_diff(0), counts_diff_norm(0), dyn_length(0), dyn_ema(0),
trend(0), bullsrc(0), bearsrc(0), x1(-1), y1(0), posx(0), speed(0), cx(0), ox(0), start_time(0),
prev_counts_diff(0), delta_counts_diff(0), max_delta_counts_diff(0), accel_factor(0),
isStartTime(false), isFromStart(false), barIdx(0), bearish_change(0), bearish_t(0),
bullish_change(0), bullish_t(0), trendspeed(0),
colour(0), fillColor(0), min_speed(0), max_speed(0), normalized_speed(0), speedGradient1(0),
rma0(0), rma1(0), i(0);
// 1. 동적 길이 및 가속도 계산
counts_diff = Close;
max_abs_counts_diff = Highest(AbsValue(counts_diff), 200);
If max_abs_counts_diff <> 0 Then
counts_diff_norm = (counts_diff + max_abs_counts_diff) / (2 * max_abs_counts_diff);
Else
counts_diff_norm = 0;
dyn_length = 5 + counts_diff_norm * (max_length - 5);
prev_counts_diff = counts_diff[1];
delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
max_delta_counts_diff = Highest(delta_counts_diff, 200);
If max_delta_counts_diff = 0 Then
max_delta_counts_diff = 1;
accel_factor = delta_counts_diff / max_delta_counts_diff;
// 2. 동적 EMA (간단화: EMA 사용)
cx = EMA(Close, 10);
ox = EMA(Open, 10);
// 3. 트렌드, 시그널 소스
trend = cx; // 실제 dyn_ema를 구현하려면 별도 로직 필요
bullsrc = Close;
bearsrc = Close;
// 4. 시간 조건
start_time = DateToJulian(start_date);
isStartTime = (DateToJulian(Date) > start_time);
isFromStart = (timer == "From start");
// 5. 첫 값 할당
If (x1 = -1) and (isStartTime or isFromStart) Then
Begin
x1 = CurrentBar;
y1 = ox;
End;
barIdx = CurrentBar;
// 6. 트렌드 방향 및 스피드 계산
If (isStartTime or isFromStart) Then
Begin
If (bullsrc > trend) and (bullsrc[1] <= trend) Then
Begin
bearish_change = Lowest(speed, barIdx - x1);
bearish_t = barIdx - x1;
x1 = barIdx;
y1 = bullsrc;
posx = 1;
speed = cx - ox;
End;
If (bearsrc < trend) and (bearsrc[1] >= trend) Then
Begin
bullish_change = Highest(speed, barIdx - x1);
bullish_t = barIdx - x1;
x1 = barIdx;
y1 = bearsrc;
posx = -1;
speed = cx - ox;
End;
End;
speed = speed + cx - ox;
// 7. 트렌드 스피드 (HullMA)
trendspeed = HullMA(speed, 5);
// 8. 색상 결정
If WMa(Close, 2) > trend Then
colour = up_col;
Else
colour = dn_col;
// 9. 동적 트렌드 플롯
Plot1(trend, "Dynamic Trend", colour);
// 10. 보조 플롯 (숨김)
Plot2(Ema((High + Low) / 2, 50), "RMA HL2");
// 11. 속도 정규화 및 그라데이션
min_speed = Lowest(speed, collen);
max_speed = Highest(speed, collen);
If (max_speed - min_speed) <> 0 Then
normalized_speed = (speed - min_speed) / (max_speed - min_speed);
Else
normalized_speed = 0;
If speed < 0 Then
speedGradient1 = dn_hist_col;
Else
speedGradient1 = up_hist_col;
// 12. 트렌드 스피드 플롯
#If (isStartTime or isFromStart) Then
# Plot3(trendspeed, "Trend Speed", speedGradient1);
// 13. 캔들 색상 적용 (PaintBar 사용)
#If candle Then
# PaintBar(Open, High, Low, Close, speedGradient1);
// 14. (테이블, 통계 등은 Print로 대체 가능)
즐거운 하루되세요
> 허밍스타 님이 쓴 글입니다.
> 제목 : 수식 부탁드립니다.
> Function HullMA(price, length)
Vars: wma1(0), wma2(0), diff(0), sqrtLen(0), result(0);
wma1 = WAverage(price, length / 2);
wma2 = WAverage(price, length);
diff = 2 * wma1 - wma2;
sqrtLen = MaxList(1, SquareRoot(length));
result = WAverage(diff, sqrtLen);
HullMA = result;
End;
Inputs:
max_length(50),
accel_multiplier(5.0),
tbl_(true),
lookback_period(100),
candle(true),
collen(100),
up_col(RGB(0,255,0)),
dn_col(RGB(255,0,0)),
up_hist_col(RGB(130,255,195)),
up_hist_col_(RGB(0,255,0)),
dn_hist_col(RGB(255,0,0)),
dn_hist_col_(RGB(247,140,140)),
start_date(20200101),
timer("From start");
Vars:
counts_diff(0), max_abs_counts_diff(0), counts_diff_norm(0), dyn_length(0), dyn_ema(0),
trend(0), bullsrc(0), bearsrc(0), x1(-1), y1(0), posx(0), speed(0), cx(0), ox(0), start_time(0),
prev_counts_diff(0), delta_counts_diff(0), max_delta_counts_diff(0), accel_factor(0),
isStartTime(false), isFromStart(false), barIdx(0), bearish_change(0), bearish_t(0),
bullish_change(0), bullish_t(0), trendspeed(0),
colour(0), fillColor(0), min_speed(0), max_speed(0), normalized_speed(0), speedGradient1(0),
rma0(0), rma1(0), i(0);
// 1. 동적 길이 및 가속도 계산
counts_diff = Close;
max_abs_counts_diff = Highest(AbsValue(counts_diff), 200);
If max_abs_counts_diff <> 0 Then
counts_diff_norm = (counts_diff + max_abs_counts_diff) / (2 * max_abs_counts_diff);
Else
counts_diff_norm = 0;
dyn_length = 5 + counts_diff_norm * (max_length - 5);
prev_counts_diff = counts_diff[1];
delta_counts_diff = AbsValue(counts_diff - prev_counts_diff);
max_delta_counts_diff = Highest(delta_counts_diff, 200);
If max_delta_counts_diff = 0 Then
max_delta_counts_diff = 1;
accel_factor = delta_counts_diff / max_delta_counts_diff;
// 2. 동적 EMA (간단화: EMA 사용)
cx = EMA(Close, 10);
ox = EMA(Open, 10);
// 3. 트렌드, 시그널 소스
trend = cx; // 실제 dyn_ema를 구현하려면 별도 로직 필요
bullsrc = Close;
bearsrc = Close;
// 4. 시간 조건
start_time = DateToJulian(start_date);
isStartTime = (DateToJulian(Date) > start_time);
isFromStart = (timer = "From start");
// 5. 첫 값 할당
If (x1 = -1) and (isStartTime or isFromStart) Then
Begin
x1 = CurrentBar;
y1 = ox;
End;
barIdx = CurrentBar;
// 6. 트렌드 방향 및 스피드 계산
If (isStartTime or isFromStart) Then
Begin
If (bullsrc > trend) and (bullsrc[1] <= trend) Then
Begin
bearish_change = Lowest(speed, barIdx - x1);
bearish_t = barIdx - x1;
x1 = barIdx;
y1 = bullsrc;
posx = 1;
speed = cx - ox;
End;
If (bearsrc < trend) and (bearsrc[1] >= trend) Then
Begin
bullish_change = Highest(speed, barIdx - x1);
bullish_t = barIdx - x1;
x1 = barIdx;
y1 = bearsrc;
posx = -1;
speed = cx - ox;
End;
End;
speed = speed + cx - ox;
// 7. 트렌드 스피드 (HullMA)
trendspeed = HullMA(speed, 5);
// 8. 색상 결정
If WAverage(Close, 2) > trend Then
colour = up_col
Else
colour = dn_col;
// 9. 동적 트렌드 플롯
Plot1(trend, "Dynamic Trend", colour);
// 10. 보조 플롯 (숨김)
Plot2(XAverage((High + Low) / 2, 50), "RMA HL2");
// 11. 속도 정규화 및 그라데이션
min_speed = Lowest(speed, collen);
max_speed = Highest(speed, collen);
If (max_speed - min_speed) <> 0 Then
normalized_speed = (speed - min_speed) / (max_speed - min_speed)
Else
normalized_speed = 0;
If speed < 0 Then
speedGradient1 = dn_hist_col
Else
speedGradient1 = up_hist_col;
// 12. 트렌드 스피드 플롯
If (isStartTime or isFromStart) Then
Plot3(trendspeed, "Trend Speed", speedGradient1);
// 13. 캔들 색상 적용 (PaintBar 사용)
If candle Then
PaintBar(Open, High, Low, Close, speedGradient1);
// 14. (테이블, 통계 등은 Print로 대체 가능)
====================================================================
ai 이용해서 코드를 작성해보고 있는데
이 코드 실제 작동여부를 떠나서
첫줄에 함수명 문법에러가 나는데... 이유를 모르겠습니다. ㅠ