
この戦略は,ブリン帯と比較的強い指標 ((RSI) を組み合わせて,買入シグナルを判断する.価格がブリン帯を突破して下線に下り,RSIが設定された下限を下回ったときに買入シグナルを生成する.価格がブリン帯を突破して上線に上線し,RSIが設定された上限を超えたときに売出シグナルを生成する.また,この戦略は,買い入りの間隔パラメータを導入し,頻繁に取引を避け,ピラミッド型のポジション管理を実現するのに役立ちます.
この戦略は,ブルイン帯とRSIの2つのクラシックな技術指標を巧妙に組み合わせて,二重確認メカニズムでトレンドの機会を捕捉します. 同時に,戦略は,リスクを制御しながら収益を最適化しようとするピラミッド型のポジション構築方法を導入します. しかし,戦略には,トレンド継続リスク,パラメータ最適化リスク,ブラック天候のリスクがあります.
/*backtest
start: 2024-02-01 00:00:00
end: 2024-02-29 23:59:59
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
strategy(overlay=true, shorttitle="cakes'Strategy For RSI", default_qty_type = strategy.percent_of_equity, initial_capital = 100000, default_qty_value = 100, pyramiding = 0, title="cakes'Strategy", currency = 'USD')
////////// ** Inputs ** //////////
// Stoploss and Profits Inputs
v1 = input(true, title="GoTradePlz")
////////// ** Indicators ** //////////
// RSI
len = 14
src = close
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)
// Bollinger Bands
length1 = 20
src1 = close
mult1 = 1.0
basis1 = sma(src1, length1)
dev1 = mult1 * stdev(src1, length1)
upper1 = basis1 + dev1
lower1 = basis1 - dev1
////////// ** Triggers and Guards ** //////////
// 输入
RSILowerLevel1 = input(30, title="RSI 下限水平")
RSIUpperLevel1 = input(70, title="RSI 上限水平")
// 购买间隔
buyInterval = input(5, title="购买间隔(K线数量)")
// 跟踪购买间隔
var int lastBuyBar = na
lastBuyBar := na(lastBuyBar[1]) ? bar_index : lastBuyBar
// 策略信号
BBBuyTrigger1 = close < lower1
BBSellTrigger1 = close > upper1
rsiBuyGuard1 = rsi < RSILowerLevel1
rsiSellGuard1 = rsi > RSIUpperLevel1
Buy_1 = BBBuyTrigger1 and rsiBuyGuard1 and (bar_index - lastBuyBar) >= buyInterval
Sell_1 = BBSellTrigger1 and rsiSellGuard1
if (Buy_1)
lastBuyBar := bar_index
strategy.entry("Long", strategy.long, when = Buy_1, alert_message = "Buy Signal!")
strategy.close("Long", when = Sell_1, alert_message = "Sell Signal!")