비트코인의 슈퍼트렌드 양적 거래 전략

저자:차오장, 날짜: 2024-02-06 12:09:09
태그:

img

전반적인 설명

이것은 슈퍼트렌드 지표에 기반한 비트코인의 자동화된 양적 거래 전략이다. 시장 트렌드를 결정하기 위해 슈퍼트렌드 지표를 사용하며 ATR 스톱 로스 원리를 결합하여 위험을 제어하여 장기 및 단기 거래를 가능하게 한다. 이 전략의 가장 큰 장점은 좋은 리스크 보상 비율과 중장기 보유에 적합한 신뢰할 수 있는 스톱 로스 전략이다. 이 전략은 코인베이스 프로와 같은 주류 거래소에서 4시간 시간 프레임을 사용하여 적용될 수 있다.

전략 원칙

이 전략은 시장 트렌드의 방향을 결정하기 위해 슈퍼 트렌드 지표를 사용합니다. 슈퍼 트렌드 지표가 하락 추세에서 상승 추세로 변할 때 길고 슈퍼 트렌드 지표가 상승 추세에서 하락 추세로 변할 때 짧습니다.

구체적으로, 이 전략은 먼저 ATR 기간을 14 바로 계산하고, 각 거래에 대한 스톱 로스 거리를 ATR 스톱 로스 멀티플라이서 (예를 들어 1.5x) 로 곱하여 결정합니다. 다음에는 기본 매개 변수를 사용하여 슈퍼 트렌드 지표를 계산합니다. (ATR 기간 = 9, 슈퍼 트렌드 멀티플라이서 = 2.5). 슈퍼 트렌드 지표가 방향을 변경하면 거래 신호가 생성됩니다.

트레이드에 진입한 후, 스톱 로스는 ATR 스톱 로스 이상 또는 아래로 고정된다. 첫 번째 취업 이윤 수준은 위험 보상 비율을 기준으로 계산되며, 기본값은 0.75이며, 즉 취업 이윤 거리는 스톱 로스 거리의 0.75x이다. 가격이 첫 번째 취업 이윤 수준에 도달하면, 포지션의 50%가 닫히고, 스톱 로스는 엔트리 가격 (브레이크 이븐) 으로 이동하여 수익을 잠금한다. 두 번째 취업 이윤 수준은 0.75의 위험 보상 비율을 계속 사용합니다. 가격이 스톱 로스에 도달하면 나머지 포지션은 스톱 로스로 닫을 것입니다.

이러한 전략은 중장기 투자 전략에 적합한 부분적 영업이익을 통해 통제 가능한 스톱 로스 위험을 보장하고 동시에 수익을 확보합니다.

이점 분석

이 전략의 가장 큰 장점은 중장기 지분을 허용하는 좋은 위험/이익 비율입니다. 구체적인 장점은 다음과 같습니다.

  1. 슈퍼트렌드를 사용하여 시장 트렌드를 결정하고 시장 소음을 필터하고 주요 트렌드를 파악합니다.

  2. 스톱 로스의 동적 ATR 추적, 단일 거래 손실을 안정적으로 제어합니다.

  3. 부분적으로 수익을 취하는 것은 수익에 잠금되어 높은 위험/이익 비율을 초래합니다.

  4. TP1에 도달한 후 Stop Loss를 엔트리 가격으로 옮기는 것은 이익에 잠금하고 전략의 안정성을 향상시킵니다.

  5. 매우 간단한 논리, 이해하기 쉽고 구현하기 쉬운, 큰 매개 변수 조정 공간.

  6. 내일 또는 고주파 데이터를 사용하는 주류 거래소에 적용되며, 높은 유연성.

위험 분석

이 전략은 또한 다음과 같은 영역에서 주로 몇 가지 위험을 안고 있습니다.

  1. 격차 위험은 스톱 로스를 유발하지 못하면 큰 손실을 당합니다. 위험을 줄이기 위해 ATR 스톱 로스 멀티플리커를 조정할 수 있습니다.

  2. 슈퍼트렌드는 올바른 트렌드를 결정하지 못해 잘못된 트레이드 신호를 발생시킵니다. 매개 변수를 최적화할 수 있습니다.

  3. 이윤률이 너무 높으면 트렌드를 따라가지 못해 다른 시장에 따라 조정해야 한다

  4. 거래 빈도는 너무 높거나 너무 낮을 수 있습니다. 슈퍼 트렌드 매개 변수를 조정하여 최적의 균형을 찾아야 합니다.

최적화 방향

