예스스탁
예스스탁 답변
2025-07-03 14:22:45
안녕하세요
예스스탁입니다.
input : exponential(1);#1:Ema, 2:sma
input : ma1_length(5),ma2_length(10),ma3_length(20),ma4_length(60);
var : ma1(0),ma2(0),ma3(0),ma4(0);
var : red_top(0),red_bottom(0),blue_top(0),blue_bottom(0);
var : red_range(0),blue_range(0),current_condition(False),prev_condition(False);
var : red_cross_above(false),blue_cross_above(False);
var : is_overlap(False),overlap_start(False),overlap_end(False);
ma1 = iff(exponential , ema(c, ma1_length) , ma(c, ma1_length));
ma2 = iff(exponential , ema(c, ma2_length) , ma(c, ma2_length));
ma3 = iff(exponential , ema(c, ma3_length) , ma(c, ma3_length));
ma4 = iff(exponential , ema(c, ma4_length) , ma(c, ma4_length));
red_top = max(ma1, ma2);
red_bottom = min(ma1, ma2);
blue_top = max(ma3, ma4);
blue_bottom = min(ma3, ma4);
red_range = red_top - red_bottom;
blue_range = blue_top - blue_bottom;
// 교차 조건 계산
current_condition = red_top > blue_top;
prev_condition = red_top[1] > blue_top[1];
// 교차 시점 감지
red_cross_above = current_condition == true and prev_condition == False;
blue_cross_above = current_condition == False and prev_condition == true;
// 겹침 조건 계산
is_overlap = (red_top > blue_bottom) and (red_bottom < blue_top);
overlap_start = is_overlap[1] == False and is_overlap == true;
overlap_end = is_overlap[1] == true and is_overlap == False;
// MA 플롯 정의 (메인 차트에 표시)
plot1(ma1, "MA1", iff(ma1-ma1[1] >= 0 ,lime ,red));
plot2(ma2, "MA2", iff(ma2-ma2[1] >= 0 ,lime ,red));
plot3(ma3, "MA3", iff(ma3-ma3[1] >= 0 ,lime ,red));
plot4(ma4, "MA4", iff(ma4-ma4[1] >= 0 ,lime ,red));
즐거운 하루되세요
> bw 님이 쓴 글입니다.
> 제목 : 변환부탁합니다.
> tradingview 지표 중 일부 수식입니다.
가능한 변환부탁드립니다.
플롯이나 fill 부분은 정확하지 않아도 됩니다.
입력값은 ma1,ma2,ma3,ma4
// 이동평균선 계산
ma1 = exponential ? ema(src, ma1_length) : sma(src, ma1_length)
ma2 = exponential ? ema(src, ma2_length) : sma(src, ma2_length)
ma3 = exponential ? ema(src, ma3_length) : sma(src, ma3_length)
ma4 = exponential ? ema(src, ma4_length) : sma(src, ma4_length)
// 각 영역의 상단/하단값 계산
red_top = max(ma1, ma2)
red_bottom = min(ma1, ma2)
blue_top = max(ma3, ma4)
blue_bottom = min(ma3, ma4)
// 범위 계산
red_range = red_top - red_bottom
blue_range = blue_top - blue_bottom
// 교차 조건 계산
current_condition = red_top > blue_top
prev_condition = red_top[1] > blue_top[1]
// 교차 시점 감지
red_cross_above = current_condition and not prev_condition
blue_cross_above = not current_condition and prev_condition
// 겹침 조건 계산
is_overlap = (red_top > blue_bottom) and (red_bottom < blue_top)
overlap_start = not is_overlap[1] and is_overlap
overlap_end = is_overlap[1] and not is_overlap
// MA 플롯 정의 (메인 차트에 표시)
p1 = plot(ma1, color=show_fill_input ? color.new(color.white, 100) : (change(ma1) >= 0 ? color.lime : color.red),
style=plot.style_line, title="MA1", linewidth=2)
p2 = plot(ma2, color=show_fill_input ? color.new(color.white, 100) : (change(ma2) >= 0 ? color.lime : color.red),
style=plot.style_line, title="MA2", linewidth=2)
p3 = plot(ma3, color=show_fill_input ? color.new(color.white, 100) : (change(ma3) >= 0 ? color.lime : color.red),
style=plot.style_line, title="MA3", linewidth=2)
p4 = plot(ma4, color=show_fill_input ? color.new(color.white, 100) : (change(ma4) >= 0 ? color.lime : color.red),
style=plot.style_line, title="MA4", linewidth=2)
/ === 색상 채우기 ===
fill(p1, p2, color=show_fill_input ? color.new(color.red, 60) : na, title="MA1-MA2 간격")
fill(p3, p4, color=show_fill_input ? color.new(color.blue, 60) : na, title="MA3-MA4 간격")