평균 역전 동력 전략

저자:차오장, 날짜: 2023-11-15 17:40:59
태그:

img

전반적인 설명

평균 회전 동력 전략은 단기 가격 평균을 추적하는 트렌드 거래 전략이다. 중장기 시장 추세를 판단하기 위해 평균 회전 지표와 동력 지표를 결합합니다.

전략 논리

전략은 먼저 평균 반전선과 가격의 표준편차를 계산합니다. 그 다음, 상단점 및 하단점 매개 변수에서 설정된 임계 값과 결합하여 가격이 평균 반전선에서 한 표준편차의 범위를 초과하는지 계산합니다. 그렇다면 거래 신호가 생성됩니다.

긴 신호의 경우, 가격은 평균 회전선 아래에서 1개의 표준편차, 클로즈 가격은 LENGTH 기간의 SMA 아래, 그리고 TREND SMA 위에 있어야 합니다. 이 세 가지 조건이 충족되면 긴 포지션이 열릴 것입니다. 폐쇄 조건은 가격이 LENGTH 기간의 SMA를 넘을 때입니다.

짧은 신호의 경우, 가격은 평균 회전선보다 1개의 표준편차로 높아야 하며, 클로즈 가격은 LENGTH 기간의 SMA보다 높고, TREND SMA보다 낮아야 합니다. 이 세 가지 조건이 충족되면, 짧은 포지션이 열립니다. 폐쇄 조건은 가격이 LENGTH 기간의 SMA보다 낮을 때입니다.

이 전략은 또한 수익을 취하고 손실을 막는 관리를 위해 퍼센트 수익 목표와 퍼센트 중지 손실을 결합합니다.

출구 방법은 이동 평균 크로스오버 또는 선형 회귀 크로스오버를 선택할 수 있습니다.

쌍방향 거래, 트렌드 필터링, 이윤 취득 및 스톱 손실 등을 결합하여 중장기 시장 추세를 판단하고 추적합니다.

장점

  1. 평균 반전 지표는 가치 중심에서 가격의 편차를 효과적으로 판단 할 수 있습니다.

  2. 동력 지표 SMA는 단기 시장 소음을 필터링할 수 있습니다.

  3. 쌍방향 거래는 모든 방향의 트렌드 기회를 완전히 포착 할 수 있습니다.

  4. 이윤 취득 및 손해 중지 메커니즘은 위험을 효과적으로 제어 할 수 있습니다.

  5. 선택 가능한 출구 방법은 시장 조건에 적응하기 위해 유연할 수 있습니다.

  6. 중장기 트렌드를 더 잘 파악하는 완벽한 트렌드 트레이딩 전략입니다.

위험성

  1. 평균 반전 지표는 매개 변수 설정에 민감하며, 잘못된 임계 설정으로 인해 잘못된 신호가 발생할 수 있습니다.

  2. 변동적인 시장 조건에서, 스톱 로스는 너무 자주 실행될 수 있습니다.

  3. 측면적인 경향에서 거래 빈도는 너무 높을 수 있으며 거래 비용과 미끄러짐 위험을 증가시킬 수 있습니다.

  4. 거래 수단이 충분한 유동성을 가지고 있지 않을 때, 미끄러짐 통제는 최적의 수준이 아닐 수 있습니다.

  5. 쌍방향 거래는 더 높은 위험을 초래하고 신중한 자금 관리가 필요합니다.

이러한 위험은 매개 변수 최적화, 스톱 로스 조정, 돈 관리 등을 통해 제어 할 수 있습니다.

최적화 방향

  1. 각기 다른 거래 도구에 더 잘 맞게 평균 반전 및 동력 지표의 매개 변수 설정을 최적화합니다.

  2. 트렌드 식별 지표를 추가하여 트렌드 인식 능력을 향상시킵니다.

  3. 시장의 중요한 변동에 더 잘 적응하기 위해 스톱 로스 전략을 최적화하십시오.

  4. 포지션 크기를 시장 조건에 따라 조정하기 위해 포지션 크기를 조정하는 모듈을 추가합니다.

  5. 최대 유출 통제, 주식 곡선 통제 등 더 많은 리스크 관리 모듈을 추가합니다.

  6. 자동으로 전략 매개 변수를 최적화하기 위해 기계 학습 방법을 결합하는 것을 고려하십시오.

요약

요약하자면, 평균 반전 모멘텀 전략은 간단하고 효과적인 지표 설계를 통해 중장기 평균 반전 추세를 포착합니다. 전략은 강력한 적응력과 다재다능성을 가지고 있지만 또한 몇 가지 위험을 가지고 있습니다. 지속적인 최적화와 다른 전략과 결합하여 더 나은 성능을 얻을 수 있습니다. 전반적으로 전략은 상당히 완전하며 고려할 가치가있는 트렌드 거래 방법입니다.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 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/
// © GlobalMarketSignals

//@version=4
strategy("GMS: Mean Reversion Strategy", overlay=true)

LongShort       = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"])
Lookback        = input(title="Length", type=input.integer, defval=10, minval=0)
LThr1           = input(title="Upper threshold", type=input.float, defval=1, minval=0)
LThr            = input(title="Lower threshold", type=input.float, defval=-1, maxval=0)
src             = input(title="Source", type=input.source, defval=close)
LongShort2      = input(title="Linear Regression Exit or Moving Average Exit?", type=input.string, defval="MA", options=["LR", "MA"])
SMAlenL         = input(title="MA/LR Exit Length", type = input.integer ,defval=10)
SMALen2         = input(title="Trend SMA Length", type = input.integer ,defval=200)
AboveBelow      = input(title="Above or Below Trend SMA?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"])
PTbutton        = input(title="Profit Target On/Off", type=input.bool, defval=true)
ProfitTarget    = input(title="Profit Target %", type=input.float, defval=1, step=0.1, minval=0)
SLbutton        = input(title="Stop Loss On/Off", type=input.bool, defval=true)
StopLoss        = input(title="Stop Loss %", type=input.float, defval=-1, step=0.1, maxval=0)

x               = (src-linreg(src,Lookback,0))/(stdev(src,Lookback))

plot(linreg(src,Lookback,0))

//PROFIT TARGET & STOPLOSS

if PTbutton == true and SLbutton == true
    strategy.exit("EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick), loss=((close*(StopLoss*-0.01))/syminfo.mintick))
else
    if PTbutton == true and SLbutton == false
        strategy.exit("PT EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick))
    else
        if PTbutton == false and SLbutton == true
            strategy.exit("SL EXIT", loss=((close*(StopLoss*-0.01))/syminfo.mintick))
        else    
            strategy.cancel("PT EXIT")


////////////////////////
//MOVING AVERAGE EXIT//
//////////////////////

if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////    
    
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL)   and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1  and close>sma(close,SMAlenL)  )
    strategy.close("SHORT", when = close<sma(close,SMAlenL))
    
//////

if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////    
    
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) )
    strategy.close("SHORT", when = close<sma(close,SMAlenL))
    
/////////////////
//LIN REG EXIT//
///////////////

if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
    
///////    
    
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0)   and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1  and close>linreg(close,SMAlenL,0)  )
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
    
//////

if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
    
///////    
    
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) )
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))






더 많은