오픈 클로즈 크로스 이동 평균 트렌드 전략

저자:차오장날짜: 2024-01-15 14:24:27
태그:

img

전반적인 설명

오픈 클로즈 크로스 이동 평균 트렌드 다음 전략 (Open Close Cross Moving Average Trend Following Strategy) 은 오픈 및 클로즈 가격의 이동 평균에 기반한 트렌드 다음 전략이다. 오픈 및 클로즈 가격의 이동 평균을 계산하여 현재 시장 트렌드를 결정한다. 종료 가격 이동 평균이 개시 가격 이동 평균을 넘어서면 긴 경로로 이동하고, 종료 가격 이동 평균이 개시 가격 이동 평균을 넘어서면 짧은 경로로 이동한다. 전략은 또한 수익을 잠금하고 위험을 효과적으로 제어하기 위해 트레일링 스톱을 설정한다.

원칙

이 전략의 핵심 논리는 현재 트렌드를 결정하기 위해 오픈 및 클로즈 가격 사이의 관계에 기반합니다. 오픈 가격은 현재 시장 수요 공급 관계와 거래 심리학을 반영하며, 종료 가격은 하루의 최종 거래 결과를 반영합니다. 일반적으로 종료 가격이 오픈 가격보다 높으면 하루의 시장 추세가 상승하고 감정이 더 상승한다는 것을 나타냅니다. 종료 가격이 오픈 가격보다 낮으면 하루의 시장 추세가 하락하고 감정이 더 하락한다는 것을 나타냅니다.

이 전략은 현재 트렌드 방향을 판단하기 위해 오픈 및 클로즈 가격의 이동 평균을 계산하여 이러한 논리를 활용합니다. 구체적으로 거래 규칙은 다음과 같습니다.

  1. 닫기 가격 이동 평균이 개시 가격 이동 평균을 넘을 때 긴 지점을 선택하십시오. 이것은 상승 분위기가 강화되고 긴 지점이 시작 될 수 있음을 신호합니다.

  2. 닫기 가격 이동 평균이 개시 가격 이동 평균 아래를 넘을 때 짧습니다. 이것은 하향 분위기가 상승하고 짧은 지점이 시작 될 수 있음을 암시합니다.

  3. 반전 신호가 발생하면 기존 포지션을 스톱 로스로 닫습니다.

이 전략은 또한 수익을 잠금하기 위해 트레일링 스톱을 설정합니다. 포지션을 입력 한 후, 입시 가격과 현재 가격 사이의 포인트 차이를 동적으로 계산합니다. 가격 움직임이 설정된 스톱 손실 포인트 임계치를 초과하면 스톱 손실 라인은 부분 수익을 잠금하기 위해 위로 이동합니다.

요약하자면, 전략은 이동 평균 기간 동안의 경향을 판단하고, 한 번에 하나의 방향적 지위를 유지하며, ATR 정지없이 역 신호로 기존 지위를 직접 종료하고, 수익을 확보하기 위해 후속 정지 설정을 가지고 있습니다.

이점 분석

이 전략은 다음과 같은 주요 장점을 가지고 있습니다.

  1. 단순 하고 명확 한 규칙개방-접근 관계를 기반으로 추세를 판단하는 것은 이해하기 쉽고 매개 변수를 최적화합니다.

  2. 유연한 MA 선택선택하고 최적화 할 수 있는 수십 가지 MA 유형이 있습니다.

  3. 조정 가능한 해상도해상도는 차트의 3-4 배로 설정할 수 있습니다. 더 민감하고 시속적인 신호를 위해.

  4. 손실 중지 메커니즘트레일링 스톱은 거래당 손실과 인수를 효과적으로 제어합니다.

  5. 개인화 가능한 보관 기간보유 기간과 변동성은 MA 매개 변수를 조정하여 제어 할 수 있습니다.

  6. 유연하게 조정할 수 있는 리스크 보상손해를 멈추는 지점과 위험-상금 선호도를 조정합니다.

