
이 전략은 부린 밴드 (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")