이동평균선 교차 돌파 전략


생성 날짜: 2024-02-06 15:02:33 마지막으로 수정됨: 2024-02-06 15:02:33
복사: 1 클릭수: 671
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

이동평균선 교차 돌파 전략

개요

이 전략은 세 개의 다른 기간의 이동 평균을 사용하여 시장의 추세 방향을 식별합니다. 세 개의 이동 평균 방향이 일치하면 입장을 둡니다. 동시에, 가장 최근의 N 근 K 선의 최고 가격 또는 최저 가격과 결합하여 손실을 중지하십시오.

전략 원칙

  1. 장기, 중기, 단기 3개의 이동 평균을 계산한다. 사용자는 스스로 주기 설정할 수 있다. 20, 10, 5 일이라는 기본 설정이 있다.

  2. 세 개의 이동 평균의 방향을 비교한다. 단기 이동 평균이 중기간에, 중기간에 장기간에 쓰일 때, 다면 시장으로 판단한다. 단기 이동 평균이 중기간에, 중기간에 장기간에 쓰일 때, 공백 시장으로 판단한다.

  3. 다단 시장에서, 가격이 가장 최근의 N근 K선 내의 최고 가격을 뚫면 더 많이 한다. 공수 시장에서, 가격이 가장 최근의 N근 K선 내의 최저 가격을 뚫면 공수한다. N은 사용자 정의 파라미터가기도 하다.

  4. 포지션에 들어가면, 스톱로스트를 설정한다. 다중 시장의 스톱로스트는 가장 최근의 N 루트 K 라인 내의 최저 가격이며, 빈 시장의 스톱로스트는 가장 최근의 N 루트 K 라인 내의 최고 가격이다.

우위 분석

이 전략은 이동 평균 지표와 K선 그래프를 결합하여 시장의 움직임을 더 잘 판단 할 수 있습니다. 동시에, 스톱 손실 설정은 합리적이며, 큰 손실을 피하는 데 도움이됩니다.

단일 이동 평균과 같은 지표에 비해, 이 전략은 3 개의 이동 평균을 사용하여 시장의 움직임을 판단하는 신뢰성이 높습니다. 또한, 최근 N 근 K 라인 최고 가격 또는 최저 가격으로 포지션에 진입하는 것은 비교적 흔한 돌파 전략입니다. 전체적으로, 전략 아이디어는 명확하고 실행하기 쉽습니다.

위험 분석

이 전략의 주요 위험은 다음과 같습니다.

  1. 세 개의 이동 평균 방향 판단 오류의 확률. 중·단기 이동 평균이 잘못된 신호를 유발하면 불필요한 손실이 발생할 수 있습니다.

  2. 진입 시기를 선택하면 부적절하고, 함정에 빠질 수 있다. 진입 시기를 적절히 최적화해야 한다.

  3. 스탠드 거리 설정이 너무 작아서 스탠드 거리를 넓히면 Running Room에 더 많은 가격을 부여할 수 있습니다.

최적화 방향

이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.

  1. 다른 지표 필터를 추가하여 이동 평균 신호의 신뢰성을 보장한다. 예를 들어 거래량을 증가시키는 공백 판단이다.

  2. 이동 평균의 주기 변수를 최적화하여 다양한 품종에 더 잘 적응하도록 한다.

  3. 기계 학습 알고리즘을 추가하여 매개 변수의 자동 최적화를 구현한다.

  4. 고주파 데이터에 대한 전략의 효과를 테스트하는 것.

요약하다

이 전략은 전반적으로 단순하고 보편적이며, 아이디어가 명확하며, 실용성이 강하다. 이동 평균 교차 시스템의 예로서, 초보자의 일반적인 선택이다. 적절한 최적화를 통해 시스템을 더 넓은 품종과 시간 주기에서 사용할 수 있으므로 안정적인 수익을 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-01-30 00:00:00
end: 2024-02-05 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hobbiecode

//@version=5
strategy("Cross Breakout - Hobbiecode", shorttitle="Cross - HOBBIE", overlay=true)

// User-defined input for moving averages
long_period = input(20, title="Long Period")
medium_period =  input(10, title = "Medium Period")
short_period = input(5, title="Short Period")
type_ma = input.string("SMA", title = "MA type", options = ["SMA", "EMA"])
candles_back = input(10, title = "Candles Back")
bars_valid = input(3, title = "Bars to Exit")

// Calculating moving averages
long_ma = 0.0
medium_ma = 0.0
short_ma = 0.0

if type_ma == "SMA"
    long_ma := ta.sma(close, long_period)
    medium_ma := ta.sma(close, medium_period)
    short_ma := ta.sma(close, short_period)
else
    long_ma := ta.ema(close, long_period)
    medium_ma := ta.ema(close, medium_period)
    short_ma := ta.ema(close, short_period)

// Plot moving averages
plot(long_ma, title="Long Moving Average", color=color.red)
plot(medium_ma, title = "Medium Moving Average", color = color.yellow)
plot(short_ma, title="Short Moving Average", color=color.green)

// Check last min/max
last_min = ta.lowest(candles_back)
last_max = ta.highest(candles_back)

// Strategy logic for crossing of moving averages
longCondition = short_ma > medium_ma and medium_ma > long_ma and high == last_max
shortCondition = short_ma < medium_ma and medium_ma < long_ma and low == last_min

longCondition_entry = longCondition and strategy.position_size == 0
shortCondition_entry = shortCondition and strategy.position_size == 0

// Check last min/max for operation
last_min_op = ta.lowest(candles_back)[1]
last_max_op = ta.highest(candles_back)[1]

// Plot lines
var line r1Line = na

// Entry orders
// if (longCondition)
//     from_line = chart.point.now(high)
//     to_line = chart.point.from_index(bar_index + candles_back, high)
//     r1Line := line.new(from_line, to_line, color = color.green, width = 2)

if longCondition_entry and ta.crossover(close,last_max_op)
    strategy.entry("Long", strategy.long)
    strategy.exit("Exit Long", from_entry="Long", stop=low)

// if (shortCondition)
//     from_line = chart.point.now(low)
//     to_line = chart.point.from_index(bar_index + candles_back, low)
//     r1Line := line.new(from_line, to_line, color = color.red, width = 2)

if shortCondition_entry and ta.crossunder(close,last_min_op)
    strategy.entry("Short", strategy.short)
    strategy.exit("Exit Short", from_entry="Short", stop=high)

if ta.barssince(longCondition_entry) >= bars_valid
    strategy.close("Long")

if ta.barssince(shortCondition_entry) >= bars_valid
    strategy.close("Short")