답변완료
부탁드립니다.
아래 지표에서 supertrend3 상향돌파시 분홍색으로 반대는 파랑색으로 강세약세 지표 부탁드립니다.
input : period1(10),multiplier1(3);
input : period2(20),multiplier2(2);
input : period3(30),multiplier3(3);
var : src(0);
var : AtrV1(0),upperBand1(0),lowerBand1(0), prevLowerBand1(0), prevUpperBand1(0);
var : prevSuperTrend1(0), superTrend1(C), direction1(0),alpha1(0),source1(0);
var : AtrV2(0),upperBand2(0),lowerBand2(0), prevLowerBand2(0), prevUpperBand2(0);
var : prevSuperTrend2(0), superTrend2(C), direction2(0),alpha2(0),source2(0);
var : AtrV3(0),upperBand3(0),lowerBand3(0), prevLowerBand3(0), prevUpperBand3(0);
var : prevSuperTrend3(0), superTrend3(C), direction3(0),alpha3(0),source3(0);
src = (H+L)/2;
if CurrentBar > 1 Then
{
alpha1 = 1 / period1;
source1 = max(high - low, abs(high - close[1]), abs(low - close[1]));
ATrV1 = alpha1 * source1 + (1 - alpha1) * ATrV1[1]; //지수가중이평방식
//ATrV = ma(source,AtrPeriod); //단순이평방식
upperBand1 = src + multiplier1 * AtrV1;
lowerBand1 = src - multiplier1 * AtrV1;
prevLowerBand1 = lowerBand1[1];
prevUpperBand1 = upperBand1[1];
if lowerBand1 > prevLowerBand1 or close[1] < prevLowerBand1 Then
lowerBand1 = lowerBand1;
Else
lowerBand1 = prevLowerBand1;
if upperBand1 < prevUpperBand1 or close[1] > prevUpperBand1 Then
upperBand1 = upperBand1;
Else
upperBand1 = prevUpperBand1;
if C > UpperBand1 Then
direction1 = 1;
if C < LowerBand1 Then
direction1 = -1;
if direction1 == 1 Then
supertrend1 = lowerband1;
Else
supertrend1 = upperband1;
alpha2 = 1 / period2;
source2 = max(high - low, abs(high - close[1]), abs(low - close[1]));
ATrV2 = alpha2 * source2 + (1 - alpha2) * ATrV2[1]; //지수가중이평방식
//ATrV = ma(source,AtrPeriod); //단순이평방식
upperBand2 = src + multiplier2 * AtrV2;
lowerBand2 = src - multiplier2 * AtrV2;
prevLowerBand2 = lowerBand2[1];
prevUpperBand2 = upperBand2[1];
if lowerBand2 > prevLowerBand2 or close[1] < prevLowerBand2 Then
lowerBand2 = lowerBand2;
Else
lowerBand2 = prevLowerBand2;
if upperBand2 < prevUpperBand2 or close[1] > prevUpperBand2 Then
upperBand2 = upperBand2;
Else
upperBand2 = prevUpperBand2;
if C > UpperBand2 Then
direction2 = 1;
if C < LowerBand2 Then
direction2 = -1;
if direction2 == 1 Then
supertrend2 = lowerband2;
Else
supertrend2 = upperband2;
alpha3 = 1 / period3;
source3 = max(high - low, abs(high - close[1]), abs(low - close[1]));
ATrV3 = alpha3 * source3 + (1 - alpha3) * ATrV3[1]; //지수가중이평방식
//ATrV = ma(source,AtrPeriod); //단순이평방식
upperBand3 = src + multiplier3 * AtrV3;
lowerBand3 = src - multiplier3 * AtrV3;
prevLowerBand3 = lowerBand3[1];
prevUpperBand3 = upperBand3[1];
if lowerBand3 > prevLowerBand3 or close[1] < prevLowerBand3 Then
lowerBand3 = lowerBand3;
Else
lowerBand3 = prevLowerBand3;
if upperBand3 < prevUpperBand3 or close[1] > prevUpperBand3 Then
upperBand3 = upperBand3;
Else
upperBand3 = prevUpperBand3;
if C > UpperBand3 Then
direction3 = 1;
if C < LowerBand3 Then
direction3 = -1;
if direction3 == 1 Then
supertrend3 = lowerband3;
Else
supertrend3 = upperband3;
if C > superTrend1 Then
{
Plot1(superTrend1,"매수1", rgb(247, 75, 201), 0, 1);
NoPlot(2);
}
Else
{
Plot2(superTrend1,"매도1", Indigo, 0, 1);
NoPlot(1);
}
if C > superTrend2 Then
{
Plot3(superTrend2,"매수2", rgb(247, 75, 201), 0, 2);
NoPlot(4);
}
Else
{
Plot4(superTrend2,"매도2", Indigo, 0, 2);
NoPlot(3);
}
if C > superTrend3 Then
{
Plot5(superTrend3,"매수3", rgb(247, 75, 201), 0, 7);
NoPlot(6);
}
Else
{
Plot6(superTrend3,"매도3", Indigo, 0, 7);
NoPlot(5);
}
}
.
2025-06-25
187
글번호 192058
지표
답변완료
수식 부탁드립니다.
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 이용해서 코드를 작성해보고 있는데
이 코드 실제 작동여부를 떠나서
첫줄에 함수명 문법에러가 나는데... 이유를 모르겠습니다. ㅠ
2025-06-25
240
글번호 192055
지표