적응형 볼링거 밴드 트렌드 추적 전략

저자:차오장, 날짜: 2024-02-04 15:30:46
태그:

img

전반적인 설명

이 전략은 트렌드 방향을 식별하고 효율적인 트렌드 거래를 위해 스톱 로스로 트렌드를 추적하기 위해 시장 주문을 위해 적응적인 볼링거 밴드 지표를 사용합니다.

전략 논리

  1. 특정 기간을 기준으로 볼링거의 중간, 상위 및 하위 대역을 계산
  2. 가격이 상단역을 넘어서면 장거리, 하단역을 넘어서면 단기로 이동해 트렌드를 추적합니다.
  3. 빠른 진입을 위해 시장 주문을 사용
  4. 포지션 관리를 위해 스톱 로스를 설정하고 이윤을 취합니다.

장점

  1. 적응형 볼링거 대역은 트렌드 반전을 빠르게 판단하기 위해 시장 변동성에 민감합니다.
  2. 시장 주문은 미끄러짐 위험을 줄이는 빠른 진입을 보장합니다.
  3. 자동 스톱 로스 및 수익을 취합니다. 위험을 엄격히 통제하고 수익을 차단합니다.

위험성

  1. 볼링거 대역은 약간의 지연 성격을 가지고 있으며, 거짓 브레이크를 완전히 피할 수 없습니다.
  2. 시장 주문은 실행 가격을 정확하게 제어 할 수 없습니다.
  3. 스톱 로스 및 영업 수익 레벨을 적절히 설정하는 것이 필요합니다.

최적화 방향

  1. 트렌드를 판단하는 데 더 민감성을 위해 볼링거 매개 변수를 조정합니다.
  2. 가짜 브레이크오웃을 필터링하기 위해 볼륨이나 MACD와 같은 지표를 추가합니다.
  3. 스톱 로스를 최적화하고 이윤을 취합니다.

요약

이 전략은 트렌드 방향을 판단하는 데 볼링거 밴드 (Bollinger Bands) 의 이점을 최대한 활용하고 양쪽에서 트렌드 추적을 위해 빠른 출구 시장 주문을 결합하여 통제된 위험 하에서 과도한 수익을 얻습니다. 볼링거 매개 변수를 최적화하고 필터링 지표를 추가하고 스톱 로스 / 취리 로직을 조정하는 등의 추가 개선은 더 나은 전략 성능으로 이어질 수 있습니다. 명확한 논리와 쉬운 구현으로 효율적이고 신뢰할 수있는 트렌드 추적 거래 전략입니다.


/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 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/
// © CryptoRox

//@version=4
//Paste the line below in your alerts to run the built-in commands.
//{{strategy.order.alert_message}}
strategy("Automated - Fibs with Market orders", "Strategy", true)

//Settings 
testing = input(false, "Live")
//Use epochconverter or something similar to get the current timestamp.
starttime = input(1600976975, "Start Timestamp") * 1000
//Wait XX seconds from that timestamp before the strategy starts looking for an entry.
seconds = input(60, "Start Delay") * 1000
testPeriod = true


leverage = input(1, "Leverage")
tp = input(1.0, "Take Profit %") / leverage
dca = input(-1.0, "DCA when < %") / leverage *-1
fibEntry = input("1", "Entry Level", options=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"])

//Strategy Calls
equity = strategy.equity
avg = strategy.position_avg_price
symbol = syminfo.tickerid
openTrades = strategy.opentrades
closedTrades = strategy.closedtrades
size = strategy.position_size

//Fibs
lentt = input(60, "Pivot Length")
h = highest(lentt)
h1 = dev(h, lentt) ? na : h
hpivot = fixnan(h1)
l = lowest(lentt)
l1 = dev(l, lentt) ? na : l
lpivot = fixnan(l1)
z = 400
p_offset= 2
transp = 60
a=(lowest(z)+highest(z))/2
b=lowest(z)
c=highest(z)

fib0 = (((hpivot - lpivot)) + lpivot)
fib1 = (((hpivot - lpivot)*.21) + lpivot)
fib2 = (((hpivot - lpivot)*.3) + lpivot)
fib3 = (((hpivot - lpivot)*.5) + lpivot)
fib4 = (((hpivot - lpivot)*.62) + lpivot)
fib5 = (((hpivot - lpivot)*.7) + lpivot)
fib6 = (((hpivot - lpivot)* 1.00) + lpivot)
fib7 = (((hpivot - lpivot)* 1.27) + lpivot)
fib8 = (((hpivot - lpivot)* 2) + lpivot)
fib9 = (((hpivot - lpivot)* -.27) + lpivot)
fib10 = (((hpivot - lpivot)* -1) + lpivot)

notna = nz(fib10[60])
entry = 0.0
if fibEntry == "1"
    entry := fib10
if fibEntry == "2"
    entry := fib9
if fibEntry == "3"
    entry := fib0
if fibEntry == "4"
    entry := fib1
if fibEntry == "5"
    entry := fib2
if fibEntry == "6"
    entry := fib3
if fibEntry == "7"
    entry := fib4
if fibEntry == "8"
    entry := fib5
if fibEntry == "9"
    entry := fib6
if fibEntry == "10"
    entry := fib7
profit = avg+avg*(tp/100)
pause = 0
pause := nz(pause[1])
paused = time < pause

fill = 0.0
fill := nz(fill[1])
count = 0.0
count := nz(fill[1])

filled = count > 0 ? entry > fill-fill/100*dca : 0
signal = testPeriod and notna and not paused and not filled ? 1 : 0

neworder = crossover(signal, signal[1])
moveorder = entry != entry[1] and signal and not neworder ? true : false
cancelorder = crossunder(signal, signal[1]) and not paused
filledorder = crossunder(low[1], entry[1]) and signal[1]

last_profit = 0.0
last_profit := nz(last_profit[1])

// if neworder and signal
//     strategy.order("New", 1, 0.0001, alert_message='New Order|e=binancefuturestestnet s=btcusdt b=long q=0.0011 fp=' + tostring(entry)) 
// if moveorder
//     strategy.order("Move", 1, 0.0001, alert_message='Move Order|e=binancefuturestestnet s=btcusdt b=long c=order|e=binancefuturestestnet s=btcusdt b=long q=0.0011 fp=' + tostring(entry))
if filledorder and size < 1
    fill := entry
    count := count+1 
    pause := time + 60000
    p = close+close*(tp/100)
    strategy.entry("Buy", 1, 1,  alert_message='Long|e=binancefuturestestnet s=btcusdt b=long q=0.0011 t=market')
if filledorder and size >= 1
    fill := entry
    count := count+1 
    pause := time + 60000
    strategy.entry("Buy", 1, 1,  alert_message='Long|e=binancefuturestestnet s=btcusdt b=long q=0.0011 t=market')

// if cancelorder and not filledorder
//     pause := time + 60000
//     strategy.order("Cancel", 1, 0.0001,  alert_message='Cancel Order|e=binancefuturestestnet s=btcusdt b=long c=order')

if filledorder
    last_profit := profit

closeit = crossover(high, profit) and size >= 1
if closeit
    strategy.entry("Close ALL", 0, 0, alert_message='Close Long|e=binancefuturestestnet s=btcusdt b=long c=position t=market')
    count := 0
    fill := 0.0
    last_profit := 0.0
    
//Plots
// bottom = signal ? color.green : filled ? color.red : color.white
// plot(entry, "Entry", bottom)

더 많은