RSIダブルトラックオシレーターロングとショート双方向取引戦略


作成日: 2023-10-25 11:57:46 最終変更日: 2023-10-25 11:57:46
コピー: 1 クリック数: 627
1
フォロー
1617
フォロワー

RSIダブルトラックオシレーターロングとショート双方向取引戦略

概要

RSI二軌道の振動線長短二方向取引戦略は,RSI指標を利用して二方向取引を行う戦略である.この戦略は,RSI指標の超買超売原理を使用して,二軌道の設定と均線取引信号を組み合わせて,高効率の二方向の開場と平仓を実現する.

戦略原則

この戦略は,主にRSI指標の超買い超売り原理に基づいて取引決定を行う. この戦略は,まず,RSI指標の値vrsi,および双軌道の上軌道のsnと下軌道のlnを計算する. RSI値の下の軌道を通過するときに多信号が発生し,RSI値上の軌道を通過するときに空白信号が発生する.

策略はまた,K線の上昇変化を検知し,さらに多空信号を生成する.具体的には,K線が上下から突破するときに多空信号を生成するlongLocic,K線が上下から突破するときに多空信号を生成するshortLogic.さらに,策略は,多空のみ,空のみ,または反転のみのパラメータスイッチを提供する.

多数の空調信号が生成された後,戦略は信号の数を統計的に計算し,ポジションの開設数を制御する.パラメータによって異なる加仓ルールを設定できる.平仓条件は,ストップ,ストップ・ロス,移動ストップ・ロスなどの方法を含み,異なるストップ・ストップ・ロスパーセントを設定できる.

要するに,この戦略は,RSI指標,平均線交差,統計的加仓,ストップ・ストップ・損失などの複数の技術手段を総合的に使用して,自動の長短双方向取引を実現します.

戦略的優位性

  • RSIの超買い超売り原理を利用して,合理的な位置に多額の空調ポジションを確立する.
  • 双軌は誤信号を避けるように設定されている.上線は多頭ポジションを早急平衡させるため,下線は空頭ポジションを早急平衡させるためになっている.
  • 平均線取引信号フィルター 偽破れ ◎ 株価が平均線を破るだけで信号が生じ,偽信号を避ける ◎
  • 統計信号回数と加仓回数,リスク管理
  • カスタマイズ可能なストップ・ストップ・ロス・パーセンテージ,収益リスクはコントロールできます.
  • 移動ストップはストップを追跡し,さらに利益をロックします.
  • 市場環境によって,多量化,空白化,または反転信号のみが適用されます.
  • 自動取引システムにより,人手による操作コストが削減されます.

戦略リスク

  • RSI指標は反転失敗のリスクがある. RSIが超買い超売り領域に入ると必ずしも反転しない.
  • 固定ストップ・ストップ・ポイントは,套装されるリスクがある. ストップ・ストップ・損失の設定が不適切である場合,早すぎるストップ・損失またはストップ・損失を引き起こす可能性がある.
  • 技術指標に依存し,パラメータ最適化のリスクがある.指標パラメータの設定が不適切で,戦略の効果に影響する.
  • 複数の条件が同時に発生すると, 欠陥の危険性があります.
  • 自動取引システムには異常なエラーの危険性があります.

上記のリスクに対応して,パラメータ設定を最適化し,ストップ・ストップ・ロスの策略を調整し,流動性のフィルタリングを増やし,信号生成ロジックを最適化し,異常誤差モニタリングを増やすなどに改善することができる。

戦略最適化の方向性

  • RSI指標のパラメータを最適化するために,異なる周期パラメータをテストする.
  • 異なるストップ・ストップ・損失比率の設定をテストする.
  • 取引量や収益率を高め,流動性の不足を回避する.
  • 信号生成ロジックを最適化し,均線交差法を改善する.
  • 安定性を検証する複数の時間帯を追加します.
  • 信号の効果を最適化するために,他の指標を追加することを検討する.
  • ポジション管理戦略に参加する
  • 異常なエラーの監視を増やします.
  • 自動ストップトラッキングアルゴリズムの最適化
  • マシン・ラーニングの強化策を考慮する

要約する

RSI双軌振動線長短双方向取引戦略は,RSI指標,統計開場・止損原理など,複数の技術手段を総合的に適用することによって,自動化された双方向取引を実現する.この戦略は,強力なカスタマイズ性があり,ユーザーは,異なる市場環境に対応して,必要に応じてパラメータを調整することができます.同時に,戦略には,パラメータ設定,風力制御戦略,信号生成ロジックなどの最適化方面から最適化できる一定の改善の余地があり,戦略をより安定して信頼できます.全体的に言えば,この戦略は,ユーザーに比較的高効率の取引方案を提供します.