이 전략의 최적화를 위해 여전히 많은 공간이 있습니다. 주로 다음 영역에서:

  1. 고정 ATR, 모멘텀 스톱, 볼링거 스톱 로스 등 다양한 ATR 스톱 로스 방법을 테스트합니다.

  2. 최고의 매개 변수를 위해 앞으로 걷거나 유전 알고리즘을 사용하여 슈퍼 트렌드 매개 변수를 최적화하십시오.

  3. 더 신뢰할 수 있는 스톱 손실을 만들기 위해 두 번째 스톱 손실 계층을 추가합니다.

  4. 최적의 이익 취득 대 위험 균형에 대한 다른 수익률을 테스트합니다.

  5. 동적 스톱 손실, 위치 조정 등을 위한 기계 학습 기술을 탐구합니다.

결론

이것은 트렌드, ATR 동적 중지 및 부분 수익을위한 슈퍼 트렌드를 기반으로 한 양적 전략입니다. 그것은 균형 잡힌 위험 보상 비율을 가지고 있으며, 알고 거래에 적합합니다. 매개 변수, 중지 손실, 수익 취득 등을 최적화 할 수있는 충분한 공간이 있습니다. 그것은 장기 조정 및 적용 가치가 있습니다.


/*backtest
start: 2024-01-06 00:00:00
end: 2024-02-05 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/
// Developed by © StrategiesForEveryone
//@version=5

strategy("SuperTrend Strategy for BTCUSD 4H", overlay=true, process_orders_on_close = true, initial_capital = 100, default_qty_type = strategy.cash, precision = 2, slippage = 50, commission_value = 0.03, backtest_fill_limits_assumption = 50)

// ------ Date filter (obtained from ZenAndTheArtOfTrading) ---------

initial_date = input(title="Initial date", defval=timestamp("10 Feb 2014 13:30 +0000"), group="Time filter", tooltip="Enter the start date and time of the strategy")
final_date   = input(title="Final date", defval=timestamp("01 Jan 2030 19:30 +0000"), group="Time filter", tooltip="Enter the end date and time of the strategy")
dateFilter(int st, int et) => time >= st and time <= et
colorDate = input.bool(defval=false, title="Date background", tooltip = "Add color to the period of time of the strategy tester")
bgcolor(colorDate and dateFilter(initial_date, final_date) ? color.new(color.blue, transp=90) : na)

// ------------ Super Trend ----------

atrPeriod = input(9, "ATR Length SuperTrend")
factor = input.float(2.5, "Factor SuperTrend", step = 0.05)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
show_supertrend = input.bool(defval = false, title="Show supertrend ?", group = "Appearance")
bodyMiddle = plot(show_supertrend ? ((open + close) / 2) : na, display=display.none)
upTrend = plot(show_supertrend and direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(show_supertrend and direction > 0 ? supertrend : na, "Down Trend", color = color.red, style=plot.style_linebr)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)

// ---------- Atr stop loss (obtained from garethyeo)

source_atr = input(close, title='Source', group = "Atr stop loss", inline = "A")
length_atr = input.int(14, minval=1, title='Period', group = "Atr stop loss" , inline = "A")
multiplier = input.float(1.5, minval=0.1, step=0.1, title='Atr multiplier', group = "Atr stop loss", inline = "A", tooltip = "Defines the stop loss distance based on the Atr stop loss indicator")
shortStopLoss = source_atr + ta.atr(length_atr) * multiplier
longStopLoss = source_atr - ta.atr(length_atr) * multiplier
show_atr_stoploss = input.bool(defval=false, title="Show Atr stop loss ?", group = "Appearance")
plot(show_atr_stoploss ? longStopLoss : na, color=color.white, style = plot.style_circles)
plot(show_atr_stoploss ? shortStopLoss : na, color=color.white, style = plot.style_circles)

// ------------- Money management --------------

strategy_contracts = strategy.equity / close
distance_sl_atr_long = -1 * (longStopLoss - close) / close
distance_sl_atr_short = (shortStopLoss - close) / close
risk = input.float(2.5, '% Account risk per trade', step=1, group = "Risk management for trades", tooltip = "Percentage of total account to risk per trade")
long_amount = strategy_contracts * (risk / 100) / distance_sl_atr_long
short_amount = strategy_contracts * (risk / 100) / distance_sl_atr_short

// ---------- Risk management ---------------

risk_reward_breakeven_long= input.float(title="Risk/reward for breakeven long", defval=0.75, step=0.05, group = "Risk management for trades")
risk_reward_take_profit_long= input.float(title="Risk/reward for take profit long", defval=0.75, step=0.05, group = "Risk management for trades")
risk_reward_breakeven_short= input.float(title="Risk/reward for break even short", defval=0.75, step=0.05, group = "Risk management for trades")
risk_reward_take_profit_short= input.float(title="Risk/reward for take profit short", defval=0.75, step=0.05, group = "Risk management for trades")
tp_percent=input.float(title="% of trade for first take profit", defval=50, step=5, group = "Risk management for trades", tooltip = "Closing percentage of the current position when the first take profit is reached.")

// ------------ Trade conditions ---------------

bought = strategy.position_size > 0
sold = strategy.position_size < 0
long_supertrend=ta.crossover(close, supertrend)
short_supertrend=ta.crossunder(close, supertrend)
var float sl_long = na
var float sl_short = na 
var float be_long = na
var float be_short = na
var float tp_long = na
var float tp_short = na
if not bought
    sl_long:=na
if not sold
    sl_short:=na

// ---------- Strategy -----------

// Long position 

if not bought and long_supertrend
    sl_long:=longStopLoss           
    long_stoploss_distance = close - longStopLoss
    be_long := close + long_stoploss_distance * risk_reward_breakeven_long
    tp_long:=close+(long_stoploss_distance*risk_reward_take_profit_long)
    strategy.entry('L', strategy.long, long_amount, alert_message = "Long")
    strategy.exit("Tp", "L", stop=sl_long, limit=tp_long, qty_percent=tp_percent)
    strategy.exit('Exit', 'L', stop=sl_long)
if high > be_long
    sl_long := strategy.position_avg_price
    strategy.exit("Tp", "L", stop=sl_long, limit=tp_long, qty_percent=tp_percent)
    strategy.exit('Exit', 'L', stop=sl_long)
if bought and short_supertrend
    strategy.close("L", comment="CL")

// Short position

if not sold and short_supertrend
    sl_short:=shortStopLoss
    short_stoploss_distance=shortStopLoss - close  
    be_short:=((short_stoploss_distance*risk_reward_breakeven_short)-close)*-1
    tp_short:=((short_stoploss_distance*risk_reward_take_profit_short)-close)*-1
    strategy.entry("S", strategy.short, short_amount, alert_message = "Short")
    strategy.exit("Tp", "S", stop=sl_short, limit=tp_short, qty_percent=tp_percent)
    strategy.exit("Exit", "S", stop=sl_short)
if low < be_short
    sl_short:=strategy.position_avg_price
    strategy.exit("Tp", "S", stop=sl_short, limit=tp_short, qty_percent=tp_percent)
    strategy.exit("Exit", "S", stop=sl_short)    
if sold and long_supertrend
    strategy.close("S", comment="CS") 

// ---------- Draw position on chart -------------

if high>tp_long
    tp_long:=na
if low<tp_short
    tp_short:=na
if high>be_long
    be_long:=na
if low<be_short
    be_short:=na

show_position_on_chart = input.bool(defval=true, title="Draw position on chart ?", group = "Appearance", tooltip = "Activate to graphically display profit, stop loss and break even")
position_price = plot(show_position_on_chart? strategy.position_avg_price : na, style=plot.style_linebr, color = color.new(#ffffff, 10), linewidth = 1)

sl_long_price = plot(show_position_on_chart and bought ? sl_long : na, style = plot.style_linebr, color = color.new(color.red, 10), linewidth = 1)
sl_short_price = plot(show_position_on_chart and sold ? sl_short : na, style = plot.style_linebr, color = color.new(color.red, 10), linewidth = 1)

tp_long_price = plot(strategy.position_size>0 and show_position_on_chart? tp_long : na, style = plot.style_linebr, color = color.new(#11eb47, 10), linewidth = 1)
tp_short_price = plot(strategy.position_size<0 and show_position_on_chart? tp_short : na, style = plot.style_linebr, color = color.new(#11eb47, 10), linewidth = 1)

breakeven_long = plot(strategy.position_size>0 and high<be_long and show_position_on_chart ? be_long : na , style = plot.style_linebr, color = color.new(#00ff40, 60), linewidth = 1)
breakeven_short = plot(strategy.position_size<0 and low>be_short and show_position_on_chart ? be_short : na , style = plot.style_linebr, color = color.new(#00ff40, 60), linewidth = 1)

position_profit_long = plot(bought and show_position_on_chart and strategy.openprofit>0 ? close : na, style = plot.style_linebr, color = color.new(#4cd350, 10), linewidth = 1)
position_profit_short = plot(sold and show_position_on_chart and strategy.openprofit>0 ? close : na, style = plot.style_linebr, color = color.new(#4cd350, 10), linewidth = 1)

fill(plot1 = position_price, plot2 = position_profit_long, color = color.new(color.green,90))
fill(plot1 = position_price, plot2 = position_profit_short, color = color.new(color.green,90))

fill(plot1 = position_price, plot2 = sl_long_price, color = color.new(color.red,90))
fill(plot1 = position_price, plot2 = sl_short_price, color = color.new(color.red,90))

fill(plot1 = position_price, plot2 = tp_long_price, color = color.new(color.green,90))
fill(plot1 = position_price, plot2 = tp_short_price, color = color.new(color.green,90))


더 많은