위험 분석

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

  1. 미흡 한 역행출구 신호는 가격 반전을 지연시켜 손실을 유지하게 될 수 있습니다. MA 기간을 단축하면 이것을 완화 할 수 있습니다.

  2. 높은 변동성 조건에 적합하지 않습니다.. 휘발성 조건 하에서 빈번한 위프사우는 높은 수수료 비용을 창출 합니다. 중지 손실 지점을 넓히거나 MA 기간을 연장하면 여기에 도움이 될 수 있습니다.

  3. 단일 지표에 의존단 하나의 지표 세트에 대한 결정을 기반으로 하는 것은 실패 위험에 노출됩니다. MACD와 같은 다른 지표를 추가하면 논리를 보완 할 수 있습니다.

  4. 과도한 최적화 위험. MA 매개 변수 및 스톱 손실 설정은 쉽게 과도하게 조정 될 수 있습니다. 샘플 외부 성능이 악화 될 수 있습니다. 매개 변수 선택에서 주의가 필요합니다.

최적화 방향

전략은 다음과 같은 영역에서 최적화되고 향상될 수 있습니다.

  1. 추가 지표변동성 및 추진력 지표는 견고성과 안정성을 높일 수 있습니다.

  2. 조건적 동적 매개 변수MA 기간은 더 나은 적응력을 위해 트렌드 또는 측면 시장 체제 검출에 따라 조정 될 수 있습니다.

  3. 역동적 위험 관리스톱 로스 포인트와 오프셋은 최근 실현된 변동성 수준에 따라 캘리브레이를 할 수 있습니다.

  4. 증진된 스톱 로스 논리ATR 스톱과 같은 더 고급 스톱 손실 메커니즘은 단순화된 트레일링 스톱을 대체할 수 있습니다.

결론

오픈 클로즈 크로스 이동 평균 트렌드 다음 전략은 오픈 클로즈 관계와 이동 평균에 기반한 전형적인 트렌드 거래 전략이다. 간단한 규칙, 유연성 및 제어 가능한 위험과 같은 장점은 또한 결여 된 역전 및 윙사와 같은 단점과 함께 제공됩니다. 향상 영역에는 더 많은 지표, 동적 매개 변수 및 더 나은 트렌드 포착 및 다양한 시장 조건에 대한 적응력을위한 고급 리스크 관리가 포함됩니다.


