
この戦略はブリン帯 (Bollinger Bands) の指標に基づい,価格がブリン帯を突破して下線に進む方法によって取引信号を生成する.価格が上線を突破する時に多し,下線を突破する時に空にする.同時に,持てる時,価格が下線を突破すると平らになる.持てる時,価格が上線を突破すると平らになる.この戦略は,市場の波動性を捉え,価格の波動が加剧したときに,タイムリー取引を進めて,価格が逆転したときにタイムリー損失を止めておくことを目的としています.
BB均線突破戦略は,ブリン帯の指標に基づく取引戦略で,価格がブリン帯を突破して下落するチャンスを捕獲して取引する.この戦略の優点は,シグナルが明確で,実行しやすいことであり,ある種のリスク管理策があることである.しかし,この戦略には,取引頻度があまりにも高すぎること,シグナル遅滞などの問題がある.したがって,実際のアプリケーションでは,シグナル確認,ストップ損失最適化,パラメータ最適化などの側面から戦略の改善を考慮して,戦略の安定性と収益性を向上させることができる.
/*backtest
start: 2023-06-08 00:00:00
end: 2024-06-13 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("BB Strategy", overlay=true)
// Input parameters
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval=-500, maxval=500, title="Offset")
// Moving average function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculate Bollinger Bands
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Plot Bollinger Bands
plot(basis, "Basis", color=color.blue, offset=offset)
p1 = plot(upper, "Upper", color=color.red, offset=offset)
p2 = plot(lower, "Lower", color=color.green, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))
// Strategy logic
longCondition = ta.crossover(close, upper)
shortCondition = ta.crossunder(close, lower)
// Strategy entries and exits
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (shortCondition and strategy.position_size > 0)
strategy.close("Long")
if (longCondition and strategy.position_size < 0)
strategy.close("Short")