브레이크아웃 변동성 밴드 거래 전략


생성 날짜: 2023-10-07 09:59:11 마지막으로 수정됨: 2023-10-07 09:59:11
복사: 0 클릭수: 658
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 브린띠의 돌파원칙에 기초하여, 가격이 완전히 경계를 넘어서거나 경계를 넘어서면 역행한다. 이 전략은 비정상적인 변동 이후의 회귀 평행선 운동을 포착할 수 있으며, 효율적인 수익을 추구하는 적극적인 거래자에게 적용된다.

원칙

이 전략은 브린띠를 이용하여 현재 시장의 변동 범위를 정의한다. 가격이 완전한 선줄기 또는 선줄기 기둥을 형성하고 브린띠를 완전히 뚫고 오르락 내리락 할 때, 시장이 높은 변동 상태에 도달하여 가격이 평행선 방향으로 돌아간다는 것을 의미한다.

구체적으로, 전략은 20 K 선의 종결 가격으로 부린띠의 중간 궤도, 상단 궤도 및 하단 궤도를 계산한다. 가격이 하단 궤도보다 낮고 종결 가격이 개시 가격보다 낮을 때, 더 많은 신호를 발생시킨다. 가격이 상단 궤도보다 높고 종결 가격이 개시 가격보다 높을 때, 빈 신호를 발생시킨다. 그 다음에는 돌파점을 중지 지점으로 사용하고, 중간 궤도는 첫 번째 목표 가격 평정지점으로 사용한다.

장점

이 전략의 주요 장점은 다음과 같습니다.

  1. 브린띠를 이용해 시장의 변동성을 판단하고, 비정상적인 상태를 효과적으로 식별한다.

  2. 브레이크 포인트는 스톱 로즈로써 위험을 효과적으로 통제할 수 있다.

  3. 중궤도로 돌아오는 것은 합리적인 목표 지점을 설정하여 지나치게 추격하여 추락하는 것을 피한다.

  4. 완전한 K선 필터링 가짜 돌파, 신호 품질을 향상 .

  5. 간단한 매개 변수 설정, 실행 및 최적화 용이함

  6. 논리적으로 명확하고, 코드는 간결하고, 우아합니다.

위험

이 전략에는 다음과 같은 위험도 있습니다.

  1. 부린 밴드 파라미터가 잘못되면 무효가 될 수 있습니다.

  2. 새로운 트렌드가 시작될 수 있는 돌파구가 될 수도 있고, 조기 퇴출의 위험이 있다.

  3. 중도 궤도 목표 지점은 너무 보수적이어서 지속적인 수익을 올릴 수 없습니다.

  4. 하지만, 이 지역은 아직 완전히 채워지지 않은 상태이며, 미끄러지는 위험이 있습니다.

  5. 이 트렌드에서 자주 불필요한 거래가 발생할 수 있습니다.

최적화 방향

이 전략은 다음과 같은 점들을 고려하여 최적화할 수 있습니다.

  1. 트렌드 강도를 평가하고, 매개 변수 또는 거래 빈도를 조정한다.

  2. 다른 지표와 함께 최적의 입학 시점을 결정한다.

  3. 변동의 정도에 따라 중지 손실을 조정하십시오.

  4. 첫 번째 목표 지점을 최적화하여 순조로운 수익을 창출하십시오.

  5. 재입학 제도에 가입하여 수익을 최적화하십시오.

  6. 신뢰성을 평가하고 잘못된 거래를 피하십시오.

요약하다

이 전략은 부린 띠 돌파 원칙에 기반하여, 단기 수익을 추구하는 적극적인 거래자에게 적합하다. 장점은 위험 통제가 명확하며, 단점은 조기 퇴출과 수익 공간이 제한되어 있다. 변수 최적화, 보조 지표 등의 방법으로 효과를 향상시킬 수 있다.

전략 소스 코드
/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 3h
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/
// © Bishnu103

//@version=4
strategy(title="Full Candle Outside BB [v1.0][Bishnu103]",shorttitle="OUTSIDE BB",overlay=true,calc_on_every_tick=true,backtest_fill_limits_assumption=2)

// ***********************************************************************************************************************
// input variables
buy_session         = input(title="Buy Session", type=input.session, defval="0915-1430")
exit_inraday        = input(title="Exit Intraday?", type=input.bool, defval=true)
entry_distance      = input(title="Entry distance from alert", minval=1, maxval=10, defval=3)
show_bb_switch      = input(title="Show BB", type=input.bool, defval=true)
//
bbLength            = input(title="BB Length", minval=1, defval=20)
bbStdDev            = input(title="BB StdDev", minval=1, defval=2)

