Strategies KB.ZH
Strategies

动态RSI震荡操作策略Dynamic-RSI-Oscillation-Trading-Strategy

ChaoZhang · PineScript · Mean Reversion · 2023-11-02 16:04:07

All strategies →

Overview

This strategy combines dynamic support/resistance levels and the relative strength index (RSI) indicator. It sets overbought/oversold thresholds for RSI and generates buy/sell signals when price breaks the dynamic support/resistance levels while RSI is not in the overbought/oversold area.

Advantages

  1. Use dynamic support/resistance to determine trend direction for higher winning rate.
  2. RSI filters out false breakouts and avoids false entries.
  3. Combining trend and indicator makes the strategy adaptable to different market conditions.
  4. Simple and clear rules make it easy to implement.

Risks

  1. Multiple tests of dynamic levels may generate false signals. Widen the breakout range to filter.
  2. Solo RSI may cause misjudgement. Add other indicators for combo filtering.
  3. Frequent trading in range-bound market leads to higher costs. Widen RSI's normal range to lower frequency.
  4. Improper parameter settings lead to missing or false signals. Optimize parameters based on different assets.

Optimization

  1. Use machine learning to auto optimize RSI parameters.
  2. Add stop loss/profit taking strategy to lock in profits and reduce losses.
  3. Incorporate more indicators for combo filtering to improve stability.
  4. Add volatility indicator to lower position size when volatility is low.
  5. Optimize position sizing algorithm to dynamically adjust positions for different market environments.

Summary

This strategy combines trend judgment and indicator filtering to effectively identify trend reversal around key levels while controlling risks. Further optimizations on parameter tuning, stop loss/profit taking, more indicators etc. can improve its stability and adaptability to generate steady profits in a wider range of markets. [/trans]

Other

Use the security function to get closing price as dynamic support/resistance levels. Trading signals are generated when price breaks through these dynamic levels. Calculate the average gain and average loss over a certain period to generate RSI values and determine if RSI reaches the overbought/oversold area. When price breaks the dynamic levels, if RSI is not in the overbought/oversold area, buy/sell signals are generated. Otherwise, the breakout signals are ignored. Close positions when price falls back to the dynamic level, or when RSI returns to normal range.

Parameters

ParametersDefaultDescription
v_input_1trueLong
v_input_2trueShort
v_input_3100Capital, %
v_input_4Wtimeframe 1
v_input_5_ohlc40Source: ohlc4
v_input_6trueantipila
v_input_7truecolor filter
v_input_87RSI Period
v_input_930RSI Limit
v_input_101900From Year
v_input_112100To Year
v_input_12trueFrom Month
v_input_1312To Month
v_input_14trueFrom day
v_input_1531To day
Source code (58 lines)
/*backtest
start: 2022-10-26 00:00:00
end: 2023-11-01 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=2
strategy(title = "Noro's Levels+RSI Strategy v1.0", shorttitle = "Levels+RSI str 1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 3)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
tf = input('W', title = "timeframe 1")
src = input(ohlc4, "Source")
ap = input(true, defval = true, title = "antipila")
cf = input(true, defval = true, title = "color filter")
rsiperiod = input(7, defval = 7, minval = 2, maxval = 100, title = "RSI Period")
rsilimit = input(30, defval = 30, minval = 1, maxval = 50, title = "RSI Limit")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//Level
level = request.security(syminfo.tickerid, tf, src[1])
plot(level, linewidth = 3, color = silver)

//RSI
uprsi = rma(max(change(close), 0), rsiperiod)
dnrsi = rma(-min(change(close), 0), rsiperiod)
rsi = dnrsi == 0 ? 100 : uprsi == 0 ? 0 : 100 - (100 / (1 + uprsi / dnrsi))

//Level Signals
ls = close > level and ap == false ? true : low > level ? true : false
up1 = strategy.position_size == 0 and ls and (close < open or cf == false)
exit1 = close < level and ap == false ? true : high < level ? true : false 

//RSI Signal

up2 = rsi < rsilimit and (close < open or cf == false)
exit2 = rsi > rsilimit and ls == false

//Trading
lot = strategy.position_size != strategy.position_size[1] ? strategy.equity / close * capital / 100 : lot[1]

if up1 or up2 
    strategy.entry("Long", strategy.long, needlong == false ? 0 : lot)
    
if  (exit1 and rsi > rsilimit) or exit2
    strategy.close_all()