ストラテジーソースコード
/*backtest
start: 2023-09-24 00:00:00
end: 2023-10-24 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Learn more about Autoview and how you can automate strategies like this one here: https://autoview.with.pink/
// strategy("Autoview Build-a-bot - 5m chart", "Strategy", overlay=true, pyramiding=2000, default_qty_value=10000)
// study("Autoview Build-a-bot", "Alerts")

///////////////////////////////////////////////
//* Backtesting Period Selector | Component *//
///////////////////////////////////////////////

//* https://www.tradingview.com/script/eCC1cvxQ-Backtesting-Period-Selector-Component *//
//* https://www.tradingview.com/u/pbergden/ *//
//* Modifications made *//

testStartYear = input(1, "Backtest Start Year") 
testStartMonth = input(11, "Backtest Start Month")
testStartDay = input(10, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(77777777, "Backtest Stop Year")
testStopMonth = input(11, "Backtest Stop Month")
testStopDay = input(15, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() => true

/////////////////////////////////////
//* Put your strategy logic below *//
/////////////////////////////////////
RSIlength = input(1,title="RSI Period Length") 
price = close
vrsi = (rsi(price, RSIlength))
src = close
len = input(2, minval=1, title="Length")

up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

rsin = input(12)
sn = 100 - rsin
ln = 0 + rsin

// Put your long and short rules here
longLocic = crossunder(rsi, ln)
shortLogic = crossover(rsi, sn)

//////////////////////////
//* Strategy Component *//
//////////////////////////

isLong = input(true, "Longs Only")
isShort = input(false, "Shorts Only")
isFlip = input(false, "Flip the Opens")

long = longLocic
short = shortLogic

if isFlip
    long := shortLogic
    short := longLocic
else
    long := longLocic
    short := shortLogic

if isLong
    long := long
    short := na

if isShort
    long := na
    short := short
    
////////////////////////////////
//======[ Signal Count ]======//
////////////////////////////////

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if long
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if short
    sectionLongs := 0
    sectionShorts := sectionShorts + 1

//////////////////////////////
//======[ Pyramiding ]======//
//////////////////////////////

pyrl = input(2, "Pyramiding less than") // If your count is less than this number
pyre = input(1, "Pyramiding equal to") // If your count is equal to this number
pyrg = input(1000000, "Pyramiding greater than") // If your count is greater than this number

longCondition = long and sectionLongs <= pyrl or long and sectionLongs >= pyrg or long and sectionLongs == pyre ? 1 : 0 and vrsi < 20
shortCondition = short and sectionShorts <= pyrl or short and sectionShorts >= pyrg or short and sectionShorts == pyre ? 1 : 0

////////////////////////////////
//======[ Entry Prices ]======//
////////////////////////////////

last_open_longCondition = na
last_open_shortCondition = na
last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])

////////////////////////////////////
//======[ Open Order Count ]======//
////////////////////////////////////

sectionLongConditions = 0
sectionLongConditions := nz(sectionLongConditions[1])
sectionShortConditions = 0
sectionShortConditions := nz(sectionShortConditions[1])

if longCondition
    sectionLongConditions := sectionLongConditions + 1
    sectionShortConditions := 0

if shortCondition
    sectionLongConditions := 0
    sectionShortConditions := sectionShortConditions + 1
    
///////////////////////////////////////////////
//======[ Position Check (long/short) ]======//
///////////////////////////////////////////////

last_longCondition = na
last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])

in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition

/////////////////////////////////////
//======[ Position Averages ]======//
/////////////////////////////////////

totalLongs = 0.0
totalLongs := nz(totalLongs[1])
totalShorts = 0.0
totalShorts := nz(totalShorts[1])
averageLongs = 0.0
averageLongs := nz(averageLongs[1])
averageShorts = 0.0
averageShorts := nz(averageShorts[1]) 

if longCondition
    totalLongs := totalLongs + last_open_longCondition
    totalShorts := 0.0

if shortCondition
    totalLongs := 0.0
    totalShorts := totalShorts + last_open_shortCondition

averageLongs := totalLongs / sectionLongConditions
averageShorts := totalShorts / sectionShortConditions

/////////////////////////////////
//======[ Trailing Stop ]======//
/////////////////////////////////

isTS = input(false, "Trailing Stop")
tsi = input(100, "Activate Trailing Stop Price (%). Divided by 100 (1 = 0.01%)") / 100 
ts = input(100, "Trailing Stop (%). Divided by 100 (1 = 0.01%)") / 100

last_high = na
last_low = na
last_high_short = na
last_low_short = na
last_high := not in_longCondition ? na : in_longCondition and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_high_short := not in_shortCondition ? na : in_shortCondition and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_low := not in_shortCondition ? na : in_shortCondition and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])
last_low_short := not in_longCondition ? na : in_longCondition and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])

