커뮤니티

부틱드립니다

프로필 이미지
파생돌이
2025-09-30 10:10:52.0
52
글번호 194396
답변완료
수고하십니다 예스로 부탁드립니다 // This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International // https://creativecommons.org/licenses/by-nc-sa/4.0/ // © Zeiierman { //@version=6 indicator("AI-Weighted RSI (Zeiierman)", overlay=false, max_lines_count=500, max_labels_count=500, precision = 1) //~~} // ~~ Tooltips { var string t1 = "RSI lookback length computed on the current timeframe." var string t2 = "Moving Average lookback length computed on RSI." var string t3 = "Rolling window for correlation learning and z-scoring.." //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Inputs { rsiLen = input.int(14, "RSI Length", minval=2, group="Rsi Settings", tooltip=t1) sigLen = input.int(20, "Signal Length", minval=2, group="Rsi Settings", tooltip=t2) learnLen = input.int(20, "Learning Window", minval=1, group="Learning / Prediction", tooltip=t3) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Per-bar features { retLog = math.log(close / nz(close[1], close)) rsiVal = ta.rsi(close, rsiLen) atrPct = ta.atr(200) / close vol = volume volLogChg = math.log(vol / nz(vol[1], vol)) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Target (y): prior bar RSI { y_rsi = rsiVal[1] //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Predictors (X): prior-bar values of each feature (aligned with y) { x_ret = nz(retLog[1]) x_rsi = nz(rsiVal[1]) x_atrp = nz(atrPct[1]) x_vchg = nz(volLogChg[1]) x_vol = nz(vol[1]) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Utilities { f_z(src, len) => m = ta.sma(src, len) s = ta.stdev(src, len) s > 0 ? (src - m) / s : 0 f_corr(a, b, len) => ta.correlation(a, b, len) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Top-K indices by value { f_topk_indices(arr) => sz = arr.size() kk = math.min(5, sz) tmp = array.new_float(sz, 0.0) for i = 0 to sz - 1 tmp.set(i, nz(arr.get(i))) out = array.new_int() for n = 0 to kk - 1 maxI = 0 maxV = tmp.get(0) for j = 1 to sz - 1 vj = tmp.get(j) take = na(maxV) or (not na(vj) and vj > maxV) if take maxV := vj maxI := j out.push(maxI) tmp.set(maxI, na) out //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Feature S e leCTion via correlations { corrs_abs_ret = math.abs(nz(f_corr(y_rsi, x_ret, learnLen))) corrs_abs_rsi = math.abs(nz(f_corr(y_rsi, x_rsi, learnLen))) corrs_abs_atrp = math.abs(nz(f_corr(y_rsi, x_atrp, learnLen))) corrs_abs_vchg = math.abs(nz(f_corr(y_rsi, x_vchg, learnLen))) corrs_abs_vol = math.abs(nz(f_corr(y_rsi, x_vol, learnLen))) corrs = array.from(corrs_abs_ret, corrs_abs_rsi, corrs_abs_atrp, corrs_abs_vchg, corrs_abs_vol) topIdx = f_topk_indices(corrs) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Z-scored current levels of each predictor series { xz_ret = nz(f_z(x_ret, learnLen)) xz_rsi = nz(f_z(x_rsi, learnLen)) xz_atrp = nz(f_z(x_atrp, learnLen)) xz_vchg = nz(f_z(x_vchg, learnLen)) xz_vol = nz(f_z(x_vol, learnLen)) featZ = array.from(xz_ret, xz_rsi, xz_atrp, xz_vchg, xz_vol) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Signed “coefficients” ~ correlations on standardized inputs { coef_ret = nz(f_corr(y_rsi, x_ret, learnLen)) coef_rsi = 1.0 // Hardcoded: always 1, since x_rsi == y_rsi coef_atrp = nz(f_corr(y_rsi, x_atrp, learnLen)) coef_vchg = nz(f_corr(y_rsi, x_vchg, learnLen)) coef_vol = nz(f_corr(y_rsi, x_vol, learnLen)) coef = array.from(coef_ret, coef_rsi, coef_atrp, coef_vchg, coef_vol) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Prediction from S e leCTed features: sum_i corr_i * z(feature_i) { f_pred(topIdxArr, coefArr, featArr) => s = 0.0 k = topIdxArr.size() for i = 0 to k - 1 idx = topIdxArr.get(i) c = coefArr.get(idx) z = featArr.get(idx) s += (nz(c) * nz(z)) s pred_rsi_z = f_pred(topIdx, coef, featZ) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Map z back to RSI level using rolling mean/std of the target { rsi_mean = ta.sma(y_rsi, learnLen) rsi_std = ta.stdev(y_rsi, learnLen) pred_rsi = nz(rsi_mean) + nz(rsi_std) * pred_rsi_z //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Map prediction → “weight” { rsiWeight = math.max(-2, math.min(2, (50 - nz(pred_rsi)) / 50)) * -1 ma_rsi = ta.sma(rsiWeight,sigLen) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Plots { rsiPlot = plot(rsiWeight, "AI-Weighted RSI", color=#7E57C2) rsiMa = plot(ma_rsi, "AI-Weighted RSI Signal Line", color=color.yellow) rsiUpperBand = hline(0.5, "AI-Weighted RSI Upper Band", color=#787B86) midline = hline(0, "AI-Weighted RSI Middle Band", color=color.new(#787B86, 50)) rsiLowerBand = hline(-0.5, "AI-Weighted RSI Lower Band", color=#787B86) fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="AI-Weighted RSI Background Fill") midLinePlot = plot(0, color = na, editable = false, display = display.none) fill(rsiPlot, midLinePlot, 0.5, 0, top_color = color.new(color.lime, 0), bottom_color = color.new(color.lime, 100), title = "Overbought Gradient Fill") fill(rsiPlot, midLinePlot, 0, -0.5, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill") //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-09-30 14:59:49.0

