이동 평균 진입 최적화 전략

저자:차오장, 날짜: 2023-09-14 16:52:30
태그:

전략 논리

이 전략은 기본 이동 평균 시스템에서 신호를 받은 입구점을 최적화합니다.

가장 중요한 논리는

  1. 한 기간 동안의 이동 평균을 계산합니다 (예를 들어 20일)

  2. 크로스오버는 긴/단 신호를 생성합니다

  3. 신호가 나오면 즉시 들어가지 말고 더 높은 레벨을 기다리세요

  4. 더 나은 수준이 지정된 날 (예: 3 일) 내에 발생하면 트레이드를 입력합니다.

  5. 그렇지 않으면 5일째에 닫기 가격으로 입력하여 놓치지 않도록 합니다

이것은 즉시 신호를 입력하기보다는 통합 후의 동향의 재개를 활용하기 위해 노력합니다. 개선 된 수준에서 위치를 설정 할 수 있습니다.

장점

  • 더 나은 입시 레벨을 위한 입시 최적화

  • 최대 대기일이 완전히 놓친 거래를 피합니다.

  • 간단하고 명확한 규칙

위험성

  • 대기 시간 및 임계 기준은 최적화되어야 합니다.

  • 단기적인 트렌드 기회를 놓칠 수도 있습니다.

  • 시간 및 가격 조건을 모니터링 할 필요가 있습니다

요약

이 전략은 트렌드를 놓치지 않도록 단순 입시 최적화를 통해 더 나은 입시 수준을 달성하는 것을 목표로합니다. 그러나 대기 시간 및 입시 기준을 최적화하는 것이 중요합니다.


/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 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/
// © dongyun

//@version=4
strategy("等待一个更好的入场机会", overlay=true)

period = input(20,'')
maxwait = input(3,'')
threshold = input(0.01,'')

signal = 0
trend = 0.0
newtrend = 0.0
wait = 0.0
initialentry = 0.0

trend := sma(close,period)
signal := nz(signal[1])
if trend > nz(trend[1])
	signal := 1
else
	if trend < nz(trend[1])
		signal := -1

wait := nz(wait[1])
initialentry := nz(initialentry[1])

if signal != signal[1]
	if strategy.position_size > 0
		strategy.close('long',comment='trend sell')
		signal := -1
	else
		if strategy.position_size < 0
    		strategy.close('short',comment='trend buy')
    		signal := 1
	wait := 0
	initialentry := close
else
	if signal != 0 and strategy.position_size == 0
		wait := wait + 1

// test for better entry
if strategy.position_size == 0
	if wait >= maxwait
		if signal > 0
			strategy.entry('long',strategy.long, comment='maxtime Long')
		else
			if signal < 0
				strategy.entry('short',strategy.short, comment='maxtime Short')
	else
		if signal > 0 and close < initialentry - threshold
			strategy.entry('long',strategy.long, comment='delayed Long')
		else
			if signal < 0 and close > initialentry + threshold
				strategy.entry('short',strategy.short, comment='delayed short')


더 많은