상대적인 거래량과 추세에 기반한 거래 전략


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

상대적인 거래량과 추세에 기반한 거래 전략

개요

이 전략은 상대적인 거래량 지표와 가격행동 판단의 트렌드 지표를 결합하여, 결합된 트렌드 추적과 돌파구를 가진 자동 거래 시스템을 구현한다. 거래량이 증가하고 변동성이 적을 때 구매하고, 중지 지점과 가격행동에 따라 중지 또는 손실을 판단한다.

전략 원칙

  1. Bollinger Bands를 사용하여 가격의 변동이 작은지 판단하십시오. 구체적으로 ATR과 BOLL 채널의 대역폭을 비교하는 것입니다.

  2. 지난 N일 동안의 평균 거래량을 계산하고, 현재 볼륨과 비교하여 거래량이 증가했는지 판단합니다.

  3. 가격이 낮을 때 거래량이 증가하고, 변동이 적을 때 구매한다.

  4. 정지점을 설정하고 최저 가격 업데이트를 추적하십시오.

  5. 가격이 하향으로 스톱로스를 돌파했을 때 스톱로스를 한다.

  6. 가격들이 다목적 삼키기 패턴을 형성할 때 멈춥니다.

우위 분석

  1. 교류량과 변동성 지표가 결합되어 가짜 돌파구를 효과적으로 필터링 할 수 있습니다.

  2. 트렌드 트래킹 스톱로스 (Trend Tracking Stop Loss) 를 사용하여 수익을 최대한 고정할 수 있습니다.

  3. 다중 헤드 삼키는 것과 같은 형질 판단을 사용하여 트렌드 반전의 전날에 정지 신호로 정지 할 수 있습니다.

  4. 전략은 직관적이고 간단하며, 이해하기 쉽고 추적하기 쉽습니다.

  5. 정지 및 정지 규칙은 명확하게 되어 있으며, 폐쇄된 시장에 대한 불확실성을 줄여줍니다.

위험 분석

  1. 수강수준이 늦어지고 있으며, 가장 좋은 입학점을 놓칠 수도 있습니다.

  2. 다중머리 삼키는 것과 같은 형태적 판단은 중단 신호로 충분히 신뢰할 수 없으며, 조기 중단의 위험이 있습니다.

  3. 스톱로스 (Stop Loss) 는 단편적 손실이 발생할 수 있는 큰 위험이 있는 후진 전략이다.

  4. ATR 및 거래량 주기와 같은 합리적인 변수 조정이 필요합니다. 그렇지 않으면 거래가 자주 발생할 수 있습니다.

  5. “지급한 청산의 가능성을 줄이기 위해 주의를 기울여야 하고, 스톱스톱스룰을 최적화해야 한다”.

최적화 방향

  1. MACD 등과 같은 다른 지표와 함께 입력 신호를 필터링하는 것을 시도하십시오.

  2. ATR 및 거래량 주기 매개 변수를 최적화하여 빈번한 거래 위험을 줄입니다.

  3. 다른 정지 신호를 시도해 보세요. 예를 들어, 가격 하락을 위한 출구 메커니즘을 시도해 보세요.

  4. 동적으로 스톱 로스를 조정하여 더 많은 수익을 잠금 할 수 있는 가능성을 연구하십시오.

  5. 포지션 보유 기간의 영향을 테스트하고, 최적의 포지션 보유 기간을 찾습니다.

  6. 다양한 품종의 계약 효과를 추적하여 가장 적합한 품종을 찾습니다.

요약하다

이 전략은 전체적으로 간단하고 직관적이며, 거래량 지표와 가격 행태 판단을 결합하여 트렌드 추적 방식의 전략을 구현한다. 이점은 신호 발생이 명확하고, 추적하기 쉽고, 역행위 위험을 줄이는 것이다. 그러나 여전히 필터 신호의 품질과 스톱 로즈 규칙을 최적화하여 전략을 더 안정적으로 신뢰할 수 있도록 해야 한다. 매개 변수 설정, 진출 및 퇴출 메커니즘 등을 계속 개선함으로써 더 우수한 성과를 낼 수 있다.

전략 소스 코드
/*backtest
start: 2022-10-10 00:00:00
end: 2023-10-16 00:00:00
period: 1d
basePeriod: 1h
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/
// © DojiEmoji (kevinhhl)

//@version=4
strategy("[KL] Relative Volume Strategy",overlay=true,pyramiding=1)
ENUM_LONG = "Long"
VERBOSE_MODE = false
opened_position = false

// Timeframe {
backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)
USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")
backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)
within_timeframe = true
// }

// Volatility Indicators {
// BOLL:
BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)
BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2
plot(SMA20, "Basis", color=#872323, offset = 0)
BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)
BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)
//fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)
// ATR v. sDev of prices
ATR_x2 = atr(input(10,title="Length of ATR [Trailing Stop Loss] (x2)"))*2
//plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)
//plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)
//plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)
is_low_volat = ATR_x2 > BOLL_sDEV_x2
// }

// Trailing stop loss {
TSL_source = low

var entry_price = float(0), var stop_loss_price = float(0)

TSL_line_color = color.green
if strategy.position_size == 0 or not within_timeframe
    TSL_line_color := color.black
    stop_loss_price := TSL_source - ATR_x2 
else if strategy.position_size > 0
    stop_loss_price := max(stop_loss_price, TSL_source - ATR_x2)
plot(stop_loss_price, color=TSL_line_color)

// }

// Relative volume indicator {
LEN_RELATIVE_VOL = input(5, title="SMA(volume) length (for relative comparison)")
relative_vol = sma(volume,LEN_RELATIVE_VOL)
// }

// price actions {
bar_range_ratio = abs(close-open)/(high-low)
engulfing = low < low[1] and high > high[1] and abs(close-open) > abs(close-open)[1]
// }

// MAIN:
if within_timeframe
	entry_msg = "", exit_msg = close <= entry_price ? "stop loss" : "take profit"

    // ENTRY :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	if close > open and volume > relative_vol and is_low_volat
		if strategy.position_size > 0
			entry_msg := "adding"
		else if strategy.position_size == 0
			entry_msg := "initial"

		if strategy.position_size == 0
			entry_price := close
			stop_loss_price := TSL_source - ATR_x2
			ATR_x2 := ATR_x2

		strategy.entry(ENUM_LONG, strategy.long, comment=entry_msg)

    // EXIT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	if strategy.position_size > 0
		bExit = false		
		// EXIT: Case (A) touches trailing stop loss
		if TSL_source <= stop_loss_price
			exit_msg := exit_msg + "[TSL]"
			bExit := true
		// EXIT: Case (B)
		else if close < open and not is_low_volat and engulfing and (high-low) > ATR_x2
			exit_msg := VERBOSE_MODE ? exit_msg + "[engulfing bearish]" : exit_msg
			bExit := true
        strategy.close(ENUM_LONG, when=bExit, comment=exit_msg)

// CLEAN UP:
if strategy.position_size == 0
	entry_price := 0
	stop_loss_price := float(0)