我是做BTC交易的 我现在有指标PCA 根据PCA的 高风险阈值和低风险阈值去进场 现在我想让你帮我测算 在PCA高低风险阈值触发的时候 别的指标比如MACD RSI MTM 它们是什么样子的 我需要共振 一个方向的确定性共振 这样可以提高准确性 //@version=5 indicator("RSI + PCA + MACD背离 + MTM&MACD金死叉 + PCA+ADX复合背离 + 多空增量综合指标", overlay=true) // === 多空增量函数:计算MACD状态 === f_getMacdStatus(_src, _fast, _slow, _signal) => [macdLine, signalLine, hist] = ta.macd(_src, _fast, _slow, _signal) histChange = hist - hist[1] bullIncreasing = hist > 0 and histChange > 0 bullDecreasing = hist > 0 and histChange < 0 bearIncreasing = hist < 0 and histChange < 0 bearDecreasing = hist < 0 and histChange > 0 status = bullIncreasing ? "多头增量" : bullDecreasing ? "多头减量" : bearIncreasing ? "空头增量" : bearDecreasing ? "空头减量" : "无状态" colorStatus = bullIncreasing ? color.new(color.green, 0) : bullDecreasing ? color.new(color.green, 50) : bearIncreasing ? color.new(color.red, 0) : bearDecreasing ? color.new(color.red, 50) : color.new(color.gray, 0) [status, colorStatus] // === 获取不同时间框架的MACD状态 === [statusDaily, colorDaily] = request.security(syminfo.tickerid, "D", f_getMacdStatus(close, 12, 26, 9), lookahead=barmerge.lookahead_off) // 日线 [statusWeekly, colorWeekly] = request.security(syminfo.tickerid, "W", f_getMacdStatus(close, 12, 26, 9), lookahead=barmerge.lookahead_off) // 周线 [status4H, color4H] = request.security(syminfo.tickerid, "240", f_getMacdStatus(close, 12, 26, 9), lookahead=barmerge.lookahead_off) // 4小时 [status1H, color1H] = request.security(syminfo.tickerid, "60", f_getMacdStatus(close, 12, 26, 9), lookahead=barmerge.lookahead_off) // 1小时 [status15M, color15M] = request.security(syminfo.tickerid, "15", f_getMacdStatus(close, 12, 26, 9), lookahead=barmerge.lookahead_off) // 15分钟 // === 创建并更新多空状态表格(右上角,右对齐) === var table statusTable = table.new(position.top_right, 1, 5, border_width=1, border_color=color.new(color.gray, 50), frame_color=color.new(color.gray, 50), bgcolor=color.new(color.black, 90)) // 仅在最新K线更新表格(避免重复计算) if barstate.islast table.cell(statusTable, 0, 0, text="周线: " + statusWeekly, text_color=colorWeekly, text_size=size.normal, text_halign=text.align_right) table.cell(statusTable, 0, 1, text="日线: " + statusDaily, text_color=colorDaily, text_size=size.normal, text_halign=text.align_right) table.cell(statusTable, 0, 2, text="4小时: " + status4H, text_color=color4H, text_size=size.normal, text_halign=text.align_right) table.cell(statusTable, 0, 3, text="1小时: " + status1H, text_color=color1H, text_size=size.normal, text_halign=text.align_right) table.cell(statusTable, 0, 4, text="15分钟: " + status15M, text_color=color15M, text_size=size.normal, text_halign=text.align_right) // === RSI 参数 === rsiLength = input.int(14, "RSI周期") rsiOverbought = input.int(75, "超买阈值") rsiOversold = input.int(25, "超卖阈值") // === RSI 值计算 === rsi = ta.rsi(close, rsiLength) // === RSI 信号条件(添加阳线/阴线限制) === isBullishCandle = close >= open isBearishCandle = close <= open rsiBullish = rsi >= rsi[1] and rsi[1] <= rsiOversold and isBullishCandle rsiBearish = rsi <= rsi[1] and rsi[1] >= rsiOverbought and isBearishCandle // === RSI施加信号标记 === plotshape(rsiBullish, title="R 买", style=shape.labelup, location=location.belowbar, color=color.new(color.lime, 0), text="R买", textcolor=color.black, size=size.small) plotshape(rsiBearish, title="R 卖", style=shape.labeldown, location=location.abovebar, color=color.new(color.orange, 0), text="R卖", textcolor=color.black, size=size.small) // === PCA 参数 === mtf = input.timeframe("", title="时间框架") levelRiskSafe = input.int(defval=21, minval=0, maxval=100, title="低风险阈值") levelRiskad = input.int(defval=40, minval=0, maxval=100, title="中等风险阈值") macdRiskLevel = input.int(defval=60, minval=0, maxval=100, title="警告风险阈值") levelRiskDanger = input.int(defval=70, minval=0, maxval=100, title="高风险阈值") // ADX 背离参数 adxLength = input.int(defval=14, title="ADX周期") lookbackPeriod = input.int(defval=20, title="回看周期", minval=1) minStrength = input.float(defval=10.0, title="最小背离强度", step=0.1) // MACD 和 StochRSI 参数 macdFast = input.int(defval=12, title="MACD快线周期") macdSlow = input.int(defval=26, title="MACD慢线周期") macdSignal = input.int(defval=9, title="MACD信号线周期") // 是否启用信号有效性过滤 useValidFilter = input.bool(defval=false, title="启用信号有效性过滤") // === MTM 参数 === mtmLength = input.int(60, "MTM计算周期", minval=1) mtmMALength = input.int(40, "MTM移动平均周期", minval=1) // === 信号有效性验证(保留趋势和波动率过滤) === trendStrength = ta.ema(close, 5) - ta.ema(close, 20) validTrend = math.abs(trendStrength) >= ta.atr(14) * 0.5 validVolatility = ta.atr(14) >= close * 0.005 normalWick = (high - low) <= ta.atr(14) * 3 isValid = validTrend and validVolatility and normalWick // ADX 计算 [diPlus, diMinus, adxValue] = ta.dmi(adxLength, adxLength) // === MACD 计算(提前以确保变量可用) === [macdLine, signalLine, macdHist] = request.security(syminfo.tickerid, mtf, ta.macd(close, macdFast, macdSlow, macdSignal)) // MACD 空头/多头增量减量判断 macdBullIncreasing = macdHist >= 0 and macdHist >= macdHist[1] macdBullDecreasing = macdHist >= 0 and macdHist <= macdHist[1] macdBearIncreasing = macdHist <= 0 and macdHist <= macdHist[1] macdBearDecreasing = macdHist <= 0 and macdHist >= macdHist[1] // WaveTrend 计算 wtMethod(l1, l2, ampl=0.5, offset=50) => esa = ta.ema(hlc3, l1) ci = (hlc3 - esa) / (0.015 * ta.ema(math.abs(hlc3 - esa), l1)) wt1 = ta.ema(ci, l2) * ampl + offset wt2 = ta.sma(wt1, 3) wtDelta = (wt1 - wt2) * (ampl * 8) + offset [wt1, wt2, wtDelta] // Stochastic RSI 计算 stochasticRsiMethod(rsi, rsiLength, smoothK, smoothD, offset=50) => k = ta.sma(ta.stoch(rsi, rsi, rsi, rsiLength), smoothK) d = ta.sma(k, smoothD) kdDelta = (k - d) + offset [k, d, kdDelta] // 计算指标 [wt1, wt2, wtDelta] = request.security(syminfo.tickerid, mtf, wtMethod(9, 12, 0.5, 50)) rsi_pca = request.security(syminfo.tickerid, mtf, ta.rsi(close, 14)) [k, d, kdDelta] = request.security(syminfo.tickerid, mtf, stochasticRsiMethod(rsi_pca, 14, 4, 4, 50)) // PCA 指标计算 f_pc1Indicator(weigthWT, weigthRSI, weigthStoch) => sumIndicators = wt1 * 0.28057677 * weigthWT + wt2 * 0.26604956 * weigthWT + wtDelta * 0.09335345 * weigthWT + rsi_pca * 0.27158859 * weigthRSI + k * 0.21072071 * weigthStoch + d * 0.20982997 * weigthStoch + kdDelta * 0.0288154 * weigthStoch nbIndicators = weigthWT * 3 + weigthRSI + weigthStoch * 3 sumIndicators / nbIndicators * 5.7 - 8 riskRatio = f_pc1Indicator(1.0, 1.0, 1.0) // === 背离检测(PCA) === priceHigh = ta.highest(high, lookbackPeriod) priceLow = ta.lowest(low, lookbackPeriod) adxHigh = ta.highest(adxValue, lookbackPeriod) adxLow = ta.lowest(adxValue, lookbackPeriod) pcaHigh = ta.highest(riskRatio[1], lookbackPeriod) pcaLow = ta.lowest(riskRatio[1], lookbackPeriod) pcaTopDivergence = high >= priceHigh and riskRatio <= pcaHigh and high == ta.highest(high, lookbackPeriod) pcaBottomDivergence = low <= priceLow and riskRatio >= pcaLow and low == ta.lowest(low, lookbackPeriod) // === PCA+ADX 复合背离检测(优化:添加MACD柱状图状态条件) === topStrength = (pcaHigh - riskRatio) + (adxHigh - adxValue) bottomStrength = (riskRatio - pcaLow) + (adxValue - adxLow) compositeTopRaw = high >= priceHigh and riskRatio <= pcaHigh and adxValue <= adxHigh compositeBottomRaw = low <= priceLow and riskRatio >= pcaLow and adxValue >= adxLow isStrongTop = topStrength >= minStrength isStrongBottom = bottomStrength >= minStrength macdBullTransition = macdBullIncreasing[1] and macdBullDecreasing macdBearTransition = macdBearIncreasing[1] and macdBearDecreasing compositeTop = compositeTopRaw and isStrongTop and not compositeTopRaw[1] and macdBullTransition compositeBottom = compositeBottomRaw and isStrongBottom and not compositeBottomRaw[1] and macdBearTransition // StochRSI 金叉/死叉 stochRsiCrossUp = ta.crossover(k, d) stochRsiCrossDown = ta.crossunder(k, d) // === PCA 买卖信号条件(添加阳线/阴线限制) === buySignal = riskRatio <= levelRiskSafe and (macdBearDecreasing or (macdBullDecreasing[1] and macdBullIncreasing)) and stochRsiCrossUp and isBullishCandle buySignalFinal = useValidFilter ? buySignal and isValid : buySignal sellSignal = riskRatio >= levelRiskDanger and (macdBullDecreasing or (macdBearDecreasing[1] and macdBearIncreasing)) and stochRsiCrossDown and isBearishCandle sellSignalFinal = useValidFilter ? sellSignal and isValid : sellSignal // === 绘制 PCA 买卖信号(K线图上,中文标签) === plotshape(series=buySignalFinal, title="买入信号", style=shape.labelup, location=location.belowbar, color=color.green, text="买", textcolor=color.white, size=size.tiny) plotshape(series=sellSignalFinal, title="卖出信号", style=shape.labeldown, location=location.abovebar, color=color.red, text="卖", textcolor=color.white, size=size.tiny) // === PCA+ADX 复合背离标签(仅显示 PCA+ADX) === if compositeTop label.new(bar_index, high, "PCA+ADX", style=label.style_label_down, color=color.new(#FFD700, 70), textcolor=color.white, size=size.small) if compositeBottom label.new(bar_index, low, "PCA+ADX", style=label.style_label_up, color=color.new(#00FFFF, 70), textcolor=color.white, size=size.small) // === MACD 背离参数 === macdFastDiv = input.int(12, title="MACD背离快速周期") macdSlowDiv = input.int(26, title="MACD背离慢速周期") macdSignalDiv = input.int(9, title="MACD背离信号线周期") // === MACD 背离计算 === [macdDiv, macdSDiv, macdHDiv] = ta.macd(close, macdFastDiv, macdSlowDiv, macdSignalDiv) // === MACD 背离检测函数 === // 看涨背离 bullishMACD() => price_nearest = 99999.9 macd_nearest = 0.0 macd_nearest_idx = 0 price_furthest = 99999.9 macd_furthest = 0.0 macd_furthest_idx = 0 if (macdHDiv[1] <= 0 and macdHDiv >= 0) or (macdHDiv[1] <= 0 and barstate.islast) i = 1 if barstate.islast i := 0 while macdHDiv[i] <= 0 price_nearest := math.min(low[i], price_nearest) macd_nearest := math.min(macdHDiv[i], macd_nearest) if macdHDiv[i] == macd_nearest macd_nearest_idx := i i += 1 while macdHDiv[i] >= 0 i += 1 while macdHDiv[i] <= 0 price_furthest := math.min(low[i], price_furthest) macd_furthest := math.min(macdHDiv[i], macd_furthest) if macdHDiv[i] == macd_furthest macd_furthest_idx := i i += 1 divergence = '无背离' if price_nearest >= price_furthest == false and macd_nearest >= macd_furthest == true divergence := '底背离' if price_nearest >= price_furthest == true and macd_nearest >= macd_furthest == false divergence := '隐藏底背离' [divergence, macd_nearest_idx, macd_furthest_idx] else ['无背离', 0, 0] // 看跌背离 bearishMACD() => price_nearest = 0.0 macd_nearest = 0.0 macd_nearest_idx = 0 price_furthest = 0.0 macd_furthest = 0.0 macd_furthest_idx = 0 if (macdHDiv[1] >= 0 and macdHDiv <= 0) or (macdHDiv[1] >= 0 and barstate.islast) i = 1 if barstate.islast i := 0 while macdHDiv[i] >= 0 price_nearest := math.max(high[i], price_nearest) macd_nearest := math.max(macdHDiv[i], macd_nearest) if macdHDiv[i] == macd_nearest macd_nearest_idx := i i += 1 while macdHDiv[i] <= 0 i += 1 while macdHDiv[i] >= 0 price_furthest := math.max(high[i], price_furthest) macd_furthest := math.max(macdHDiv[i], macd_furthest) if macdHDiv[i] == macd_furthest macd_furthest_idx := i i += 1 divergence = '无背离' if price_nearest >= price_furthest == true and macd_nearest >= macd_furthest == false divergence := '顶背离' if price_nearest >= price_furthest == false and macd_nearest >= macd_furthest == true divergence := '隐藏顶背离' [divergence, macd_nearest_idx, macd_furthest_idx] else ['无背离', 0, 0] // === 绘制MACD背离标记 === [a_divergence, a_idx_1, a_idx_2] = bullishMACD() if a_divergence == '底背离' label.new(bar_index[a_idx_1], low[a_idx_1], color=color.green, style=label.style_label_up, text="底背离", size=size.small) line.new(x1=bar_index[a_idx_1], y1=low[a_idx_1], x2=bar_index[a_idx_2], y2=low[a_idx_2], color=color.green, width=2) if a_divergence == '隐藏底背离' label.new(bar_index[a_idx_1], low[a_idx_1], color=color.green, style=label.style_label_up, text="隐藏底背离", size=size.small) line.new(x1=bar_index[a_idx_1], y1=low[a_idx_1], x2=bar_index[a_idx_2], y2=low[a_idx_2], color=color.green, width=2) [divergence, idx_1, idx_2] = bearishMACD() if divergence == '顶背离' label.new(bar_index[idx_1], high[idx_1], color=color.red, style=label.style_label_down, text="顶背离", size=size.small) line.new(x1=bar_index[idx_1], y1=high[idx_1], x2=bar_index[idx_2], y2=high[idx_2], color=color.red, width=2) if divergence == '隐藏顶背离' label.new(bar_index[idx_1], high[idx_1], color=color.red, style=label.style_label_down, text="隐藏顶背离", size=size.small) line.new(x1=bar_index[idx_1], y1=high[idx_1], x2=bar_index[idx_2], y2=high[idx_2], color=color.red, width=2) // === MTM 计算 === mtm = close - close[mtmLength] mtmMA = ta.sma(mtm, mtmMALength) mtmCrossUp = ta.crossover(mtm, mtmMA) mtmCrossDown = ta.crossunder(mtm, mtmMA) // === MACD 金叉/死叉计算 === macdCrossUp = ta.crossover(macdLine, signalLine) macdCrossDown = ta.crossunder(macdLine, signalLine) // === 持久化信号 === var string macdSignalText = na var string mtmSignal = na if macdCrossUp macdSignalText := "MACD金叉" else if macdCrossDown macdSignalText := "MACD死叉" if mtmCrossUp mtmSignal := "MTM金叉" else if mtmCrossDown mtmSignal := "MTM死叉" // === MTM & MACD 金叉/死叉显示(右边中间表格) === var table crossTable = table.new(position.middle_right, 1, 2, border_width=1) table.cell(crossTable, 0, 0, macdSignalText, bgcolor=macdSignalText == "MACD金叉" ? color.green : macdSignalText == "MACD死叉" ? color.red : color.gray, text_color=color.white) table.cell(crossTable, 0, 1, mtmSignal, bgcolor=mtmSignal == "MTM金叉" ? color.green : mtmSignal == "MTM死叉" ? color.red : color.gray, text_color=color.white) // === PCA-RAM 指标 === color c_gold = #ceb70b color c_white = color.white // 输入参数 window = input.int(50, "PCA窗口") fast_len = input.int(8, "快线平滑") slow_len = input.int(21, "慢线平滑") // 标准化数据 n_open = (open - ta.sma(open, window)) / ta.stdev(open, window) n_high = (high - ta.sma(high, window)) / ta.stdev(high, window) n_low = (low - ta.sma(low, window)) / ta.stdev(low, window) n_close = (close - ta.sma(close, window)) / ta.stdev(close, window) n_vol = (ta.obv - ta.sma(ta.obv, window)) / ta.stdev(ta.obv, window) // 近似主成分(简单加权平均) raw_proj = (n_open + n_high + n_low + n_close + n_vol) / 5 // 平滑快慢线 fast_line = ta.ema(raw_proj, fast_len) slow_line = ta.ema(raw_proj, slow_len) // 绘制三角符号 plotshape(ta.crossover(fast_line, slow_line), title="看多", style=shape.triangleup, location=location.belowbar, color=c_white, size=size.small, offset=-1) plotshape(ta.crossunder(fast_line, slow_line), title="看空", style=shape.triangledown, location=location.abovebar, color=c_gold, size=size.small, offset=-1) // 警报 if ta.crossover(fast_line, slow_line) alert("看多信号") if ta.crossunder(fast_line, slow_line) alert("看空信号") // === Moving Average Converging [LuxAlgo] === // 设置 length = input(100, title="Converging MA Length") incr = input(10, "Increment") fast = input(10, "Fast MA Period") src = input(close, "Source") // 计算 var ma = 0. var fma = 0. var alpha = 0. var k_lux = 1 / incr upper = ta.highest(length) lower = ta.lowest(length) init_ma = ta.sma(src, length) cross = ta.cross(src, ma) alpha := cross ? 2 / (length + 1) : src > ma and upper > upper[1] ? alpha + k_lux : src < ma and lower < lower[1] ? alpha + k_lux : alpha ma := nz(ma[1] + alpha[1] * (src - ma[1]), init_ma) fma := nz(cross ? math.avg(src, fma[1]) : src > ma ? math.max(src, fma[1]) + (src - fma[1]) / fast : math.min(src, fma[1]) + (src - fma[1]) / fast, src) // 绘制 css = fma > ma ? color.teal : color.red // plot(fma, "Fast MA", color=#ff5d00, linewidth=2) // 已注释此行以移除 Fast MA plot(ma, "Converging MA", color=css, linewidth=2) 这个是我现在的指标 我觉得还是有点乱 我需要测算过的准确性 需要你的帮助

视频信息