long_ts = isTS and not na(last_high) and low <= last_high - last_high / 100 * ts and longCondition == 0 and last_high >= averageLongs + averageLongs / 100 * tsi
short_ts = isTS and not na(last_low) and high >= last_low + last_low / 100 * ts and shortCondition == 0 and last_low <= averageShorts - averageShorts/ 100 * tsi

///////////////////////////////
//======[ Take Profit ]======//
///////////////////////////////

isTP = input(true, "Take Profit")
tp = input(125, "Take Profit (%). Divided by 100 (1 = 0.01%)") / 100
long_tp = isTP and close > averageLongs + averageLongs / 100 * tp and not longCondition
short_tp = isTP and close < averageShorts - averageShorts / 100 * tp and not shortCondition

/////////////////////////////
//======[ Stop Loss ]======//
/////////////////////////////

isSL = input(true, "Stop Loss")
sl = input(140, "Stop Loss (%). Divided by 100 (1 = 0.01%)") / 100
long_sl = isSL and close < averageLongs - averageLongs / 100 * sl and longCondition == 0
short_sl = isSL and close > averageShorts + averageShorts / 100 * sl and shortCondition == 0

/////////////////////////////////
//======[ Close Signals ]======//
/////////////////////////////////

longClose = long_tp or long_sl or long_ts ? 1 : 0
shortClose = short_tp or short_sl or short_ts ? 1: 0

///////////////////////////////
//======[ Plot Colors ]======//
///////////////////////////////

longCloseCol = na
shortCloseCol = na
longCloseCol := long_tp ? purple : long_sl ? maroon : long_ts ? blue : longCloseCol[1]
shortCloseCol := short_tp ? purple : short_sl ? maroon : short_ts ? blue : shortCloseCol[1]
tpColor = isTP and in_longCondition ? purple : isTP and in_shortCondition ? purple : white
slColor = isSL and in_longCondition ? red : isSL and in_shortCondition ? red : white

//////////////////////////////////
//======[ Strategy Plots ]======//
//////////////////////////////////

plot(isTS and in_longCondition ? averageLongs + averageLongs / 100 * tsi : na, "Long Trailing Activate", blue, style=3, linewidth=2)
plot(isTS and in_longCondition and last_high >= averageLongs +  averageLongs / 100 * tsi ? last_high - last_high / 100 * ts : na, "Long Trailing", fuchsia, style=2, linewidth=3)
plot(isTS and in_shortCondition ? averageShorts - averageShorts/ 100 * tsi : na, "Short Trailing Activate", blue, style=3, linewidth=2)
plot(isTS and in_shortCondition and last_low <= averageShorts - averageShorts/ 100 * tsi ? last_low + last_low / 100 * ts : na, "Short Trailing", fuchsia, style=2, linewidth=3)
plot(isTP and in_longCondition and last_high < averageLongs + averageLongs / 100 * tp ? averageLongs + averageLongs / 100 * tp : na, "Long TP", tpColor, style=3, linewidth=2)
plot(isTP and in_shortCondition and last_low > averageShorts - averageShorts / 100 * tp ? averageShorts - averageShorts / 100 * tp : na, "Short TP", tpColor, style=3, linewidth=2)
plot(isSL and in_longCondition and last_low_short > averageLongs - averageLongs / 100 * sl ? averageLongs - averageLongs / 100 * sl : na, "Long SL", slColor, style=3, linewidth=2)
plot(isSL and in_shortCondition and last_high_short < averageShorts + averageShorts / 100 * sl ? averageShorts + averageShorts / 100 * sl : na, "Short SL", slColor, style=3, linewidth=2)

///////////////////////////////
//======[ Alert Plots ]======//
///////////////////////////////

// plot(longCondition, "Long", green)
// plot(shortCondition, "Short", red)
// plot(longClose, "Long Close", longCloseCol)
// plot(shortClose, "Short Close", shortCloseCol)

///////////////////////////////////
//======[ Reset Variables ]======//
///////////////////////////////////

if longClose or not in_longCondition
    averageLongs := 0
    totalLongs := 0.0
    sectionLongs := 0
    sectionLongConditions := 0

if shortClose or not in_shortCondition
    averageShorts := 0
    totalShorts := 0.0
    sectionShorts := 0
    sectionShortConditions := 0

////////////////////////////////////////////
//======[ Strategy Entry and Exits ]======//
////////////////////////////////////////////

if testPeriod()
    strategy.entry("Long", 1, when=longCondition)
    strategy.entry("Short", 0,  when=shortCondition)
    strategy.close("Long", when=longClose)
    strategy.close("Short", when=shortClose)