거래 전략에 따른 상대적 양량 동향

저자:차오장, 날짜: 2023-10-17 16:19:59
태그:

img

전반적인 설명

이 전략은 상대 부피 지표와 가격 액션 트렌드 판단을 결합하여 트렌드 추적 및 브레이크아웃을 통합하는 자동 거래 시스템을 구축합니다. 부피가 증가하고 변동성이 낮을 때 구매하고 스톱 로스 및 가격 액션을 기반으로 판매합니다.

어떻게 작동 합니까?

  1. 볼링거 대역을 사용하여 가격 변동성이 낮는지 여부를 결정합니다. 특히 ATR와 BOLL 대역 폭을 비교하여

  2. 지난 N일 동안의 평균 부피를 계산하고 현재 부피와 비교하여 부피가 증가했는지 확인합니다.

  3. 가격이 거의 낮고 부피가 증가하고 변동성이 낮을 때 구매합니다.

  4. 스톱 로스를 설정하고 가장 낮은 가격을 추적합니다.

  5. 가격이 스톱 로스 이하로 떨어지면 팔자.

  6. 가격이 상승 추세로 치솟을 때 팔자

장점

  1. 부피와 변동성을 결합하면 가짜 브레이크를 효과적으로 필터합니다.

  2. 손해를 막는 것은 최대 수익을 올릴 수 있습니다.

  3. 상승세와 같은 출구 신호는 트렌드 전환을 일찍 잡습니다.

  4. 직관적이고 따라하기 쉽죠.

  5. 스톱 로즈와 영업 취득에 대한 명확한 규칙은 불확실성을 줄입니다.

위험성

  1. 부피 지표가 뒤떨어지고 있어 가장 좋은 입구를 놓칠 수 있어

  2. 침몰과 같은 출구 신호는 신뢰성이 부족하고, 조기 출구 위험이 있습니다.

  3. 더 넓은 스톱은 단일 거래에서 더 큰 손실을 초래합니다.

  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)


더 많은