RSI-VWAP 加密货币交易机器人(免费)– TradingView 脚本
最初,这是一个较为简单的策略,它使用 RSI(相对强弱指标),但与传统 RSI 不同的是,该策略将 VWAP(成交量加权平均价格) 作为 RSI 的计算数据源,而不是使用收盘价。
您可以在此查看原始策略代码:
RSI-VWAP
重要提示!
这是一个趋势跟踪策略(Trend Strategy),在趋势行情中表现最佳。
策略新增了基于 EMA(指数移动平均线) 与 SMA(简单移动平均线) 相互关系的趋势识别机制。
已加入 止盈(Take Profit) 和 止损(Stop Loss) 设置。
新增回测周期输入参数,允许您按月评估策略表现。
参数设置
Input | Value |
Period | 14 |
RSI-VWAP LENGTH LONG | 15 |
RSI-VWAP OVERSOLD LONG | 15 |
RSI-VWAP OVERBOUGHT LONG | 72 |
RSI-VWAP LENGTH SHORT | 14 |
RSI-VWAP OVERSOLD SHORT | 8 |
RSI-VWAP OVERBOUGHT SHORT | 72 |
Long Take Profit (%) | NA (100) |
Long Stop Loss (%) | 3.3 |
Trailing Stop Long | NA (100) |
Short Take Profit (%) | NA (100) |
Short Stop Loss (%) | 4 |
Trailing Stop Short | NA (100) |
修订版策略脚本代码
您可以复制以下代码并粘贴到 TradingView 中使用。
// © WunderTrading
//@version=5
strategy('RSI-VWAP INDICATOR', overlay=false, initial_capital=1000, currency='USD', pyramiding=3, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
/// TREND
ribbon_period = input.int(14, 'Period', step=1)
leadLine1 = ta.ema(close, ribbon_period)
leadLine2 = ta.sma(close, ribbon_period)
p1 = plot(leadLine1, color=color.new(#53b987, 50), title='EMA', linewidth=1)
p2 = plot(leadLine2, color=color.new(#eb4d5c, 50), title='SMA', linewidth=1)
fill(p1, p2, color=leadLine1 > leadLine2 ? #53b987 : #eb4d5c, transp=60)
// Initial inputs
Act_RSI_VWAP_long = input(true, 'RSI VOLUME WEIGHTED AVERAGE PRICE LONG')
RSI_VWAP_length_long = input(15, 'RSI-VWAP LENGTH LONG')
RSI_VWAP_overSold_long = input.float(15, 'RSI-VWAP OVERSOLD LONG')
RSI_VWAP_overBought_long = input.float(72, 'RSI-VWAP OVERBOUGHT LONG')
Act_RSI_VWAP_short = input(true, 'RSI VOLUME WEIGHTED AVERAGE PRICE SHORT')
RSI_VWAP_length_short = input(14, 'RSI-VWAP LENGTH SHORT')
RSI_VWAP_overSold_short = input.float(8, 'RSI-VWAP OVERSOLD SHORT')
RSI_VWAP_overBought_short = input.float(72, 'RSI-VWAP OVERBOUGHT SHORT')
// RSI with VWAP as source
RSI_VWAP_long = ta.rsi(ta.vwap(close), RSI_VWAP_length_long)
RSI_VWAP_short = ta.rsi(ta.vwap(close), RSI_VWAP_length_short)
// Plot Them Separately.
//Plotting LONG, Put overlay=false
r_long = plot(RSI_VWAP_long, color=RSI_VWAP_long > RSI_VWAP_overBought_long ? color.red : RSI_VWAP_long < RSI_VWAP_overSold_long ? color.lime : color.blue, title='rsi', linewidth=2, style=plot.style_line)
h1_long = plot(RSI_VWAP_overBought_long, color=color.new(color.gray, 0), style=plot.style_stepline)
h2_long = plot(RSI_VWAP_overSold_long, color=color.new(color.gray, 0), style=plot.style_stepline)
fill(r_long, h1_long, color=RSI_VWAP_long > RSI_VWAP_overBought_long ? color.red : na, transp=60)
fill(r_long, h2_long, color=RSI_VWAP_long < RSI_VWAP_overSold_long ? color.lime : na, transp=60)
// Plotting SHORT, Put overlay=false
r_short = plot(RSI_VWAP_short, color=RSI_VWAP_short > RSI_VWAP_overBought_short ? color.red : RSI_VWAP_short < RSI_VWAP_overSold_short ? color.lime : color.blue, title='rsi', linewidth=2, style=plot.style_line)
h1_short = plot(RSI_VWAP_overBought_short, color=color.new(color.gray, 0), style=plot.style_stepline)
h2_short = plot(RSI_VWAP_overSold_short, color=color.new(color.gray, 0), style=plot.style_stepline)
fill(r_short, h1_short, color=RSI_VWAP_short > RSI_VWAP_overBought_short ? color.red : na, transp=60)
fill(r_short, h2_short, color=RSI_VWAP_short < RSI_VWAP_overSold_short ? color.lime : na, transp=60)
/////// STRATEGY Take Profit / Stop Loss ////////
////// LONG //////
long_tp_inp = input.float(100, title='Long Take Profit %', step=0.1) / 100
long_sl_inp = input.float(3.3, title='Long Stop Loss %', step=0.1) / 100
long_trailing = input.float(100, title='Trailing Stop Long', step=0.1) / 100
long_take_level = strategy.position_avg_price * (1 + long_tp_inp)
long_stop_level = strategy.position_avg_price * (1 - long_sl_inp)
////// SHORT //////
short_tp_inp = input.float(100, title='Short Take Profit %', step=0.1) / 100
short_sl_inp = input.float(4, title='Short Stop Loss %', step=0.1) / 100
short_trailing = input.float(100, title='Trailing Stop short', step=0.1) / 100
short_take_level = strategy.position_avg_price * (1 - short_tp_inp)
short_stop_level = strategy.position_avg_price * (1 + short_sl_inp)
///Strategy_Conditions
/// LONG ///
entry_long = ta.crossover(RSI_VWAP_long, RSI_VWAP_overSold_long) and leadLine2 < leadLine1
entry_price_long = ta.valuewhen(entry_long, close, 0)
exit_long = ta.crossunder(RSI_VWAP_long, RSI_VWAP_overBought_long)
/// SHORT ///
entry_short = ta.crossunder(RSI_VWAP_short, RSI_VWAP_overBought_short) and leadLine2 > leadLine1
entry_price_short = ta.valuewhen(entry_short, close, 0)
exit_short = ta.crossover(RSI_VWAP_short, RSI_VWAP_overSold_short)
////// BACKTEST PERIOD ///////
testStartYear = input(2019, 'Backtest Start Year')
testStartMonth = input(1, 'Backtest Start Month')
testStartDay = input(1, 'Backtest Start Day')
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)
testStopYear = input(9999, 'Backtest Stop Year')
testStopMonth = input(12, 'Backtest Stop Month')
testStopDay = input(31, 'Backtest Stop Day')
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
testPeriod() =>
time >= testPeriodStart and time <= testPeriodStop ? true : false
if testPeriod()
if strategy.position_size == 0 or strategy.position_size > 0
strategy.entry('long', strategy.long, when=entry_long, comment='*** INSERT OPEN LONG COMMENT FROM WBT ***')
strategy.exit('long', stop=long_stop_level, limit=long_take_level, trail_points=entry_price_long * long_trailing / syminfo.mintick, trail_offset=entry_price_long * long_trailing / syminfo.mintick, comment='*** INSERT CLOSE LONG COMMENT FROM WBT ***')
strategy.close('long', when=exit_long, comment='*** INSERT CLOSE LONG COMMENT FROM WBT ***')
if strategy.position_size == 0 or strategy.position_size < 0
strategy.entry('short', strategy.short, when=entry_short, comment='*** INSERT OPEN SHORT COMMENT FROM WBT ***')
strategy.exit('TP/SL/TRS_short', 'short', stop=short_stop_level, limit=short_take_level, trail_points=entry_price_short * short_trailing / syminfo.mintick, trail_offset=entry_price_short * short_trailing / syminfo.mintick, comment='*** INSERT CLOSE SHORT COMMENT FROM WBT ***')
strategy.close('short', when=exit_short, comment='*** INSERT CLOSE SHORT COMMENT FROM WBT ***')

