
이것은 Bollinger Bands와 K-Line 형태를 동시에 입력 신호로 사용하는 트렌드 추적 전략이다. 그것은 더 긴 시간 동안 트렌드를 포착하기 위해 고안되었으며, 외환 거래에 적용된다.
전략은 가격의 표준 차이의 범위를 계산하여 볼린저 대역을 구축합니다. 대역폭은 시장의 변동성을 나타냅니다. 가격이 상반기 또는 하반기 경계에 접근 할 때 과매매 신호로 간주됩니다. 특정 K 선 모양과 결합하여 판정 입장합니다.
구체적으로, 다중 신호는: 낮은 지점이 위쪽으로 하향 궤도를 돌파하고, 다중 헤드 흡수 또는 아래 그림자 K 라인이 나타난다. 공허 신호는: 높은 지점 아래로 상향 궤도를 돌파하고, 공허 헤드 흡수 또는 상향 그림자 K 라인이 나타난다.
스톱 로드는 미리 설정된 스톱 가격에 적용된다. 스톱 로드는 브린 중선을 통과했을 때 부분적으로 스톱된다.
이 전략은 추세와 재입장 기회를 결합한다. 볼링거는 추세와 과매매 기회를 인식한다. K선은 재입장 시간을 판단하여 가짜 돌파구를 피한다.
스톱 스톱 손실 설정이 명확하고, 위험도 조절할 수 있다. 긴 라인 운영에 적합하며, 거래 빈도를 줄인다.
이 전략의 가장 큰 위험은 트렌드를 잡지 못하거나 큰 흔들림이 발생할 때입니다.
또한, 막대기는 중선에 의존하고, 너무 일찍 또는 너무 늦게 막대기가 발생할 수 있다.
변수 조합을 조정하여 최적화할 수 있고, 더 신뢰할 수 있는 K선 형태를 식별하거나, 오동률에 따라 막기 기준을 수정하여 개선할 수 있다.
다른 지표와 결합하여 대주기 트렌드를 판단하여 역동작전을 피하거나 기계학습 알고리즘을 추가하여 최적의 파라미터 조합을 판단할 수 있다.
스톱은 이동 스톱이나 변동율 스톱을 고려하여 수익을 극대화 할 수 있습니다.
이것은 볼린저 밴드 및 K선 기술 지표에 기반한 더 긴 주기의 트렌드 전략이다. 그것은 기본 전략으로 사용하기에 적합하며, 어느 정도의 신뢰성과 수익의 여지가 있지만, 안정성을 높이기 위해 계속 테스트 및 최적화가 필요합니다.
/*backtest
start: 2024-01-07 00:00:00
end: 2024-01-14 00:00:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("BB策略", overlay=true)
length = input(20, minval=1)
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=#198787, transp=95)
diff=upper-lower
//plot(upper*0.9985, "Upper", color=color.white, offset = offset)
//plot(lower*1.0015, "Lower", color=color.white, offset = offset)
//Engulfing Candles
openBarPrevious = open[1]
closeBarPrevious = close[1]
openBarCurrent = open
closeBarCurrent = close
//If current bar open is less than equal to the previous bar close AND current bar open is less than previous bar open AND current bar close is greater than previous bar open THEN True
bullishEngulfing = openBarCurrent <= closeBarPrevious and openBarCurrent < openBarPrevious and
closeBarCurrent > openBarPrevious
//If current bar open is greater than equal to previous bar close AND current bar open is greater than previous bar open AND current bar close is less than previous bar open THEN True
bearishEngulfing = openBarCurrent >= closeBarPrevious and openBarCurrent > openBarPrevious and
closeBarCurrent < openBarPrevious
//bullishEngulfing/bearishEngulfing return a value of 1 or 0; if 1 then plot on chart, if 0 then don't plot
//plotshape(bullishEngulfing, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)
//plotshape(bearishEngulfing, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
//alertcondition(bullishEngulfing, title="Bullish Engulfing", message="[CurrencyPair] [TimeFrame], Bullish candle engulfing previous candle")
//alertcondition(bearishEngulfing, title="Bearish Engulfing", message="[CurrencyPair] [TimeFrame], Bearish candle engulfing previous candle")
//Long Upper Shadow - Bearish
C_Len = 14 // ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body
C_BodyHi = max(close, open)
C_BodyLo = min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or (abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals
patternLabelPosLow = low - (atr(30) * 0.6)
patternLabelPosHigh = high + (atr(30) * 0.6)
C_LongUpperShadowBearishNumberOfCandles = 1
C_LongShadowPercent = 75.0
C_LongUpperShadowBearish = C_UpShadow > C_Range/100*C_LongShadowPercent
//alertcondition(C_LongUpperShadowBearish, title = "Long Upper Shadow", message = "New Long Upper Shadow - Bearish pattern detected.")
//if C_LongUpperShadowBearish
// var ttBearishLongUpperShadow = "Long Upper Shadow\nTo indicate buyer domination of the first part of a session, candlesticks will present with long upper shadows, as well as short lower shadows, consequently raising bidding prices."
// label.new(bar_index, patternLabelPosHigh, text="LUS", style=label.style_label_down, color = color.red, textcolor=color.white, tooltip = ttBearishLongUpperShadow)
//gcolor(highest(C_LongUpperShadowBearish?1:0, C_LongUpperShadowBearishNumberOfCandles)!=0 ? color.red : na, offset=-(C_LongUpperShadowBearishNumberOfCandles-1))
C_Len1 = 14 // ema depth for bodyAvg
C_ShadowPercent1 = 5.0 // size of shadows
C_ShadowEqualsPercent1 = 100.0
C_DojiBodyPercent1 = 5.0
C_Factor1 = 2.0 // shows the number of times the shadow dominates the candlestick body
C_BodyHi1 = max(close, open)
C_BodyLo1 = min(close, open)
C_Body1 = C_BodyHi1 - C_BodyLo1
C_BodyAvg1 = ema(C_Body1, C_Len1)
C_SmallBody1 = C_Body1 < C_BodyAvg1
C_LongBody1 = C_Body1 > C_BodyAvg1
C_UpShadow1 = high - C_BodyHi1
C_DnShadow1 = C_BodyLo1 - low
C_HasUpShadow1 = C_UpShadow1 > C_ShadowPercent1 / 100 * C_Body1
C_HasDnShadow1 = C_DnShadow1 > C_ShadowPercent1 / 100 * C_Body1
C_WhiteBody1 = open < close
C_BlackBody1 = open > close
C_Range1 = high-low
C_IsInsideBar1 = C_BodyHi1[1] > C_BodyHi1 and C_BodyLo1[1] < C_BodyLo1
C_BodyMiddle1 = C_Body1 / 2 + C_BodyLo1
C_ShadowEquals1 = C_UpShadow1 == C_DnShadow1 or (abs(C_UpShadow1 - C_DnShadow1) / C_DnShadow1 * 100) < C_ShadowEqualsPercent1 and (abs(C_DnShadow1 - C_UpShadow1) / C_UpShadow1 * 100) < C_ShadowEqualsPercent1
C_IsDojiBody1 = C_Range1 > 0 and C_Body1 <= C_Range1 * C_DojiBodyPercent1 / 100
C_Doji1 = C_IsDojiBody1 and C_ShadowEquals1
patternLabelPosLow1 = low - (atr(30) * 0.6)
patternLabelPosHigh1 = high + (atr(30) * 0.6)
C_LongLowerShadowBullishNumberOfCandles1 = 1
C_LongLowerShadowPercent1 = 75.0
C_LongLowerShadowBullish1 = C_DnShadow1 > C_Range1/100*C_LongLowerShadowPercent1
//alertcondition1(C_LongLowerShadowBullish1, title = "Long Lower Shadow", message = "New Long Lower Shadow - Bullish pattern detected.")
// Make input options that configure backtest date range
startDate = input(title="Start Date", type=input.integer,
defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer,
defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer,
defval=2018, minval=1800, maxval=2100)
endDate = input(title="End Date", type=input.integer,
defval=1, minval=1, maxval=31)
endMonth = input(title="End Month", type=input.integer,
defval=11, minval=1, maxval=12)
endYear = input(title="End Year", type=input.integer,
defval=2030, minval=1800, maxval=2100)
// Look if the close time of the current bar
// falls inside the date range
inDateRange = true
//多單
if ((bullishEngulfing or C_LongLowerShadowBullish1) and inDateRange and cross(low,lower))
strategy.entry("L", strategy.long, qty=1,stop=(low[1]))
//strategy.close("L",comment = "L exit",when=cross(basis,close),qty_percent=50)
if crossunder(close,upper*0.9985)
strategy.close("L",comment = "L exit",qty_percent=1)
//空單
if (((bullishEngulfing == 0) or C_LongUpperShadowBearish) and inDateRange and cross(close,upper))
strategy.entry("S", strategy.short,qty= 1,stop=(high[1]))
//strategy.close("S",comment = "S exit",when=cross(basis,close),qty_percent=50)
if crossunder(lower*1.0015,close)
strategy.close("S",comment = "S exit",qty_percent=1)