이중 이동 평균 볼링거 밴드 트렌드 전략에 따라

저자:차오장, 날짜: 2023-11-01 14:15:11
태그:

img

전반적인 설명

이 전략은 트렌드를 따르기 위해 이중 이동 평균 볼링거 밴드 (Bollinger Bands) 를 기반으로 거래 결정을 내립니다. 그것은 낮은 구매와 높은 판매를 달성하기 위해 낮은 레일 근처에서 구매하고 상위 레일 근처에서 판매하여 트렌드 변화를 결정하기 위해 볼링거 밴드의 상부 및 하부 레일의 컨버전스와 분리를 사용합니다.

전략 논리

이 전략은 단순한 볼링거 밴드와 향상된 볼링거 밴드 모두 적용됩니다.

간단한 볼링거 밴드는 중간 밴드에서 마감 가격의 SMA를 사용하지만 강화된 볼링거 밴드는 마감 가격의 EMA를 사용합니다.

상단 및 하단 대역은 중간 대역 ± N 표준편차로 계산된다.

이 전략은 상위 및 하위 대 사이의 스프레드를 기준으로 트렌드의 강도를 판단합니다. 스프레드가 한 임계치 이하로 떨어지면 트렌드를 따르는 트렌드 기간의 시작을 나타냅니다.

특히, 가격이 하위 대역에 접근할 때, 그것은 긴. 가격이 상위 대역에 접근 할 때, 그것은 위치를 닫습니다. 중지 손실 방법은 고정 비율입니다. 추적 중지 또한 활성화 될 수 있습니다.

이윤은 중위권이나 상위권에 가까운 매출에 달려 있습니다.

이 전략은 손실을 방지하기 위해 이윤으로만 판매하는 것도 선택할 수 있습니다.

이점 분석

이 전략의 장점:

  1. 이중 볼링거 대역은 효율성을 향상시킵니다.

단순하고 향상된 볼링거 밴드를 비교함으로써 더 높은 효율성을 위해 더 나은 버전을 선택할 수 있습니다.

  1. 스프레드는 트렌드 강도를 판단합니다.

스프레드가 좁아지면 강화 추세를 나타냅니다. 추세를 따라가면 더 높은 승률이 있습니다.

  1. 유연한 수익 취득 및 중단 손실

일정한 비율의 스톱 손실은 단일 거래 손실을 통제합니다. 중간에 또는 상단 근처에서 이익을 취합니다. 후속 스톱 손실은 더 많은 이익을 얻을 수 있습니다.

  1. 손실에 대한 보호 메커니즘

이윤으로 판매하는 것만이 손실이 커지는 것을 방지합니다.

위험 분석

위험은 다음과 같습니다.

  1. 적립 위험

트렌드를 따라가는 것은 마감 위험을 안고 있습니다.

  1. 윙사 위험

폭이 넓으면 시장이 옆으로 돌릴 수 있습니다. 전략은 덜 효과적입니다. 트렌드가 재개될 때까지 거래를 중단해야합니다.

  1. 적립된 적립된 적립된 적립된 적립된

일정한 비율의 스톱 손실은 너무 공격적이 될 수 있습니다. ATR 스톱처럼 더 온화한 스톱이 필요합니다.

최적화 방향

이 전략은 다음과 같이 최적화 할 수 있습니다.

  1. 볼링거 밴드 매개 변수

다른 MA 길이와 표준편차 곱을 테스트하여 다른 시장에 최적의 조합을 찾습니다.

  1. 필터를 추가합니다

MACD, KD와 같은 필터를 볼링거 신호 위에 추가하여 윙사 시장에서 거래를 줄이십시오.

  1. 수익 취득 및 스톱 손실

다른 트레일링 스톱 방법을 테스트하거나 변동성, ATR 등을 기반으로 스톱 손실을 최적화하십시오.

  1. 돈 관리

트레이드별로 포지션 사이즈를 최적화하고 다른 추가 전략을 테스트합니다.

결론

이 전략은 듀얼 볼링거 밴드의 강점을 결합하여, 밴드 너비와 트렌드 중에 거래 인기를 판단합니다. 또한 위험을 제어하기 위해 적절한 스톱 로스를 설정합니다. 매개 변수 최적화 및 필터를 추가함으로써 추가 개선이 가능합니다.


/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-31 00:00:00
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/
// © JCGMarkets 

//@version=4
strategy("B.Bands | Augmented | Intra-range | Long-Only", shorttitle = "BB|A|IR|L", initial_capital=5000, commission_value=0.075, slippage = 1, overlay = true)

//Technical Indicators Data
show_simp   = input(false, title="Trade on Simple Bollinger Bands ", type= input.bool, group="Select Strategy System")
show_augm   = input(true, title="Trade on Augmented Bollinger Bands", type= input.bool, group="Select Strategy System") 
periods     = input(20, title="Periods for Moving Average", type =input.integer, minval = 2, step = 1, group="Technical Inputs")
std         = input(2, title="Std", type = input.float, minval=0.1 , step = 0.1, group="Technical Inputs")

