You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script编码技巧:如何让RSI超卖策略仅在股价高于200MA时提交买单

Pine Script 交易策略实现代码(V5版本)

以下是完整可直接运行的代码,已内置200MA过滤逻辑,仅当价格高于200MA时RSI超卖信号才会触发买入:

//@version=5
strategy("RSI超卖+200MA过滤买入策略", overlay=true, initial_capital=10000, default_qty_value=1000, commission_type=strategy.commission.percent, commission_value=0.1)

// 参数设置(可根据自身需求调整)
rsi_period = input.int(14, title="RSI周期")
rsi_oversold_threshold = input.int(30, title="RSI超卖阈值")
ma_length = input.int(200, title="均线周期")
ma_type = input.string("SMA", title="均线类型", options=["SMA", "EMA"])

// 计算指标
ma200 = ma_type == "SMA" ? ta.sma(close, ma_length) : ta.ema(close, ma_length)
rsi_value = ta.rsi(close, rsi_period)

// 信号条件定义
// 价格高于200MA过滤条件
price_above_ma = close > ma200
// RSI从超卖区间向上突破信号(避免超卖区间重复触发,若需要只要在超卖区间就触发可改为 rsi_value < rsi_oversold_threshold)
rsi_buy_signal = ta.crossover(rsi_value, rsi_oversold_threshold)
// 合并条件:两个条件同时满足才触发买入
long_condition = price_above_ma and rsi_buy_signal

// 执行买入订单
if long_condition
    strategy.entry("多单入场", strategy.long)

// 可视化指标
plot(ma200, color=color.new(color.blue, 0), title="200MA", linewidth=2)
plot(rsi_value, "RSI", display=display.data_window, color=color.purple)
hline(rsi_oversold_threshold, "超卖线", display=display.data_window, color=color.red)

关键逻辑说明

  • 200MA过滤通过price_above_ma变量实现,不满足该条件时,即使RSI触发超卖信号也不会提交买入订单
  • 代码内置了参数调整面板,你可以直接在TradingView指标设置页修改周期、阈值、均线类型,不需要改代码
  • 如果需要用开盘价/最高价/最低价判断是否在均线上方,只需把price_above_ma = close > ma200中的close替换为open/high/low即可

内容的提问来源于stack exchange,提问作者nezas4444

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 21:57:01