INVITE-ONLY SCRIPT

趋势Scalping(多时间框架动能策略)

39
策略概述
本策略是一个基于多时间框架动能的短线交易策略,通过结合短期与长期趋势指标、RSI超买超卖判断以及时间过滤机制,在趋势明确时入场,并在特定条件或时间点退出交易。策略适用于股票、期货、加密货币等高频波动的市场。

输入参数说明
数据源(Source)
默认使用 hl2(最高最低价的平均值),也可选择其他价格数据。

短期趋势周期(Short Term Trend)
默认值为5,用于计算短期RSI,捕捉近期价格动量的变化。

长期趋势周期(Long Term Trend)
默认值为60,用于计算随机指标(Stochastic)的周期,判断中长期趋势方向。

长期趋势平滑周期(Smooth Long Term Trend)
默认值为13,对长期随机指标进行平滑处理,减少噪音。

近期回调检测周期(Clear Short Term Pullback Appears Recently)
默认值为15,用于检测短期是否出现明显回调。

RSI超卖阈值(Threshold of Short Term Pullback Clear)
默认值为35.0,RSI低于该值视为短期超卖,可能出现反弹。

RSI回调结束阈值(Threshold of Short Term Pullback End)
默认值为50.0,RSI回升至此表示短期回调结束。

条件失效时退出(Exit if Reason Over)
若启用,当入场条件不再成立时自动平仓。

交易时间范围
可设置策略运行的开始与结束时间(以小时和分钟为单位),仅在指定时间段内交易。

策略逻辑
指标计算:
随机指标(Stochastic):基于长期周期计算,反映价格在近期区间内的位置。

平滑随机值(y_k):对随机指标进行移动平均平滑处理。

RSI指标:基于短期周期计算,反映近期价格动量的强弱。

多空判断:
多头信号(y_upper):
当平滑随机值高于50、RSI高于结束阈值,且近期出现明显超卖回调时,触发做多信号。

空头信号(y_lower):
当平滑随机值低于50、RSI低于结束阈值,且近期出现明显超买回调时,触发做空信号。

时间过滤:
策略仅在用户设定的时间范围内(例如7:00至15:10)运行,避免在波动性较低或非主力交易时段操作。

强制平仓机制:
每天下午16:10(或指定时间区间)强制平仓所有头寸,避免隔夜风险或尾盘波动。

图表显示
策略在副图中绘制以下三条线:

随机指标(红色)

平滑随机值(蓝色)

RSI指标(黄色)

水平线50:作为多空分界线参考。

使用建议
本策略适合在流动性高、波动性强的市场中运行。

建议配合止损机制使用,以控制单笔交易风险。

用户可根据不同品种调整参数周期和阈值,优化入场时机。

Strategy Overview
This is a short-term trading strategy designed to capitalize on momentum shifts within a broader trend. It combines multiple technical indicators across different timeframes—including Stochastic, RSI, and custom trend logic—to generate entry and exit signals. The strategy incorporates a time filter to operate only during specified high-liquidity hours and includes a mandatory end-of-session close-out to avoid overnight risk. It is suitable for volatile markets like equities, futures, and cryptocurrencies.

Input Parameters
Source
The price data used for calculations. Default is hl2 (the average of high and low prices).

Short Term Trend (x_len_a)
The period for the short-term RSI calculation. Default is 5. Used to capture recent price momentum.

Long Term Trend (x_len_b)
The period for the Stochastic Oscillator calculation. Default is 60. Defines the medium-to-long-term trend context.

Smooth Long Term Trend (x_k_b)
The smoothing period applied to the Stochastic value (K). Default is 13. Reduces noise for a clearer trend signal.

Clear Short Term Pullback Appears Recently (x_changk)
The lookback period to identify a recent significant pullback. Default is 15.

Threshold of Short Term Pullback Clear (x_rsi_ct)
The RSI level indicating an oversold (for longs) or overbought (for shorts) condition. Default is 35.0.

Threshold of Short Term Pullback End (x_rsi_ft)
The RSI level signaling that the short-term pullback has concluded and momentum is reversing. Default is 50.0.

Exit if Reason Over (x_exit_if_reason_over)
A boolean switch. If enabled, the strategy will automatically close a position if the original entry condition is no longer valid.

Time Filter (Start/End Hour & Minute)
Defines the specific intraday window during which the strategy is active (e.g., 7:00 to 15:10). All trades are initiated and managed only within this window.

Strategy Logic
Indicator Calculation:
y_stoch: The raw Stochastic Oscillator value calculated over the x_len_b period.

y_k: A smoothed version of the Stochastic (y_stoch) using a Simple Moving Average with period x_k_b.

y_rsi: The Relative Strength Index calculated on the Source price over the short-term period x_len_a.

Entry & Exit Conditions:
The core logic generates a composite signal (y_upper for long, y_lower for short) based on three components:

The deviation of the smoothed Stochastic (y_k) from its midpoint (50).

The deviation of the RSI (y_rsi) from its pullback-end threshold (x_rsi_ft).

The extremity of the recent RSI move compared to the pullback-clear threshold (x_rsi_ct) over the x_changk period.

Long Entry (LE): Triggered when the composite signal y_upper is greater than 0 AND the current time is within the allowed trading window.

Short Entry (SE): Triggered when the composite signal y_lower is less than 0 AND the current time is within the allowed trading window.

Conditional Exit: If x_exit_if_reason_over is true, long positions are closed if y_upper <= 0, and short positions are closed if y_lower >= 0.

Time-Based Filter:
The strategy only evaluates entries and exits if the current bar's time falls within the user-defined start_time and end_time range.

Mandatory Close-Out:
A critical risk management feature: All open positions are automatically closed at 16:10 (4:10 PM) based on the chart's timezone, ensuring no positions are held overnight or into the late session.

Plotting
The strategy plots three key series in the indicator pane:

Stochastic (y_stoch): Red line.

Smoothed Stochastic (y_k): Blue line.

RSI (y_rsi): Yellow line.

A hline at 50 serves as a visual midpoint reference for both Stochastic and RSI.

Usage Recommendations
This strategy performs best in markets with high volatility and strong trending characteristics.

It is highly recommended to use this script with a brokerage account that supports and enforces stop-loss orders on the strategy's behalf, as the script itself does not calculate stop-loss levels.

Parameters, especially periods and thresholds, should be optimized for the specific asset and timeframe being traded.

Always conduct rigorous backtesting and forward testing before deploying capital.

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。