// Strategy data
max_spread_bb   = input(20000.0, title="Max Spread Tolerance Beetween Bands", type=input.float, step=0.1, group="Strategy Inputs")
entry_source    = input(close, title="Entry data source", type=input.source, group="Strategy Inputs")
exit_source     = input(high, title="Exit data source", type=input.source, group="Strategy Inputs")
take_profit     = input("middle", title = "Profit to band:", options = ["middle", "opposite"], group="Strategy Inputs")
stop_loss       = input(3.00, title="Stop Loss %", type=input.float, step=0.05, group="Strategy Inputs")
trailing        = input(false, title="Activate trailing stop?", type = input.bool, group="Strategy Inputs")
stop_perc       = input(6.00, title="Trailing %", type=input.float, step=0.125, group="Strategy Inputs") * 0.01
sell_profit     = input(false, title="Only sell in profit (Stop Loss still active) ", type= input.bool, group="Strategy Inputs")


var SL = 0.0
var SLT= 0.0


//Simple BB Calculation -> adapt if needed with different std for upper-lower, sma-ema, etc 
middle_sim = sma(close, periods)

//Augmented BB Calculation -> adapt if needed with different std for upper lower, etc
middle_augm  = ema(close, periods)
middle_upp = ema(high, periods)
middle_low = ema(low, periods)

//Multiplier
dev      = stdev(close, periods) * std

//Upper & Lower Bands
upper = (middle_sim + dev)
lower = (middle_sim - dev)

//Augmented Bands
upper_augm = (middle_upp + dev)
lower_augm = (middle_low - dev)

//Bands Spread
spread   = upper - lower
spread_augm   = upper_augm - lower_augm

//From date
filter_from    =   input(  true,    title="===> From", group="Date Control")
from_y         =   input(  2010,    title = "from year", group="Date Control")
from_m         =   input(     1,    title = "from month", minval =1, maxval=12, group="Date Control")
from_d         =   input(     1,    title = "from day",  minval=1, maxval=31, group="Date Control")

//To date
filter_to   =    input( true,   title="===> To", group="Date Control")
to_y        =    input( 2030,   title = "To year", group="Date Control")
to_m        =    input(    1,   title = "To month", minval =1, maxval=12, group="Date Control")
to_d        =    input(    1,  title = "To day",  minval=1, maxval=31, group="Date Control")

// Date Condition
In_date() =>  true

in_position = strategy.position_size > 0 

// Trailing stop 
SLT := if in_position and In_date()
    stop_inicial = entry_source * (1 - stop_perc)
    max(stop_inicial, SLT[1])
else
    0

slts = (low <= SLT) and (trailing == true)


//Essential Trade logics
entry_long = (entry_source <= lower) and (spread < max_spread_bb)
entry_long_augm = (entry_source <= lower_augm) and (spread_augm < max_spread_bb)

// Simple Bollinger Conditions

if (not in_position and show_simp and In_date())
    if entry_long
        // Trigger buy order
        position_size = round( strategy.equity / close ) // All available equity for this strategy example
        strategy.entry("Entry", strategy.long, qty = position_size )
        SL := close * (1 - (stop_loss / 100)) // You could determine wether or not implement stop loss with bool input and if condition here.


if in_position and show_simp and not sell_profit and In_date()
    //Exits if not sell in profit
    if take_profit == "middle" 
        strategy.exit("Target", "Entry", limit = middle_sim, stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry", limit = upper, stop = SL, comment="Exit")    

if in_position and show_simp and sell_profit and In_date()
    //Exits if sell in profit
    if take_profit == "middle" 
        strategy.exit("Target", "Entry", limit = (strategy.openprofit > 0 ? middle_sim: na), stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry", limit = (strategy.openprofit > 0 ? upper: na), stop = SL, comment="Exit")    



if in_position and show_simp and slts and In_date()
    //Trailing activation
    strategy.close("Entry", comment="SLT")

if not In_date()
    //Exit due out of date range
    strategy.close("Entry", comment="Out of date range")



// Augmented Bollinger Conditions

if (not in_position and show_augm and In_date()) 
    if entry_long_augm
        // Trigger buy order
        position_size = round( strategy.equity / close )
        strategy.entry("Entry_A", strategy.long, qty = position_size )
        SL := close * (1 - (stop_loss / 100) )

if in_position and show_augm and not sell_profit and In_date()
    //Exits and not sell in profit
    if take_profit == "middle"
        strategy.exit("Target", "Entry_A", limit = middle_augm, stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry_A", limit = upper_augm, stop = SL, comment="Exit")            
        

if in_position and show_augm and sell_profit and In_date() 
    //Exit only in profit
    if take_profit == "middle"
        strategy.exit("Target", "Entry_A", limit = (strategy.openprofit > 0 ? middle_augm:na), stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry_A", limit = (strategy.openprofit > 0 ? upper_augm: na) , stop = SL, comment="Exit") 


if in_position  and show_augm and slts and In_date()
    //Trigger trailing
    strategy.close("Entry_A", comment="SLT")
    
if not In_date()
    //Out of date trigger
    strategy.close("Entry_A", comment= "Out of date range")




// Plotting

plot(in_position ? SL > 0 ? SL : na : na , style = plot.style_circles, color = color.red, title = "Stop Loss")
plot(in_position ? trailing ? SLT > 0 ? SLT : na : na : na , style = plot.style_circles, color = color.blue, title = "Trailing Stop" )

s = plot(show_simp ? upper : na , color = color.aqua)
plot(show_simp ? middle_sim : na , color=color.red)
i = plot(show_simp ? lower : na , color = color.aqua)
fill(s,i, color=color.new(color.aqua,90))


plot(show_augm ? middle_augm : na , color=color.blue)
s_a = plot( show_augm ? upper_augm : na, color=color.orange)
i_a = plot( show_augm ? lower_augm : na, color= color.orange)
fill(s_a,i_a, color=color.new(color.orange, 90))

더 많은