커뮤니티

수식 부탁드립니다

프로필 이미지
사노소이
2025-05-13 00:37:04
274
글번호 190758
답변완료
매번 도와주셔서 감사합니다. 지표식 부탁드립니다. //@version=4 study(title="Gaussian Channel [DW]", shorttitle="GC [DW]", overlay=true) // This study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity. // Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times. // First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this 스크립트 is 9. // Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode". // Then the alpha and source values are used to calculate the filter and filtered true range of the dataset. // Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel. // Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode". //Custom bar colors are included. //Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is. // Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag. // For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower trun_cates the equation. //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //업데이트: // Huge shoutout to @e2e4mfck for taking the time to improve the calculation method! // -> migrated to v4 // -> pi is now calculated using trig identities rather than being explicitly defined. // -> The filter calculations are now organized into functions rather than being individually defined. // -> Revamped color scheme. //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Functions - courtesy of @e2e4mfck //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Filter function f_filt9x (_a, _s, _i) => int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0, int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a) // Weights. // Initial weight _m1 is a pole number and equal to _i _m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0 _m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0 _m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5 : _i == 4 ? 1 : 0 _m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1 : 0 _m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0 _m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0 _m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0 _m9 := _i == 9 ? 1 : 0 // filter _f := pow(_a, _i) * nz(_s) + _i * _x * nz(_f[1]) - (_i >= 2 ? _m2 * pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ? _m3 * pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ? _m4 * pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ? _m5 * pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ? _m6 * pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ? _m7 * pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ? _m8 * pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ? _m9 * pow(_x, 9) * nz(_f[9]) : 0) //9 var declaration fun f_pole (_a, _s, _i) => _f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0), _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0) _f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5) : 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0) _f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8) : 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0) _fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na [_fn, _f1] //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Inputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Source src = input(defval=hlc3, title="Source") //Poles int N = input(defval=4, title="Poles", minval=1, maxval=9) //Period int per = input(defval=144, title="Sampling Period", minval=2) //True Range Multiplier float mult = input(defval=1.414, title="Filtered True Range Multiplier", minval=0) //Lag Reduction bool modeLag = input(defval=false, title="Reduced Lag Mode") bool modeFast = input(defval=false, title="Fast Response Mode") //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Definitions //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Beta and Alpha Components beta = (1 - cos(4*asin(1)/per)) / (pow(1.414, 2/N) - 1) alpha = - beta + sqrt(pow(beta, 2) + 2*beta) //Lag lag = (per - 1)/(2*N) //Data srcdata = modeLag ? src + (src - src[lag]) : src trdata = modeLag ? tr(true) + (tr(true) - tr(true)[lag]) : tr(true) //Filtered Values [filtn, filt1] = f_pole(alpha, srcdata, N) [filtntr, filt1tr] = f_pole(alpha, trdata, N) //Lag Reduction filt = modeFast ? (filtn + filt1)/2 : filtn filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr //Bands hband = filt + filttr*mult lband = filt - filttr*mult // Colors color1 = #0aff68 color2 = #00752d color3 = #ff0a5a color4 = #990032 fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 : (src > src[1]) and (src >= hband) ? #0aff1b : (src <= src[1]) and (src > filt) ? #00752d : (src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a : (src < src[1]) and (src <= lband) ? #ff0a11 : (src >= src[1]) and (src < filt) ? #990032 : #cccccc //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Outputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Filter Plot filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3) //Band Plots hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor) lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor) //Channel Fill fill(hbandplot, lbandplot, title="Channel Fill", color=fcolor, transp=80) //Bar Color barcolor(barcolor)
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-05-13 16:25:24

