커뮤니티

수식 부탁드립니다

프로필 이미지
사노소이
2025-10-25 21:11:25
180
글번호 227298
답변완료

지표식 부탁 드립니다. 
//@version=5 indicator('DFT', overlay=true)

import jdehorty/KernelFunctions/2 as kernel

// INPUTS N = input.int(10,"Fourier Period") xval = input.source(close,"Fourier X Series",tooltip = "i.e. the source of the discrete Fourier"+  " transform (with the Y Series being the bars through time.)") highlighting = input.bool(true,"Highlighting") smoothing = input.int(10,"Kernel Smoothing")


DFT(x, y, Nx, _dir) =>     float _arg = 0.0     float _cos = 0.0     float _sin = 0.0     float xArr_i = 0.0     float yArr_i = 0.0     xArr = array.new_float(array.size(x))     yArr = array.new_float(array.size(y))

    for i = 0 to Nx - 1 by 1         xArr_i := 0.0         yArr_i := 0.0         kx = float(i) / float(Nx)         _arg := -_dir * 2 * math.pi * kx         for k = 0 to Nx - 1 by 1             _cos := math.cos(k * _arg)             _sin := math.sin(k * _arg)             xArr_i += array.get(x, k) * _cos - array.get(y, k) * _sin             yArr_i += array.get(x, k) * _sin + array.get(y, k) * _cos             yArr_i         array.set(xArr, i, xArr_i)         array.set(yArr, i, yArr_i)

    if _dir == 1         for i = 0 to Nx - 1 by 1             array.set(x, i, array.get(xArr, i) / float(Nx))             array.set(y, i, array.get(yArr, i) / float(Nx))     else         for i = 0 to Nx - 1 by 1             array.set(x, i, array.get(xArr, i))             array.set(y, i, array.get(yArr, i))


// CALCULATIONS // Fourier transform x = array.new_float(N, 0.0) y = array.new_float(N, 0.0) for i = 0 to N - 1     array.set(x, i, xval[i])     array.set(y, i, 0.0)

DFT(x, y, N, 1)

mag = array.new_float(N, 0.0) for i = 0 to N - 1     mag_i = math.sqrt(math.pow(array.get(x, i), 2) + math.pow(array.get(y, i), 2))     array.set(mag, i, mag_i)

dft = array.get(mag,0) dfts = kernel.rationalQuadratic(dft,25,1,smoothing)

// DISPLAY ft = plot(dft, "DFT", color= color.white) fts = plot(dfts, "Smoothing", color = dfts > dft ? color.red : color.lime)

fill(ft,fts,color = highlighting and dfts > dft ? color.new(color.red,75) : highlighting and dfts < dft ? color.new(color.lime,75) : na)

지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-10-27 14:42:24

안녕하세요 예스스탁입니다. input : N(10); input : highlighting(true); input : smoothing(10); var : xval(0),_arg(0),_cos(0),_sin(0),xArr_i(0),yArr_i(0); var : i(0),k(0),kx(0),mag_i(0); Array : x[100](0),y[100](0),xArr[100](0),yArr[100](0),mag[100](0); xval = close; For i = 0 to 99 { x[i] = 0; y[i] = 0; } for i = 0 to N - 1 { x[i] = xval[i]; y[i] = 0; } for i = 0 to N - 1 step 1 { xArr_i = 0.0; yArr_i = 0.0; kx = i/N; _arg = -1 * 2 * pie * kx; for k = 0 to N - 1 step 1 { _cos = cos((k * _arg)*(180/Pie)); _sin = sin((k * _arg)*(180/Pie)); xArr_i = xArr_i + x[k] * _cos - y[k] * _sin; yArr_i = yArr_i + x[k] * _sin + y[k] * _cos; } xArr[i] = xArr_i; yArr[i] = yArr_i; } for i = 0 to N - 1 step 1 { x[i] = xArr[i] /N; y[i] = yArr[i] /N; } for i = 0 to N - 1 { mag_i = sqrt(pow(x[i], 2) +pow(y[i], 2)); mag[i] = mag_i; } var : _currentWeight(0),_cumulativeWeight(0),_size(0),dft(0),dfts(0),yy(0),w(0); dft = mag[0]; _currentWeight = 0; _cumulativeWeight = 0; _size = 10; for i = 0 to _size + smoothing { yy = dft[i]; w = pow(1 + (pow(i, 2) / ((pow(25, 2) * 2 * 1))), -1); _currentWeight = _currentWeight + yy*w; _cumulativeWeight = _cumulativeWeight+ w; } dfts = _currentWeight / _cumulativeWeight; // DISPLAY plot1(dft, "DFT"); plot2(dfts, "Smoothing", IFf(dfts > dft , red , lime)); 즐거운 하루되세요