안녕하세요 예스스탁입니다. input : rsiLen(14); input : sigLen(20); input : learnLen(20); var : retLog(0),rsiVal(0),alpha(0),ATRV(0),atrPct(0),vol(0),volLogChg(0),y_rsi(0); var : x_ret(0),x_rsi(0),x_atrp(0),x_vchg(0),x_vol(0); retLog = log(close / iff(isnan(close[1])==true, close,close[1])); rsiVal = rsi(rsiLen); alpha = 1 / 200 ; ATRV = IFf(IsNan(ATRV[1]) == true, ma(TrueRange,200) , alpha * TrueRange + (1 - alpha) * IFf(isnan(ATRV[1])==true,0,ATRV[1])); atrPct = ATRV / close; vol = volume; volLogChg = log(vol / iff(isnan(vol[1])==true, vol,vol[1])); y_rsi = rsiVal[1]; x_ret = iff(IsNan(retLog[1])==true,0,retLog[1]); x_rsi = iff(IsNan(rsiVal[1])==true,0,rsiVal[1]); x_atrp = iff(IsNan(atrPct[1])==true,0,atrPct[1]); x_vchg = iff(IsNan(volLogChg[1])==true,0,volLogChg[1]); x_vol = iff(IsNan(vol[1])==true,0,vol[1]); var1 = CoefficientR(y_rsi, x_ret, learnLen); var2 = CoefficientR(y_rsi, x_rsi, learnLen); var3 = CoefficientR(y_rsi, x_atrp, learnLen); var4 = CoefficientR(y_rsi, x_vchg, learnLen); var5 = CoefficientR(y_rsi, x_vol, learnLen); var : corrs_abs_ret(0),corrs_abs_rsi(0),corrs_abs_atrp(0),corrs_abs_vchg(0),corrs_abs_vol(0); corrs_abs_ret = abs(iff(IsNan(var1)==true,0,var1)); corrs_abs_rsi = abs(iff(IsNan(var2)==true,0,var2)); corrs_abs_atrp = abs(iff(IsNan(var3)==true,0,var3)); corrs_abs_vchg = abs(iff(IsNan(var4)==true,0,var4)); corrs_abs_vol = abs(iff(IsNan(var5)==true,0,var5)); Array : corrs[5](0); corrs[0] = corrs_abs_ret; corrs[1] = corrs_abs_rsi; corrs[2] = corrs_abs_atrp; corrs[3] = corrs_abs_vchg; corrs[4] = corrs_abs_vol; var : i(0),j(0),n(0); Array : tmp[5](0),topIdx[5](0); var : maxI(0),maxV(0),vj(0),take(False); for i = 0 to 4 { tmp[i] = iff(IsNan(corrs[i])==true,0,corrs[i]); topIdx[i] = 0; } for n = 0 to 4 { maxI = 0; maxV = tmp[0]; for j = 1 to 4 { vj = tmp[j]; take = isnan(maxV) == true or (IsNan(vj) == False and vj > maxV); if take Then { maxV = vj; maxI = j; } } topIdx[n] = maxI; tmp[maxI] = nan; } var : xz_ret(0),xz_rsi(0),xz_atrp(0),xz_vchg(0),xz_vol(0); var : m1(0),s1(0),fz1(0); var : m2(0),s2(0),fz2(0); var : m3(0),s3(0),fz3(0); var : m4(0),s4(0),fz4(0); var : m5(0),s5(0),fz5(0); Array : featz[5](0); m1 = ma(x_ret, learnLen); s1 = std(x_ret, learnLen); fz1 = iff(s1 > 0 , (x_ret - m1) / s1 , 0); m2 = ma(x_rsi, learnLen); s2 = std(x_rsi, learnLen); fz2 = iff(s2 > 0 , (x_rsi - m2) / s2 , 0); m3 = ma(x_atrp, learnLen); s3 = std(x_atrp, learnLen); fz3 = iff(s3 > 0 , (x_atrp - m3) / s3 , 0); m4 = ma(x_vchg, learnLen); s4 = std(x_vchg, learnLen); fz4 = iff(s4 > 0 , (x_vchg - m4) / s4 , 0); m5 = ma(x_vol, learnLen); s5 = std(x_vol, learnLen); fz5 = iff(s5 > 0 , (x_vol - m5) / s5 , 0); xz_ret = iff(isnan(fz1) ==true,0,fz1); xz_rsi = iff(isnan(fz2) ==true,0,fz2); xz_atrp = iff(isnan(fz3) ==true,0,fz3); xz_vchg = iff(isnan(fz4) ==true,0,fz4); xz_vol = iff(isnan(fz5) ==true,0,fz5); featZ[0] = xz_ret; featZ[1] = xz_rsi; featZ[2] = xz_atrp; featZ[3] = xz_vchg; featZ[4] = xz_vol; value1 = CoefficientR(y_rsi, x_ret, learnLen); value3 = CoefficientR(y_rsi, x_atrp, learnLen); value4 = CoefficientR(y_rsi, x_vchg, learnLen); value5 = CoefficientR(y_rsi, x_vol, learnLen); var : coef_ret(0),coef_rsi(0),coef_atrp(0),coef_vchg(0),coef_vol(0); coef_ret = iff(IsNan(value1)==true,0,value1); coef_rsi = 1.0; // Hardcoded: always 1, since x_rsi == y_rsi coef_atrp = iff(IsNan(value3)==true,0,value3); coef_vchg = iff(IsNan(value4)==true,0,value4); coef_vol = iff(IsNan(value5)==true,0,value5); Array : coef[5](0); coef[0] = coef_ret; coef[1] = coef_rsi; coef[2] = coef_atrp; coef[3] = coef_vchg; coef[4] = coef_vol; var : s(0),idx(0),g(0),z(0),pred_rsi_z(0); s = 0.0; pred_rsi_z = 0; for i = 0 to 4 { idx = topIdx[i]; g = coef[idx]; z = featZ[idx]; pred_rsi_z = pred_rsi_z + (iff(isnan(g)==true,0,g) * IFf(IsNan(z)==true,0,z)); } var : rsi_mean(0),rsi_std(0),pred_rsi(0); var : rsiWeight(0),ma_rsi(0); rsi_mean = ma(y_rsi, learnLen); rsi_std = std(y_rsi, learnLen); pred_rsi = iff(isnan(rsi_mean)==true,0,rsi_mean) + iff(isnan(rsi_std)==true,0,rsi_std) * pred_rsi_z; rsiWeight = max(-2, min(2, (50 - iff(isnan(pred_rsi)==true,0,pred_rsi)) / 50)) * -1; ma_rsi = ma(rsiWeight,sigLen); plot1(rsiWeight, "AI-Weighted RSI",Violet); plot2(ma_rsi, "AI-Weighted RSI Signal Line",yellow); plot3(0.5, "AI-Weighted RSI Upper Band",Gray); plot4(0, "AI-Weighted RSI Middle Band", gray); plot5(-0.5, "AI-Weighted RSI Lower Band",Gray); 즐거운 명절 되시기 바랍니다. > 파생돌이 님이 쓴 글입니다. > 제목 : 부틱드립니다 > 수고하십니다 예스로 부탁드립니다 // This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International // https://creativecommons.org/licenses/by-nc-sa/4.0/ // © Zeiierman { //@version=6 indicator("AI-Weighted RSI (Zeiierman)", overlay=false, max_lines_count=500, max_labels_count=500, precision = 1) //~~} // ~~ Tooltips { var string t1 = "RSI lookback length computed on the current timeframe." var string t2 = "Moving Average lookback length computed on RSI." var string t3 = "Rolling window for correlation learning and z-scoring.." //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Inputs { rsiLen = input.int(14, "RSI Length", minval=2, group="Rsi Settings", tooltip=t1) sigLen = input.int(20, "Signal Length", minval=2, group="Rsi Settings", tooltip=t2) learnLen = input.int(20, "Learning Window", minval=1, group="Learning / Prediction", tooltip=t3) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Per-bar features { retLog = math.log(close / nz(close[1], close)) rsiVal = ta.rsi(close, rsiLen) atrPct = ta.atr(200) / close vol = volume volLogChg = math.log(vol / nz(vol[1], vol)) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Target (y): prior bar RSI { y_rsi = rsiVal[1] //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Predictors (X): prior-bar values of each feature (aligned with y) { x_ret = nz(retLog[1]) x_rsi = nz(rsiVal[1]) x_atrp = nz(atrPct[1]) x_vchg = nz(volLogChg[1]) x_vol = nz(vol[1]) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Utilities { f_z(src, len) => m = ta.sma(src, len) s = ta.stdev(src, len) s > 0 ? (src - m) / s : 0 f_corr(a, b, len) => ta.correlation(a, b, len) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Top-K indices by value { f_topk_indices(arr) => sz = arr.size() kk = math.min(5, sz) tmp = array.new_float(sz, 0.0) for i = 0 to sz - 1 tmp.set(i, nz(arr.get(i))) out = array.new_int() for n = 0 to kk - 1 maxI = 0 maxV = tmp.get(0) for j = 1 to sz - 1 vj = tmp.get(j) take = na(maxV) or (not na(vj) and vj > maxV) if take maxV := vj maxI := j out.push(maxI) tmp.set(maxI, na) out //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Feature S e leCTion via correlations { corrs_abs_ret = math.abs(nz(f_corr(y_rsi, x_ret, learnLen))) corrs_abs_rsi = math.abs(nz(f_corr(y_rsi, x_rsi, learnLen))) corrs_abs_atrp = math.abs(nz(f_corr(y_rsi, x_atrp, learnLen))) corrs_abs_vchg = math.abs(nz(f_corr(y_rsi, x_vchg, learnLen))) corrs_abs_vol = math.abs(nz(f_corr(y_rsi, x_vol, learnLen))) corrs = array.from(corrs_abs_ret, corrs_abs_rsi, corrs_abs_atrp, corrs_abs_vchg, corrs_abs_vol) topIdx = f_topk_indices(corrs) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Z-scored current levels of each predictor series { xz_ret = nz(f_z(x_ret, learnLen)) xz_rsi = nz(f_z(x_rsi, learnLen)) xz_atrp = nz(f_z(x_atrp, learnLen)) xz_vchg = nz(f_z(x_vchg, learnLen)) xz_vol = nz(f_z(x_vol, learnLen)) featZ = array.from(xz_ret, xz_rsi, xz_atrp, xz_vchg, xz_vol) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Signed “coefficients” ~ correlations on standardized inputs { coef_ret = nz(f_corr(y_rsi, x_ret, learnLen)) coef_rsi = 1.0 // Hardcoded: always 1, since x_rsi == y_rsi coef_atrp = nz(f_corr(y_rsi, x_atrp, learnLen)) coef_vchg = nz(f_corr(y_rsi, x_vchg, learnLen)) coef_vol = nz(f_corr(y_rsi, x_vol, learnLen)) coef = array.from(coef_ret, coef_rsi, coef_atrp, coef_vchg, coef_vol) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Prediction from S e leCTed features: sum_i corr_i * z(feature_i) { f_pred(topIdxArr, coefArr, featArr) => s = 0.0 k = topIdxArr.size() for i = 0 to k - 1 idx = topIdxArr.get(i) c = coefArr.get(idx) z = featArr.get(idx) s += (nz(c) * nz(z)) s pred_rsi_z = f_pred(topIdx, coef, featZ) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Map z back to RSI level using rolling mean/std of the target { rsi_mean = ta.sma(y_rsi, learnLen) rsi_std = ta.stdev(y_rsi, learnLen) pred_rsi = nz(rsi_mean) + nz(rsi_std) * pred_rsi_z //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Map prediction → “weight” { rsiWeight = math.max(-2, math.min(2, (50 - nz(pred_rsi)) / 50)) * -1 ma_rsi = ta.sma(rsiWeight,sigLen) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Plots { rsiPlot = plot(rsiWeight, "AI-Weighted RSI", color=#7E57C2) rsiMa = plot(ma_rsi, "AI-Weighted RSI Signal Line", color=color.yellow) rsiUpperBand = hline(0.5, "AI-Weighted RSI Upper Band", color=#787B86) midline = hline(0, "AI-Weighted RSI Middle Band", color=color.new(#787B86, 50)) rsiLowerBand = hline(-0.5, "AI-Weighted RSI Lower Band", color=#787B86) fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="AI-Weighted RSI Background Fill") midLinePlot = plot(0, color = na, editable = false, display = display.none) fill(rsiPlot, midLinePlot, 0.5, 0, top_color = color.new(color.lime, 0), bottom_color = color.new(color.lime, 100), title = "Overbought Gradient Fill") fill(rsiPlot, midLinePlot, 0, -0.5, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill") //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}