커뮤니티

아래의 트레이디이뷰 수식을 변환부탁드립니다.

프로필 이미지
해암
2025-11-12 04:01:40
152
글번호 227926
답변완료

//@version=6

indicator("Trend Filter (2-pole) [BigBeluga]", overlay = true)



// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

int length = input.int(20, "Length")

float damping = input.float(0.9, "Damping", minval = 0.1, maxval = 1.0, step = 0.01)

int ris_fal = input.int(5, "Rising and Falling")

float bands = input.float(1.0, "Bands", step = 0.1, minval = 0.5)



color up_col = input.color(color.lime, "↑", inline = "color")

color dn_col = input.color(color.red, "↓", inline = "color")

color __col = input.color(color.yellow, "〜", inline = "color")



bool bar_col = input.bool(false, "BarColor", inline = "Features")

bool signals = input.bool(false, "Signals", inline = "Features")



// }




// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

atr = ta.atr(200) * bands



//@function Two-pole filter

//@param src (series float) Source data (e.g., price)

//@param length (float) Length of the filter (higher value means smoother output)

//@param damping (float) Damping factor for the filter

//@returns (series float) Filtered value

method two_pole_filter(float src, int length, float damping) =>

    // Calculate filter coefficients

    float omega = 2.0 * math.pi / length

    float alpha = damping * omega

    float beta = math.pow(omega, 2)

   

    // Initialize the filter variables

    var float f1 = na

    var float f2 = na



    // Update the filter

    f1 := nz(f1[1]) + alpha * (src - nz(f1[1]))

    f2 := nz(f2[1]) + beta * (f1 - nz(f2[1]))

   

    f2




tp_f = close.two_pole_filter(length, damping)



var rising = 0

var falling = 0



up = tp_f > tp_f[2]

dn = tp_f < tp_f[2]



if up

    rising += 1

    falling := 0



if dn

    rising := 0

    falling += 1



color = up ? color.from_gradient(rising, 0, 15, __col, up_col) : dn ? color.from_gradient(falling, 0, 15, __col, dn_col) : __col

// }





// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{

plot(tp_f, "Two-Pole Filter", color = color, linewidth = 3)



plotshape(falling >= ris_fal ? tp_f + atr : na, "Falling", shape.circle, location.absolute, color = color)

plotshape(rising >= ris_fal  ? tp_f - atr : na, "Rising", shape.circle, location.absolute, color = color)



bool sig_up = ta.crossover(rising, ris_fal) and barstate.isconfirmed and signals

bool sig_dn = ta.crossover(falling, ris_fal) and barstate.isconfirmed and signals



plotshape(sig_dn ? tp_f[1] + atr : na, "Falling", shape.triangledown, location.absolute, color = color, size = size.tiny, offset = -1)

plotshape(sig_up ? tp_f[1] - atr : na, "Rising", shape.triangleup, location.absolute, color = color, size = size.tiny, offset = -1)




barcolor(bar_col ? color : na)

// }

지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-11-12 11:23:25

안녕하세요 예스스탁입니다. input : length(20); input : damping(0.9); input : ris_fal(5); input : bands(1.0); input : up_col(lime); input : dn_col(red); input : __col(yellow); input : bar_col(false); input : signals(false); var : a(0),atrv(0),atr(0); var : omega(0),alpha(0),beta(0),f1(Nan),tp_f(Nan); var : rising(0),falling(0); var : up(False),dn(False),color(0),tx(0); a = 1 / 200; ATRV = IFf(IsNan(ATRV[1]) == true, ma(TrueRange,200) , a * TrueRange + (1 - a) * IFf(isnan(ATRV[1])==true,0,ATRV[1])); atr = atrv* bands; omega = 2.0 * pie / length; alpha = damping * omega; beta = pow(omega, 2); f1 = iff(isnan(f1[1])==true,0,f1[1]) + alpha * (close - iff(isnan(f1[1])==true,0,f1[1])); tp_f = iff(isnan(tp_f[1])==true,0,tp_f[1]) + beta * (f1 - iff(isnan(tp_f[1])==true,0,tp_f[1])); up = tp_f > tp_f[2]; dn = tp_f < tp_f[2]; if up then { rising = rising+1; falling = 0; } if dn Then { rising = 0; falling = falling+ 1; } color = iff(up ,up_col , iff(dn ,dn_col, __col)); plot1(tp_f, "Two-Pole Filter", color); if falling >= ris_fal Then plot2(tp_f + atr, "Falling",color); //점그래프로 Else NoPlot(2); if rising >= ris_fal Then plot3(tp_f - atr, "Falling",color); //점그래프로 Else NoPlot(3); 즐거운 하루되세요