안녕하세요 예스스탁입니다. 사용자함수 2개 먼저 만드신 후에 지표식 작성해 사용하시면 됩니다. 1. 사용자함수 사용자함수명 : f_filt9x 반환값형 : 숫자형 input :_a(Numeric),_s(Numeric),_i(Numeric); var : _m2(0),_m3(0),_m4(0),_m5(0),_m6(0); var : _m7(0),_m8(0),_m9(0),_f(0),_x(0); _x = (1-_a); _m2 = iff(_i == 9 , 36 , iff(_i == 8 , 28 , iff(_i == 7 , 21 , iff(_i == 6 , 15 , iff(_i == 5 , 10 ,iff( _i == 4 , 6 , iff(_i == 3 , 3 , iff(_i == 2 , 1 , 0)))))))); _m3 = iff(_i == 9 , 84 , iff(_i == 8 , 56 , iff(_i == 7 , 35 , iff(_i == 6 , 20 , iff(_i == 5 , 10 ,iff( _i == 4 , 4 , iff(_i == 3 , 1 , 0))))))); _m4 = iff(_i == 9 , 126 , iff(_i == 8 , 70 , iff(_i == 7 , 35 , iff(_i == 6 , 15 , iff(_i == 5 , 5 ,iff( _i == 4 , 1 , 0)))))); _m5 = iff(_i == 9 , 126 , iff(_i == 8 , 56 , iff(_i == 7 , 21 , iff(_i == 6 , 6 , iff(_i == 5 , 1 , 0))))); _m6 = iff(_i == 9 , 84 , iff(_i == 8 , 28 , iff(_i == 7 , 7 , iff(_i == 6 , 1 , 0)))); _m7 = iff(_i == 9 , 36 , iff(_i == 8 , 8 , iff(_i == 7 , 1 , 0))); _m8 = iff(_i == 9 , 9 , iff(_i == 8 , 1 , 0)); _m9 = iff(_i == 9 , 1 , 0); // filter _f = pow(_a, _i) * IFF(IsNan(_s)==true,0,_s) + _i * _x *IFF(IsNan(_f[1])==true,0,_f[1]) - IFF(_i >= 2 , _m2 * pow(_x, 2) * IFF(IsNan(_f[2])==true,0,_f[2]) , 0) + IFF(_i >= 3 , _m3 * pow(_x, 3) * IFF(IsNan(_f[3])==true,0,_f[3]) , 0) - IFF(_i >= 4 , _m4 * pow(_x, 4) * IFF(IsNan(_f[4])==true,0,_f[4]) , 0) + IFF(_i >= 5 , _m5 * pow(_x, 5) * IFF(IsNan(_f[5])==true,0,_f[5]) , 0) - IFF(_i >= 6 , _m6 * pow(_x, 6) * IFF(IsNan(_f[6])==true,0,_f[6]) , 0) + IFF(_i >= 7 , _m7 * pow(_x, 7) * IFF(IsNan(_f[7])==true,0,_f[7]) , 0) - IFF(_i >= 8 , _m8 * pow(_x, 8) * IFF(IsNan(_f[8])==true,0,_f[8]), 0) + IFF(_i == 9 , _m9 * pow(_x, 9) * IFF(IsNan(_f[9])==true,0,_f[9]), 0); f_filt9x = _f; 2. 사용자함수 사용자함수명 : f_pole 반환값형 : 숫자형 input :_a(Numeric),_s(Numeric),_i(Numeric),fn(NumericRef),f1(NumericRef); var : _f1(0),_f2(0),_f3(0),_f4(0),_f5(0); var : _f6(0),_f7(0),_f8(0),_f9(0); _f1 = f_filt9x(_a, _s, 1); _f2 = IFF(_i >= 2 , f_filt9x(_a, _s, 2) , 0); _f3 = IFF(_i >= 3 , f_filt9x(_a, _s, 3) , 0); _f4 = IFF(_i >= 4 , f_filt9x(_a, _s, 4) , 0); _f5 = IFF(_i >= 5 , f_filt9x(_a, _s, 5) , 0); _f6 = IFF(_i >= 6 , f_filt9x(_a, _s, 6) , 0); _f7 = IFF(_i >= 2 , f_filt9x(_a, _s, 7) , 0); _f8 = IFF(_i >= 8 , f_filt9x(_a, _s, 8) , 0); _f9 = IFF(_i == 9 , f_filt9x(_a, _s, 9) , 0); fn = iff(_i == 1 , _f1 , iff(_i == 2 , _f2 , iff(_i == 3 , _f3 , iff(_i == 4 , _f4 , iff(_i == 5 , _f5 , iff(_i == 6 , _f6 , iff(_i == 7 , _f7 , iff(_i == 8 , _f8 , iff(_i == 9 , _f9 , Nan))))))))); f1 = _f1; f_pole = 1; 3. 지표 var : src(0); src = (h+l+c)/3; input : N(4); input : Per(144); input : mult(1.414); input : modeLag(false); input : modeFast(false); var : bet(0),beta(0),alpha(0),lag(0),tr(0); var : srcdata(0),trdata(0); bet = 4*asin(1)/per; beta = (1 - cos(bet*(180/Pie))) / (pow(1.414, 2/N) - 1); alpha = - beta + sqrt(pow(beta, 2) + 2*beta); lag = (per - 1)/(2*N); tr = TrueRange; srcdata = iff(modeLag , src + (src - src[lag]) , src); trdata = iff(modeLag , tr + (tr - tr[lag]) , tr); var : filtn(0),filt1(0),filtntr(0),filt1tr(0); var : filt(0),filttr(0),hband(0),lband(0); var1 = f_pole(alpha, srcdata, N,filtn,filt1); var2 = f_pole(alpha, trdata, N,filtntr,filt1tr); //Lag Reduction filt = iff(modeFast , (filtn + filt1)/2 , filtn); filttr = iff(modeFast , (filtntr + filt1tr)/2 , filtntr); //Bands hband = filt + filttr*mult; lband = filt - filttr*mult; // Colors var : color1(0),color2(0),color3(0),color4(0),fcolor(0); fcolor = iff(filt > filt[1] , Lime ,IFf(filt < filt[1] ,Red ,Gray)); plot1(filt, "Filter", fcolor); plot2(hband, "Filtered True Range High Band", fcolor); plot3(lband, "Filtered True Range Low Band", fcolor); 즐거운 하루되세요 > 사노소이 님이 쓴 글입니다. > 제목 : 수식 부탁드립니다 > 매번 도와주셔서 감사합니다. 지표식 부탁드립니다. //@version=4 study(title="Gaussian Channel [DW]", shorttitle="GC [DW]", overlay=true) // This study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity. // Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times. // First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this 스크립트 is 9. // Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode". // Then the alpha and source values are used to calculate the filter and filtered true range of the dataset. // Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel. // Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode". //Custom bar colors are included. //Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is. // Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag. // For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower trun_cates the equation. //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //업데이트: // Huge shoutout to @e2e4mfck for taking the time to improve the calculation method! // -> migrated to v4 // -> pi is now calculated using trig identities rather than being explicitly defined. // -> The filter calculations are now organized into functions rather than being individually defined. // -> Revamped color scheme. //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Functions - courtesy of @e2e4mfck //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Filter function f_filt9x (_a, _s, _i) => int _m2 = 0, int _m3 = 0, int _m4 = 0, int _m5 = 0, int _m6 = 0, int _m7 = 0, int _m8 = 0, int _m9 = 0, float _f = .0, _x = (1 - _a) // Weights. // Initial weight _m1 is a pole number and equal to _i _m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0 _m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0 _m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5 : _i == 4 ? 1 : 0 _m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1 : 0 _m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0 _m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0 _m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0 _m9 := _i == 9 ? 1 : 0 // filter _f := pow(_a, _i) * nz(_s) + _i * _x * nz(_f[1]) - (_i >= 2 ? _m2 * pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ? _m3 * pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ? _m4 * pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ? _m5 * pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ? _m6 * pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ? _m7 * pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ? _m8 * pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ? _m9 * pow(_x, 9) * nz(_f[9]) : 0) //9 var declaration fun f_pole (_a, _s, _i) => _f1 = f_filt9x(_a, _s, 1), _f2 = (_i >= 2 ? f_filt9x(_a, _s, 2) : 0), _f3 = (_i >= 3 ? f_filt9x(_a, _s, 3) : 0) _f4 = (_i >= 4 ? f_filt9x(_a, _s, 4) : 0), _f5 = (_i >= 5 ? f_filt9x(_a, _s, 5) : 0), _f6 = (_i >= 6 ? f_filt9x(_a, _s, 6) : 0) _f7 = (_i >= 2 ? f_filt9x(_a, _s, 7) : 0), _f8 = (_i >= 8 ? f_filt9x(_a, _s, 8) : 0), _f9 = (_i == 9 ? f_filt9x(_a, _s, 9) : 0) _fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na [_fn, _f1] //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Inputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Source src = input(defval=hlc3, title="Source") //Poles int N = input(defval=4, title="Poles", minval=1, maxval=9) //Period int per = input(defval=144, title="Sampling Period", minval=2) //True Range Multiplier float mult = input(defval=1.414, title="Filtered True Range Multiplier", minval=0) //Lag Reduction bool modeLag = input(defval=false, title="Reduced Lag Mode") bool modeFast = input(defval=false, title="Fast Response Mode") //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Definitions //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Beta and Alpha Components beta = (1 - cos(4*asin(1)/per)) / (pow(1.414, 2/N) - 1) alpha = - beta + sqrt(pow(beta, 2) + 2*beta) //Lag lag = (per - 1)/(2*N) //Data srcdata = modeLag ? src + (src - src[lag]) : src trdata = modeLag ? tr(true) + (tr(true) - tr(true)[lag]) : tr(true) //Filtered Values [filtn, filt1] = f_pole(alpha, srcdata, N) [filtntr, filt1tr] = f_pole(alpha, trdata, N) //Lag Reduction filt = modeFast ? (filtn + filt1)/2 : filtn filttr = modeFast ? (filtntr + filt1tr)/2 : filtntr //Bands hband = filt + filttr*mult lband = filt - filttr*mult // Colors color1 = #0aff68 color2 = #00752d color3 = #ff0a5a color4 = #990032 fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc barcolor = (src > src[1]) and (src > filt) and (src < hband) ? #0aff68 : (src > src[1]) and (src >= hband) ? #0aff1b : (src <= src[1]) and (src > filt) ? #00752d : (src < src[1]) and (src < filt) and (src > lband) ? #ff0a5a : (src < src[1]) and (src <= lband) ? #ff0a11 : (src >= src[1]) and (src < filt) ? #990032 : #cccccc //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Outputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Filter Plot filtplot = plot(filt, title="Filter", color=fcolor, linewidth=3) //Band Plots hbandplot = plot(hband, title="Filtered True Range High Band", color=fcolor) lbandplot = plot(lband, title="Filtered True Range Low Band", color=fcolor) //Channel Fill fill(hbandplot, lbandplot, title="Channel Fill", color=fcolor, transp=80) //Bar Color barcolor(barcolor)