この戦略は,RSI指標を使用して,超売り機会を識別し,価格が下がるときに入場し,平均値を継続して保持コストを削減することにより,長期的な利益を実現します.同時に,戦略は,DCA機構を組み込み,リスクをさらに制御します.
この戦略は,まず,市場が超売りであるかどうかを判断するためにRSIの指標を計算します. RSIが30を下回ると,超売り機会の出現を示します.
ポジション開設後,戦略は6つの平均値戻り価格を設定し,それぞれ現在の価格の98%,97%,95%,95%,84%および70%である.価格がこれらの価格に触れたときに,ポジションを追加し続けます.このように,継続的な平均値によって,ポジションのコストを削減できます.
さらに,戦略は,保有の平均価格を計算します. 価格が平均価格の5%を超えると,ストップを開始します. 同時に,価格が上昇し続け,平均価格の5%を超えるストップ価格を超えると,すべてストップします.
最後に,この戦略は,DCAのメカニズムも追加した.毎週月曜日,固定金額のポジションが,保有している場合,平均価格より低い価格で追加されます.これは,保有コストをさらに削減します.
この戦略の最大の利点は,平均値とDCAメカニズムを利用してリスクを制御することです.具体的には,以下のポイントが含まれています:
グループ入場戦略により,ポジションのリスクを分散させ,最下位を逃さないようにする.
複数の平均回帰価格を設定することで,ポジションのコストを継続的に削減し,下落のリスクを効果的に制御できます.
持株平均価格を計算し,利益の実現後にタイムリーストップし,利益をロックする.
DCAメカニズムの適用により,保有コストをさらに削減し,リスクを制御します.
RSI指標で市場のタイミングを判断し,高点開設を避ける.
平均線フィルターを使用し,反転を回避します.
この戦略にはいくつかのリスクがあります.
戦略は市場の逆転点を特定することができないので,長期にわたって低水準の市場に直面した場合,継続的に多額化すると損失が増加する.
ストップ・ローズ・メカニズムを考慮しない戦略は,単一の損失を効果的に制御することはできません.
市場が急激に下落すれば,ポジションは増え続けるだろう.
DCAの仕組みには時間的なリスクがあり,最低点でのポジション開設を保証することはできません.
対応方法:
RSIのみに頼らないように,他の指標と組み合わせて市場の構造を判断できます.
移動停止または縮小停止を増加させる
倉庫の開設層を制限し,過大なポジションを避ける.
DCAのポジション開設タイミングを最適化し,より安定した方法をとる.
この戦略は以下の点で最適化できます.
平均回帰アルゴリズムを最適化し,より科学的方法で価格回帰値を計算する.
停止の最適化方法は,移動停止または階段停止を採用することができる.
単一損失のコントロールを高めるため, Stop Loss 策を導入する.
市場構造を判断する他の指標と組み合わせて,RSIのみに依存することを避ける.
DCAのポジション開設ロジックを最適化し,固定時間でのポジション開設のリスクを回避する.
ポジション管理モジュールを追加し,ポジションのサイズを最適化します.
パラメータの設定を最適化し,戦略を市場の統計特性に適したものにします.
スイッチングロジック,異なる市場環境におけるスイッチング戦略.
この戦略は,全体として,RSI判断のタイミングを利用して,入場を分批して平均値にする長線投資戦略である.これは,現在の高波動の仮想通貨市場に適しており,震動区間を効果的に保有コスト管理のために利用することができる.同時に,戦略の仕組みは,最適化できる場所もある.より多くの技術指標判断とリスク管理モジュールを追加すれば,戦略の効果をさらに改善し,より複雑な市場環境に対応するのに十分なようにすることができる.
/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
// © A3Sh
// RSI Strategy that buys the dips, works with Price Averaging and has a Dollar Cost Average option.
// When the price drops below specified percentages of the price (6 PA layers), new entries are openend to average the price of the assets.
// Open entries are closed by a specified take profit.
// Entries can be reopened, after closing and consequently crossing a PA layer again.
// The idea is to lower the average position price to a point that when the market rises, the current price crosses over the average position price.
// When the current price crosses the average position size and reaches the specified take profit, all entries are closed at once.
// In case the market drops significantly, there is an option to activate DCA to lower the average price further.
// RSI code adapted from the Optimized RSI Buy the Dips strategy, by Coinrule
// https://www.tradingview.com/script/Pm1WAtyI-Optimized-RSI-Strategy-Buy-The-Dips-by-Coinrule/
// Pyramiding entries code adapted from Pyramiding Entries on Early Trends startegy, by Coinrule
// https://www.tradingview.com/script/7NNJ0sXB-Pyramiding-Entries-On-Early-Trends-by-Coinrule/
// Plot entry layers code adapted from HOWTO Plot Entry Price by vitvlkv
// https://www.tradingview.com/script/bHTnipgY-HOWTO-Plot-Entry-Price/
// Buy every week code based on the following question in Stack Overflow
// https://stackoverflow.com/questions/59870411/in-pine-script-how-can-you-do-something-once-per-day-or-keep-track-if-somethin
strategy(title = "RSI+PA+DCA", pyramiding = 16, overlay = true, initial_capital = 400, default_qty_type = strategy.percent_of_equity, default_qty_value = 15, commission_type = strategy.commission.percent, commission_value = 0.075)
port = input(15, title = "Portfolio %", type = input.float, step = 0.1, minval = 0.1, maxval = 100)
q = (strategy.equity / 100 * port) / open
// Long position entry layers. Percentage from the entry price of the the first long
PositionInputs = input("++++", title = "+++++ Long Positions VA Layers +++++")
ps2 = input(2, title = "2nd Long Entry %", step = 0.1)
ps3 = input(3, title = "3rd Long Entry %", step = 0.1)
ps4 = input(5, title = "4th Long Entry %", step = 0.1)
ps5 = input(10, title = "5th Long Entry %", step = 0.1)
ps6 = input(16, title = "6th Long Entry %", step = 0.1)
// Calculate Moving Averages
maInput = input("++++", title = "+++++ Moving Average Filter +++++")
plotMA = input(title = "Plot Moving Average", defval = false)
movingaverage_signal = sma(close, input(100))
plot (plotMA ? movingaverage_signal : na, color = color.white)
// RSI inputs and calculations
rsiInput = input( "++++", title = "+++++ RSI Inputs +++++" )
length = input( 14 )
overSold = input( 30, title = "oversold, entry trigger long position" )
overBought = input( 70, title = "overbought, has no specific function")
price = close
vrsi = rsi(price, length)
// Long trigger (co)
co = crossover(vrsi, overSold) and close < movingaverage_signal
// Take profit
takeprofit = input("++++", title = "+++++ Take Profit +++++")
ProfitTarget_Percent = input(5)
// Store values to create and plot the different DCA layers
long1 = valuewhen(co, close, 0)
long2 = valuewhen(co, close - (close / 100 * ps2), 0)
long3 = valuewhen(co, close - (close / 100 * ps3), 0)
long4 = valuewhen(co, close - (close / 100 * ps4), 0)
long5 = valuewhen(co, close - (close / 100 * ps5), 0)
long6 = valuewhen(co, close - (close / 100 * ps6), 0)
eps1 = 0.00
eps1 := na(eps1[1]) ? na : eps1[1]
eps2 = 0.00
eps2 := na(eps2[1]) ? na : eps2[1]
eps3 = 0.00
eps3 := na(eps3[1]) ? na : eps3[1]
eps4 = 0.00
eps4 := na(eps4[1]) ? na : eps4[1]
eps5 = 0.00
eps5 := na(eps5[1]) ? na : eps5[1]
eps6 = 0.00
eps6 := na(eps6[1]) ? na : eps6[1]
plot (strategy.position_size > 0 ? eps1 : na, title = "Long entry 1", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps2 : na, title = "Long entry 2", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps3 : na, title = "Long entry 3", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps4 : na, title = "Long entry 4", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps5 : na, title = "Long entry 5", style = plot.style_linebr)
plot (strategy.position_size > 0 ? eps6 : na, title = "Long entry 6", style = plot.style_linebr)
// Plot position average price
plot (strategy.position_avg_price, title = "Average price", style = plot.style_linebr, color = color.red, linewidth = 2)
// Take profit and exit all on take profit above position average price
tpv = strategy.position_avg_price + (strategy.position_avg_price / 100 * ProfitTarget_Percent)
tpl1 = close < tpv ? eps1 + close * (ProfitTarget_Percent / 100) : tpv
tpl2 = close < tpv ? eps2 + close * (ProfitTarget_Percent / 100) : tpv
tpl3 = close < tpv ? eps3 + close * (ProfitTarget_Percent / 100) : tpv
tpl4 = close < tpv ? eps4 + close * (ProfitTarget_Percent / 100) : tpv
tpl5 = close < tpv ? eps5 + close * (ProfitTarget_Percent / 100) : tpv
tpl6 = close < tpv ? eps6 + close * (ProfitTarget_Percent / 100) : tpv
// Open DCA order once at the start of the week
dcaWeek = input("++++", title = "+++++ Open DCA order once every week +++++")
newWeek = change(time("W"))
dcatime = input(title = "Buy a fixed amount every Monday", defval = false)
fixedAmount = input(40, title = "Fixed amount currency for DCA orders", step = 0.1)
dcaq = fixedAmount / open
plotchar (dcatime ? newWeek : na, "buy at Week start", "▼", location.top, size = size.tiny, color = color.white)
bgcolor (dcatime and newWeek ? color.white : na, transp = 50)
// Submit entry orders
if (co and strategy.opentrades == 0)
eps1 := long1
eps2 := long2
eps3 := long3
eps4 := long4
eps5 := long5
eps6 := long6
strategy.entry("Long1", strategy.long, q)
if (strategy.opentrades == 1)
strategy.entry("Long2", strategy.long, q, limit = eps2)
if (strategy.opentrades == 2)
strategy.entry("Long3", strategy.long, q, limit = eps3)
if (strategy.opentrades == 3)
strategy.entry("Long4", strategy.long, q, limit = eps4)
if (strategy.opentrades == 4)
strategy.entry("Long5", strategy.long, q, limit = eps5)
if (strategy.opentrades == 5)
strategy.entry("Long6", strategy.long, q, limit = eps6)
// Submit Weekly DCA order, only when price is below position average price and when a position is open
if (dcatime and newWeek and strategy.position_size > 0 and close < strategy.position_avg_price)
strategy.entry("DCA", strategy.long, dcaq)
// Exit orders
if (strategy.position_size > 0)
strategy.exit(id = "Exit 1", from_entry = "Long1", limit = tpl1)
strategy.exit(id = "Exit 2", from_entry = "Long2", limit = tpl2)
strategy.exit(id = "Exit 3", from_entry = "Long3", limit = tpl3)
strategy.exit(id = "Exit 4", from_entry = "Long4", limit = tpl4)
strategy.exit(id = "Exit 5", from_entry = "Long5", limit = tpl5)
strategy.exit(id = "Exit 6", from_entry = "Long6", limit = tpl6)
strategy.exit(id = "Exit DCA", from_entry = "DCA", limit = tpv)
// Make sure that all open limit orders are canceled after exiting all the positions
longClose = strategy.position_size[1] > 0 and strategy.position_size == 0 ? 1 : 0
if longClose
strategy.cancel_all()