// ***********************************************************************************************************************
// global variables
long_entry          = false
short_entry         = false
long_exit           = false
short_exit          = false

// variable values available across candles
var entry_price     = 0.0  
var sl_price        = 0.0
var exit_price      = 0.0
var candle_count    = 0

// ***********************************************************************************************************************
// function to return bollinger band values based on candle poition passed 
getBB(pos) => [mBB, uBB, lBB] = bb(close[pos], bbLength, bbStdDev)

// function returns true if current time is within intraday byuing session set in input
BarInSession(sess) => time(timeframe.period, sess) != 0

// ***********************************************************************************************************************
// strategy
//
// get current bb value
[mBB_0,uBB_0,lBB_0] = getBB(0)

// check if full candle outside upper BB
outside_uBB = low > uBB_0 and close <= open
outside_lBB = high < lBB_0 and close >= open

// ***********************************************************************************************************************
// entry conditions 
long_entry   := outside_lBB
short_entry  := outside_uBB

// keep candle count since the alert generated so that order can be cancelled after N number of candle calling it out as invalid alert
candle_count := candle_count + 1
if long_entry or short_entry
    candle_count    := 0

// ***********************************************************************************************************************
// risk management
//
// decide entry and sl price
if long_entry
    entry_price := high
    
if short_entry
    entry_price := low
    
if long_entry
    sl_price    := low
    
if short_entry
    sl_price    := high

// first exit is when price hits middle BB, gets updated for each candle based on it's middle BB value
exit_price  := mBB_0

// ***********************************************************************************************************************
// position sizing
price = if close[0] > 25000
    25000
else
    price = close[0]

qty = 25000/price

// ***********************************************************************************************************************
// entry
//if long_entry and strategy.position_size == 0
//    strategy.entry("BUY", strategy.long, qty, stop=entry_price, comment="BUY @ "+ tostring(entry_price)) 
if long_entry and strategy.position_size == 0
    strategy.order("BUY", strategy.long, qty, stop=entry_price, comment="BUY @ "+ tostring(entry_price))

//if short_entry and strategy.position_size == 0
//    strategy.entry("SELL", strategy.short, qty, stop=entry_price, comment="SELL @ "+ tostring(entry_price))
if short_entry and strategy.position_size == 0
    strategy.order("SELL", strategy.short, qty, stop=entry_price, comment="SELL @ "+ tostring(entry_price))

// cancel an order if N number of candles are completed after alert candle
strategy.cancel_all(candle_count > entry_distance)

// if current time is outside byuing session then do not enter intraday trade
strategy.cancel_all(timeframe.isintraday and not BarInSession(buy_session))

// ***********************************************************************************************************************
// exit
if strategy.position_size > 0
    strategy.cancel("EXIT at MBB", true)
    strategy.cancel("EXIT at SL", true)
    strategy.order("EXIT at MBB", strategy.short, abs(strategy.position_size), limit=exit_price, comment="EXIT TG @ "+ tostring(exit_price))
    strategy.order("EXIT at SL", strategy.short, abs(strategy.position_size), stop=sl_price, comment="EXIT SL @ "+ tostring(sl_price))

if strategy.position_size < 0
    strategy.cancel("EXIT at MBB", true)
    strategy.cancel("EXIT at SL", true)
    strategy.order("EXIT at MBB", strategy.long, abs(strategy.position_size), limit=exit_price, comment="EXIT TG @ "+ tostring(exit_price))
    strategy.order("EXIT at SL", strategy.long, abs(strategy.position_size), stop=sl_price, comment="EXIT SL @ "+ tostring(sl_price))

// if intraday trade, close the trade at open of 15:15 candle //!!!!!!!!!!!!!!!!!!!!! TO BE CORRECTED !!!!!!!!!!!!!!!!!!!!!!!
if timeframe.isintraday and exit_inraday and hour == 15 and minute == 00
    strategy.close("BUY",  when=strategy.position_size > 0, qty=strategy.position_size, comment="EXIT @ "+ tostring(close))
    strategy.close("SELL", when=strategy.position_size < 0, qty=strategy.position_size, comment="EXIT @ "+ tostring(close))

// ***********************************************************************************************************************
// plots    
//
// plot BB
[mBBp,uBBp,lBBp] = getBB(0)
p_mBB = plot(show_bb_switch ? mBBp : na, color=color.teal)
p_uBB = plot(show_bb_switch ? uBBp : na, color=color.teal)
p_lBB = plot(show_bb_switch ? lBBp : na, color=color.teal)
fill(p_uBB,p_lBB,color=color.teal,transp=95)