이중 이동 평균 및 윌리엄스 평균 조합 전략

저자:차오장, 날짜: 2024-01-26 16:36:27
태그:

img

전반적인 설명

전략 논리

이 전략은 두 가지 하위 전략으로 구성됩니다.

  1. 윌리엄스 세 이동 평균. 이 지표는 긴, 중간 및 짧은 라인으로 구성되어 있습니다. 트렌드 변화를 결정하고 거래 신호를 생성하기 위해 다른 기간의 이동 평균의 교차를 사용합니다. 짧은 라인이 중간 라인의 위를 넘고 중간 라인이 긴 라인의 위를 넘으면 긴 신호입니다. 짧은 라인이 중간 라인의 아래를 넘고 중간 라인이 긴 라인의 아래를 넘으면 짧은 신호입니다.

이 전략의 거래 신호는 두 하위 전략의 결과의 AND 연산이다. 즉, 두 하위 전략이 동시에 신호를 발행할 때만 이 전략에 대한 주문이 트리거 될 것이다. 이것은 잘못된 신호를 효과적으로 줄이고 포지션 보유의 안정성을 향상시킬 수 있다.

이점 분석

위험 분석

이 전략의 주요 위험은 시장이 격렬한 변동에 들어갈 때 스톱 로스 포인트가 깨질 수 있으며 이로 인해 더 큰 손실이 발생할 수 있다는 것입니다. 이것은 이동 평균 전략의 일반적인 문제입니다. 또한, 오스실레이션 시장에서이 전략은 종종 포지션을 열고 닫을 수 있으며 거래 수수료의 비용을 증가시킬 수 있습니다.

최적화 방향

결론


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 21/04/2022
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This indicator plots 2/20 exponential moving average. For the Mov 
// Avg X 2/20 Indicator, the EMA bar will be painted when the Alert criteria is met.
//
// Second strategy
// This indicator calculates 3 Moving Averages for default values of
// 13, 8 and 5 days, with displacement 8, 5 and 3 days: Median Price (High+Low/2).
// The most popular method of interpreting a moving average is to compare 
// the relationship between a moving average of the security's price with 
// the security's price itself (or between several moving averages).
//
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
EMA20(Length) =>
    pos = 0.0
    xPrice = close
    xXA = ta.ema(xPrice, Length)
    nHH = math.max(high, high[1])
    nLL = math.min(low, low[1])
    nXS = nLL > xXA or nHH < xXA ? nLL : nHH
    iff_1 = nXS < close[1] ? 1 : nz(pos[1], 0)
    pos := nXS > close[1] ? -1 : iff_1
    pos


BWA3Lines(LLength,MLength,SLength,LOffset,MOffset,SOffset) =>
    pos = 0.0
    xLSma = ta.sma(hl2, LLength)[LOffset]
    xMSma = ta.sma(hl2, MLength)[MOffset]
    xSSma = ta.sma(hl2, SLength)[SOffset]
    pos := close < xSSma and xSSma < xMSma and xMSma < xLSma ? -1 :
    	     close > xSSma and xSSma > xMSma and xMSma > xLSma ? 1 : nz(pos[1], 0) 
    pos

strategy(title='Combo 2/20 EMA & Bill Williams Averages. 3Lines', shorttitle='Combo', overlay=true)
var I1 = '●═════ 2/20 EMA ═════●'
Length = input.int(14, minval=1, group=I1)
var I2 = '●═════ 3Lines ═════●'
LLength = input.int(13, minval=1, group=I2)
MLength = input.int(8,minval=1, group=I2)
SLength = input.int(5,minval=1, group=I2)
LOffset = input.int(8,minval=1, group=I2)
MOffset = input.int(5,minval=1, group=I2)
SOffset = input.int(3,minval=1, group=I2)
var misc = '●═════ MISC ═════●'
reverse = input.bool(false, title='Trade reverse', group=misc)
var timePeriodHeader = '●═════ Time Start ═════●'
d = input.int(1, title='From Day', minval=1, maxval=31, group=timePeriodHeader)
m = input.int(1, title='From Month', minval=1, maxval=12, group=timePeriodHeader)
y = input.int(2005, title='From Year', minval=0, group=timePeriodHeader)
StartTrade = time > timestamp(y, m, d, 00, 00) ? true : false
posEMA20 = EMA20(Length)
prePosBWA3Lines = BWA3Lines(LLength,MLength,SLength,LOffset,MOffset,SOffset)
iff_1 = posEMA20 == -1 and prePosBWA3Lines == -1 and StartTrade ? -1 : 0
pos = posEMA20 == 1 and prePosBWA3Lines == 1 and StartTrade ? 1 : iff_1
iff_2 = reverse and pos == -1 ? 1 : pos
possig = reverse and pos == 1 ? -1 : iff_2
if possig == 1
    strategy.entry('Long', strategy.long)
if possig == -1
    strategy.entry('Short', strategy.short)
if possig == 0
    strategy.close_all()
barcolor(possig == -1 ? #b50404 : possig == 1 ? #079605 : #0536b3)

더 많은