该策略是一个基于相对强弱指数(RSI)的动量策略,结合了手动设置止盈(TP)和止损(SL)的功能。策略的主要思路是通过RSI指标来捕捉市场的超买和超卖状态,同时考虑日线收盘价相对于近期最高价和最低价的位置,以此来判断进场时机。一旦达到预设的止盈或止损水平,策略就会自动平仓。
该策略提供了一个基于RSI动量指标的交易框架,同时引入了手动止盈止损的功能,使得交易者可以根据自己的风险偏好和市场观点来管理仓位。然而,策略的表现很大程度上依赖于参数的选择和市场状况。因此,交易者应当谨慎使用该策略,对其进行充分的回测和优化,并结合其他形式的分析和风险管理技术,以获得更稳健的交易表现。
//@version=5
strategy("RSI Strategy with Manual TP and SL", overlay=true)
// Strategy Parameters
length = input(14, title="RSI Length")
overSold = input(30, title="Oversold Level")
overBought = input(70, title="Overbought Level")
trail_profit_pct = input.float(20, title="Trailing Profit (%)")
// RSI Calculation
vrsi = ta.rsi(close, length)
// Entry Conditions for Long Position
rsi_crossed_below_30 = vrsi > overSold and ta.sma(vrsi, 2) <= overSold // RSI crossed above 30
daily_close_above_threshold = close > (ta.highest(close, 50) * 0.7) // Daily close above 70% of the highest close in the last 50 bars
// Entry Conditions for Short Position
rsi_crossed_above_70 = vrsi < overBought and ta.sma(vrsi, 2) >= overBought // RSI crossed below 70
daily_close_below_threshold = close < (ta.lowest(close, 50) * 1.3) // Daily close below 130% of the lowest close in the last 50 bars
// Entry Signals
if (rsi_crossed_below_30 and daily_close_above_threshold)
strategy.entry("RsiLE", strategy.long, comment="RsiLE")
if (rsi_crossed_above_70 and daily_close_below_threshold)
strategy.entry("RsiSE", strategy.short, comment="RsiSE")
// Manual Take Profit and Stop Loss
tp_percentage = input.float(1, title="Take Profit (%)")
sl_percentage = input.float(1, title="Stop Loss (%)")
long_tp = strategy.position_avg_price * (1 + tp_percentage / 100)
long_sl = strategy.position_avg_price * (1 - sl_percentage / 100)
short_tp = strategy.position_avg_price * (1 - tp_percentage / 100)
short_sl = strategy.position_avg_price * (1 + sl_percentage / 100)
strategy.exit("TP/SL Long", "RsiLE", limit=long_tp, stop=long_sl)
strategy.exit("TP/SL Short", "RsiSE", limit=short_tp, stop=short_sl)