커뮤니티

수식 부탁합니다.

프로필 이미지
newstory
2025-12-19 22:48:47
89
글번호 229224
답변완료

안녕하세요.


아래 지표 변환부탁 합니다.



//@version=5

indicator("Transient Zones v1.1 [v5 Upgrade]", "TZ v5", overlay=true)

// --- Inputs ---

h_left = input.int(10, title="H left")

h_right = input.int(10, title="H right")

sample_period = input.int(5000, title="Sample bars for % TZ")

show_ptz = input.bool(true, title="Show PTZ")

show_channel = input.bool(true, title="Show channel")

// --- PTZ (Potential Transient Zones) Logic ---

// 현재 바가 왼쪽 h_left 기간 동안의 최고/최저인지 확인

h_left_low = ta.lowest(low, h_left)

h_left_high = ta.highest(high, h_left)

newlow = low <= h_left_low[1]

newhigh = high >= h_left_high[1]

// PTZ 시각화 (실시간으로 나타났다 사라질 수 있음)

plotshape(newlow and show_ptz, style=shape.triangledown, location=location.belowbar, color=color.red, title="PTZ Low")

plotshape(newhigh and show_ptz, style=shape.triangleup, location=location.abovebar, color=color.green, title="PTZ High")

// 채널 그리기

plot(show_channel ? h_left_low : na, color=color.new(color.silver, 50), title="Channel Low")

plot(show_channel ? h_left_high : na, color=color.new(color.silver, 50), title="Channel High")

// --- True TZ (Transient Zones) Logic ---

// 과거 h_right만큼 시간이 지난 뒤, 해당 지점이 실제로 고점/저점이었는지 확인

central_bar_low = low[h_right]

central_bar_high = high[h_right]

full_zone_low = ta.lowest(low, h_left + h_right + 1)

full_zone_high = ta.highest(high, h_left + h_right + 1)

central_bar_is_highest = central_bar_high >= full_zone_high

central_bar_is_lowest = central_bar_low <= full_zone_low

// True TZ 시각화 (h_right만큼 뒤로 밀어서 표시)

plotarrow(central_bar_is_highest ? -1 : 0, offset=-h_right, colorup=color.green, colordown=color.red, title="Confirmed TZ")

plotarrow(central_bar_is_lowest ? 1 : 0, offset=-h_right, colorup=color.green, colordown=color.red, title="Confirmed TZ")

// --- Probability Calculations ---

// TZ 카운트

high_bar_tz_count = ta.cum(central_bar_is_highest ? 1 : 0)

low_bar_tz_count = ta.cum(central_bar_is_lowest ? 1 : 0)

total_tz = high_bar_tz_count + low_bar_tz_count

// PTZ 카운트

high_bar_ptz_count = ta.cum(newhigh ? 1 : 0)

low_bar_ptz_count = ta.cum(newlow ? 1 : 0)

total_ptz = high_bar_ptz_count + low_bar_ptz_count

// 통계 데이터 계산 (차트 하단 데이터 창에서 확인 가능)

percent_total_tz = (total_tz / sample_period) * 100

percent_total_ptz = (total_ptz / sample_period) * 100

percent_ptz_resolved = (1 - (total_tz / (total_ptz > 0 ? total_ptz : 1))) * 100

// 데이터 출력을 위한 투명 플롯 (Data Window 전용)

plot(percent_total_tz, color=color.new(color.black, 100), title="Total TZ %", display=display.data_window)

plot(percent_total_ptz, color=color.new(color.navy, 100), title="Total PTZ %", display=display.data_window)

plot(percent_ptz_resolved, color=color.new(color.gray, 100), title="PTZ Resolved %", display=display.data_window)

지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-12-22 11:09:23

안녕하세요 예스스탁입니다. input : h_left(10),h_right(10),sample_period(5000),show_ptz(true),show_channel(true); var : h_left_low(0),h_left_high(0),newhigh(False),newlow(False),tx(0); h_left_low = lowest(low, h_left); h_left_high = highest(high, h_left); newlow = low <= h_left_low[1]; newhigh = high >= h_left_high[1]; if newlow and show_ptz Then { tx = Text_New(sDate,sTime,L,"▼"); Text_SetStyle(tx,2,0); Text_SetColor(tx,Red); } if newhigh and show_ptz Then { tx = Text_New(sDate,sTime,H,"▲"); Text_SetStyle(tx,2,1); Text_SetColor(tx,Green); } if show_channel == true Then { plot1(h_left_low,"Channel Low",Silver); plot2(h_left_high,"Channel High",Silver); } Else { NoPlot(1); NoPlot(2); } var : central_bar_low(0),central_bar_high(0); var : full_zone_low(0),full_zone_high(0); var : central_bar_is_highest(False),central_bar_is_lowest(False); var : tx1(0); central_bar_low = low[h_right]; central_bar_high = high[h_right]; full_zone_low = lowest(low, h_left + h_right + 1); full_zone_high = highest(high, h_left + h_right + 1); central_bar_is_highest = central_bar_high >= full_zone_high; central_bar_is_lowest = central_bar_low <= full_zone_low; if central_bar_is_highest == true Then { tx1 = Text_New(sDate[h_right],sTime[h_right],H[h_right],"▼"); Text_SetStyle(tx1,2,1); Text_SetColor(tx1,Magenta); } if central_bar_is_lowest == true Then { tx1 = Text_New(sDate[h_right],sTime[h_right],L[h_right],"▲"); Text_SetStyle(tx1,2,0); Text_SetColor(tx1,Lime); } var : high_bar_tz_count(0),low_bar_tz_count(0),total_tz(0); var : high_bar_ptz_count(0),low_bar_ptz_count(0),total_ptz(0); var : percent_total_tz(0),percent_total_ptz(0),percent_ptz_resolved(0); high_bar_tz_count = Accum(iff(central_bar_is_highest , 1 , 0)); low_bar_tz_count = Accum(iff(central_bar_is_lowest , 1 , 0)); total_tz = high_bar_tz_count + low_bar_tz_count; high_bar_ptz_count = Accum(iff(newhigh , 1 , 0)); low_bar_ptz_count = Accum(iff(newlow , 1 , 0)); total_ptz = high_bar_ptz_count + low_bar_ptz_count; percent_total_tz = (total_tz / sample_period) * 100; percent_total_ptz = (total_ptz / sample_period) * 100; percent_ptz_resolved = (1 - (total_tz / IFf(total_ptz > 0 , total_ptz , 1))) * 100; #plot3(percent_total_tz,"Total TZ %",Black); #plot4(percent_total_ptz,"Total PTZ %",Navy); #plot5(percent_ptz_resolved,"PTZ Resolved %",Gray); 즐거운 하루되세요