달 위상을 기반으로 한 양방향 거래 전략

저자:차오장, 날짜: 2024-02-21 16:15:25
태그:

img

전반적인 설명

이 전략은 달의 위상을 기준으로 길고 짧게 거래합니다. 새 달에는 길고 보름달에는 짧게 거래합니다.

전략 논리

이 전략은 사용자 지정 함수를 사용하여 날짜를 기반으로 정밀하게 달 단계를 계산합니다. 달 연령이 15 미만인 것은 새 달이며 15 ~ 30 사이에는 보름달입니다. 달 단계에 따라 길고 짧은 신호를 생성하여 새 달에서 긴 포지션을 열고 보름달에서 짧은 포지션을 닫습니다. 역 신호에 따라 포지션을 닫습니다. 보름달에서 긴 신호를 닫고 보름달에 짧은 신호를 닫습니다.

사용자들은 새 달에 롱, 풀 달에 쇼트 또는 그 반대를 선택할 수 있다. 볼레 변수는 거래가 현재 열렸는지 추적한다. 포지션이 열리지 않은 상태에서 신호가 나타나면 새로운 거래를 열고 역 신호에 현재 포지션을 닫는다. 구매 및 판매 마커는 시각적으로 표시된다.

장점

  1. 달 주기의 주기성을 사용하여 장기적인 경향을 포착합니다
  2. 커스터마이징 표시 색상, 채우기 등
  3. 양방향 전략 선택
  4. 명확한 개방/폐기 표시기
  5. 최적화를 위한 사용자 정의 가능한 백테스트 시작 시간

위험성

  1. 긴 달 주기가 단기적 움직임을 포착하는 데 실패
  2. 손해를 막지 않으면 큰 손실이 발생할 수 있습니다.
  3. 고정 주기가 패턴 형성에 유연합니다.

위험 완화:

  1. 다중 시간 프레임 거래를 위한 다른 단기주기 지표를 추가합니다.
  2. 스톱 손실을 실행
  3. 손실 영향을 제한하기 위해 위치 크기를 최적화

최적화 방향

이 전략은 다음과 같이 개선될 수 있습니다.

  1. 신호 필터링에 더 많은 지표를 추가하고 안정성을 향상
  2. 최적화 및 손실 영향을 줄이기 위해 위치 크기를 추가
  3. 손실을 제한하기 위해 스톱 로스 모듈을 추가
  4. 미끄러짐을 줄이고 승률을 향상시키기 위해 오픈/클로즈 조건을 최적화

결론

이 전략은 새 달과 보름달을 기반으로 한 양방향 거래 전략을 구현하기 위해 달 주기의 주기성을 이용합니다. 명확한 신호, 높은 사용자 정의 가능성, 장기 트렌드를 잘 잡습니다. 그러나 손실을 제한할 수 없다는 것은 상당한 위험을 초래합니다. 짧은 주기의 지표를 결합하고 포지션 사이징을 추가하고 손실을 중지하여 전략을 더 최적화하는 것이 좋습니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
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/

// ---------------------------© paaax----------------------------
// ---------------- Author1: Pascal Simon (paaax) ----------------
// -------------------- www.pascal-simon.de ---------------------
// ---------------- www.tradingview.com/u/paaax/-----------------
// Source: https://gist.github.com/L-A/3497902#file-moonobject-js

// -------------------------© astropark--------------------------
// --------------- Author2: Astropark (astropark) ---------------
// -------------- https://bit.ly/astroparktrading ---------------
// -------------- www.tradingview.com/u/astropark/---------------


// @version=4
strategy(title="[astropark] Moon Phases [strategy]", overlay=true, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 100000, currency = currency.USD, commission_value = 0.1)

// INPUT    --- {

newMoonColor = input(color.black, "New Moon Color")
fullMoonColor = input(color.white, "Full Moon Color")

fillBackground = input(true, "Fill Background?")
newMoonBackgroundColor = input(#fffff0aa, "New Moon Background Color")
fullMoonBackgroundColor = input(#aaaaaaaa, "Full Moon Background Color")

//} --- INPUT

// FUNCTION --- {

normalize(_v) =>
    x = _v
    x := x - floor(x)
    if x < 0
        x := x + 1
    x

calcPhase(_year, _month, _day) =>

    int y = na
    int m = na
    float k1 = na 
    float k2 = na 
    float k3 = na
    float jd = na
    float ip = na

    y := _year - floor((12 - _month) / 10)       
    m := _month + 9
    if m >= 12 
        m := m - 12
    
    k1 := floor(365.25 * (y + 4712))
    k2 := floor(30.6 * m + 0.5)
    k3 := floor(floor((y / 100) + 49) * 0.75) - 38
    
    jd := k1 + k2 + _day + 59
    if jd > 2299160
        jd := jd - k3
    
    ip := normalize((jd - 2451550.1) / 29.530588853)
    age = ip * 29.53

//} --- FUNCTION

// INIT     --- {

age = calcPhase(year, month, dayofmonth)
moon = 
     floor(age)[1] > floor(age) ? 1 : 
     floor(age)[1] < 15 and floor(age) >= 15 ? -1 : na

//} --- INIT

// PLOT     --- {

plotshape(
     moon==1, 
     "Full Moon", 
     shape.circle, 
     location.top, 
     color.new(newMoonColor, 20), 
     size=size.normal
     )   

plotshape(
     moon==-1, 
     "New Moon", 
     shape.circle, 
     location.bottom, 
     color.new(fullMoonColor, 20), 
     size=size.normal
     )   

var color col = na
if moon == 1 and fillBackground
    col := fullMoonBackgroundColor
if moon == -1 and fillBackground
    col := newMoonBackgroundColor
bgcolor(col, title="Moon Phase", transp=10)

//} --- PLOT


// STRATEGY     --- {

strategy = input("buy on new moon, sell on full moon", options=["buy on new moon, sell on full moon","sell on new moon, buy on full moon"])
longCond = strategy == "buy on new moon, sell on full moon" ? moon == -1 : moon == 1
shortCond = strategy == "buy on new moon, sell on full moon" ? moon == 1 : moon == -1

weAreInLongTrade = false
weAreInShortTrade = false
weAreInLongTrade := (longCond or weAreInLongTrade[1]) and shortCond == false
weAreInShortTrade := (shortCond or weAreInShortTrade[1]) and longCond == false
buySignal = longCond and weAreInLongTrade[1] == false
sellSignal = shortCond and weAreInShortTrade[1] == false

showBuySellSignals = input(defval=true, title = "Show Buy/Sell Signals")
longEnabled = input(true, title="Long enabled")
shortEnabled = input(true, title="Short enabled")

analysisStartYear = input(2017, "Backtesting From Year", minval=1980)
analysisStartMonth = input(1, "And Month", minval=1, maxval=12)
analysisStartDay = input(1, "And Day", minval=1, maxval=31)
analysisStartHour = input(0, "And Hour", minval=0, maxval=23)
analysisStartMinute = input(0, "And Minute", minval=0, maxval=59)
analyzeFromTimestamp = timestamp(analysisStartYear, analysisStartMonth, analysisStartDay, analysisStartHour, analysisStartMinute)

plotshape(showBuySellSignals and buySignal, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
plotshape(showBuySellSignals and sellSignal, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)

strategy.entry("long", strategy.long, when = time > analyzeFromTimestamp and buySignal and longEnabled)
strategy.entry("short", strategy.short, when = time > analyzeFromTimestamp and sellSignal and shortEnabled)
strategy.close("long", when = sellSignal)
strategy.close("short", when = buySignal)

//} --- STRATEGY


더 많은