/*backtest
start: 2023-01-08 00:00:00
end: 2024-01-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy(title = "Open Close Cross Strategy (PineScript=v4)", shorttitle = "OCC Strategy", overlay = true )

// Revision:        1
// Author:          @JayRogers
//
// Description:
//  - Strategy based around Open-Close Crossovers.
// Setup:
//  - I have generally found that setting the strategy resolution to 3-4x that of the chart you are viewing
//    tends to yield the best results, regardless of which MA option you may choose (if any)
//  - Don't aim for perfection. Just aim to get a reasonably snug fit with the O-C band, with good runs of
//    green and red.
//  - Option to either use basic open and close series data, or pick your poison with a wide array of MA types.
//  - Optional trailing stop for damage mitigation if desired (can be toggled on/off)
//  - Positions get taken automagically following a crossover - which is why it's better to set the resolution
//    of the script greater than that of your chart, so that the trades get taken sooner rather than later.
//  - If you make use of the trailing stops, be sure to take your time tweaking the values. Cutting it too fine
//    will cost you profits but keep you safer, while letting them loose could lead to more drawdown than you
//    can handle.

// === INPUTS ===
useRes = input(defval=true, title="Use Alternate Resolution? ( recommended )")
stratRes = input(defval="120", title="Set Resolution ( should not be lower than chart )", type=input.resolution)
useMA = input(defval=true, title="Use MA? ( otherwise use simple Open/Close data )")
basisType = input(defval="DEMA", title="MA Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )", type=input.string)
basisLen = input(defval=14, title="MA Period", minval=1)
offsetSigma = input(defval=6, title="Offset for LSMA / Sigma for ALMA", minval=0)
offsetALMA = input(defval=0.85, title="Offset for ALMA", minval=0, step=0.01)
useStop = input(defval=true, title="Use Trailing Stop?")
slPoints = input(defval=200, title="Stop Loss Trail Points", minval=1)
slOffset = input(defval=400, title="Stop Loss Trail Offset", minval=1)
// === /INPUTS ===

// === BASE FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, offSig, offALMA) =>
    v1 = sma(src, len)  // Simple
    v2 = ema(src, len)  // Exponential
    v3 = 2 * v2 - ema(v2, len)  // Double Exponential
    v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)  // Triple Exponential
    v5 = wma(src, len)  // Weighted
    v6 = vwma(src, len)  // Volume Weighted
    sma_1 = sma(src, len)  // Smoothed
    v7 = na(v5[1]) ? sma_1 : (v5[1] * (len - 1) + src) / len
    v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))  // Hull
    v9 = linreg(src, len, offSig)  // Least Squares
    v10 = alma(src, len, offALMA, offSig)  // Arnaud Legoux
    type == "EMA" ? v2 : type == "DEMA" ? v3 : type == "TEMA" ? v4 : 
       type == "WMA" ? v5 : type == "VWMA" ? v6 : type == "SMMA" ? v7 : 
       type == "HullMA" ? v8 : type == "LSMA" ? v9 : type == "ALMA" ? v10 : v1
// security wrapper for repeat calls
reso(exp, use, res) =>
    security_1 = security(syminfo.tickerid, res, exp)
    use ? security_1 : exp
// === /BASE FUNCTIONS ===

// === SERIES SETUP ===
// open/close
variant__1 = variant(basisType, close, basisLen, offsetSigma, offsetALMA)
reso__1 = reso(variant__1, useRes, stratRes)
reso__2 = reso(close, useRes, stratRes)
closeSeries = useMA ? reso__1 : reso__2
variant__2 = variant(basisType, open, basisLen, offsetSigma, offsetALMA)
reso__3 = reso(variant__2, useRes, stratRes)
reso__4 = reso(open, useRes, stratRes)
openSeries = useMA ? reso__3 : reso__4
trendState = bool(na)
trendState := closeSeries > openSeries ? true : 
   closeSeries < openSeries ? false : trendState[1]
// === /SERIES ===

// === PLOTTING ===
barcolor(color=closeSeries > openSeries ? #006600 : #990000, title="Bar Colours")
// channel outline
closePlot = plot(closeSeries, title="Close Line", color=#009900, linewidth=2, style=plot.style_line, transp=90)
openPlot = plot(openSeries, title="Open Line", color=#CC0000, linewidth=2, style=plot.style_line, transp=90)
// channel fill
closePlotU = plot(trendState ? closeSeries : na, transp=100, editable=false)
openPlotU = plot(trendState ? openSeries : na, transp=100, editable=false)
closePlotD = plot(trendState ? na : closeSeries, transp=100, editable=false)
openPlotD = plot(trendState ? na : openSeries, transp=100, editable=false)
fill(openPlotU, closePlotU, title="Up Trend Fill", color=#009900, transp=40)
fill(openPlotD, closePlotD, title="Down Trend Fill", color=#CC0000, transp=40)
// === /PLOTTING ===

// === STRATEGY ===
// conditions
longCond = crossover(closeSeries, openSeries)
shortCond = crossunder(closeSeries, openSeries)
// entries and base exit
strategy.entry("long", strategy.long, when=longCond)
strategy.entry("short", strategy.short, when=shortCond)
// if we're using the trailing stop
if useStop
    strategy.exit("XL", from_entry="long", trail_points=slPoints, trail_offset=slOffset)
    strategy.exit("XS", from_entry="short", trail_points=slPoints, trail_offset=slOffset)
// not sure needed, but just incase..
strategy.exit("XL", from_entry="long", when=shortCond)
strategy.exit("XS", from_entry="short", when=longCond)
// === /STRATEGY ===


더 많은