크로스 페리오드 돌파구 시스템

저자:차오장, 날짜: 2023-11-22 15:22:49
태그:

img

전반적인 설명

이것은 양적 거래 전략으로 이동 평균과 MACD 지표를 사용하여 두 방향으로 돌파구 작업을 수행합니다. 즉, 더 긴 시간 프레임에서 트렌드 방향을 판단하고 더 짧은 시간 프레임에서 기회를 찾습니다.

전략 원칙

이 전략은 트렌드 방향을 결정하기 위해 다른 길이의 3 SMMA 이동 평균과 1 EMA 이동 평균을 사용합니다. 동시에 단기 트렌드와 진입 기회를 판단하기 위해 MACD 지표를 결합합니다. 구체적으로, 구매 트리거 조건은: 가격이 모든 이동 평균을 상향으로 돌파하고 짧은 평균은 긴 평균보다 높습니다. 판매 트리거 조건은 반대로, 가격이 모든 이동 평균을 하향으로 돌파하고 짧은 평균은 긴 평균보다 낮습니다.

이 전략은 중장기 트렌드 방향을 판단하기 위해 이동 평균을 활용하고, MACD는 단기 반전을 판단함으로써 더 나은 진입 기회를 잡는 것을 볼 수 있습니다. 이 다중 시간 프레임 공동 작업은 전략의 중요한 특징입니다.

이점 분석

이 횡단 기간 거래의 장점은 높은 확률 트렌드 방향으로 진입하기 위해 적합한 단기 반전 지점을 선택할 수 있다는 것입니다. 따라서 더 나은 위험 / 보상 비율을 얻을 수 있습니다. 구체적으로 다음과 같은 3 가지 장점이 있습니다.

  1. 3개의 SMMA 평균과 1개의 EMA 라인 멀티 레벨 필터링은 중장기 트렌드 방향을 효과적으로 결정하여 트렌드에 반대되는 거래를 피할 수 있습니다.

  2. MACD 지표가 입상하기 위한 단기적 반전점을 판단하면 더 나은 입시 가격 수준을 얻을 수 있습니다.

  3. 필터링 조건으로 엄격한 이동 평균 순서 관계는 잘못된 동작의 가능성을 줄일 수 있습니다.

위험 분석

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

  1. 이동 평균 자체는 더 큰 지연 특성을 가지고 있으며, 단기 트렌드 역전 기회를 놓칠 수 있습니다.

  2. MACD 지표는 잘못된 신호를 생성하는 경향이 있으며 가격 수준과 함께 필터링되어야합니다.

  3. 다중 시간 프레임 판단은 전략의 복잡성을 증가시키고 실패에 유연합니다.

리스크 1과 리스크 2를 해결하기 위해 우리는 이동 평균과 신호 주기를 적절히 단축하여 단기 트렌드 반전에 신속하게 대응하여 최적화 할 수 있습니다. 리스크 3의 경우, 우리는 전략 매개 변수를 그 다양성의 특성에 엄격하게 조정하기 위해 다양한 품종과 주기를 최적화하고 테스트해야합니다.

최적화 방향

이 전략을 최적화 할 수 있는 주요 측면은 다음과 같습니다.

  1. 이동 평균 및 MACD의 매개 변수를 최적화하여 서로 다른 주기와 종류의 특성에 가장 잘 맞게하십시오. 이동 평균의 길이를 단축하거나 신호 매개 변수를 증가시키는 것과 같이.

  2. ATR 또는 다른 지표를 사용하여 합리적인 이동 스톱을 설정하는 스톱 로스 전략을 증가시킵니다. 이것은 전략의 위험 통제를 크게 향상시킬 수 있습니다.

  3. MACD 신호를 대체하기 위해 더 나은 지표 또는 필터링 방법을 찾으십시오. 예를 들어 변동성 지표를 도입하고 그에 따라 신호를 필터하십시오.

  4. 다른 이익과 손실 비율 관계를 테스트하여 더 나은 리스크-상금 비율을 가진 매개 변수 조합을 얻습니다.

요약

일반적으로, 이것은 크로스 타임프레임 사고를 가진 독특한 획기적인 시스템이다. 그것은 여러 시간 프레임에 걸쳐 공동 판단 운영 전략을 달성하기 위해 이동 평균과 MACD의 장점을 모두 활용합니다. 매개 변수 및 필터링 기준을 최적화하고 조정함으로써이 전략은 매우 실용적인 양적 거래 솔루션이 될 수 있습니다.


/*backtest
start: 2023-10-22 00:00:00
end: 2023-11-21 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/
// © SoftKill21

//@version=4
strategy("Koala Script",initial_capital=1000, 
     commission_type=strategy.commission.cash_per_contract, 
     commission_value=0.000065,
     slippage=3)
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2000, title = "From Year", minval = 1970)
 
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 8, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2031, title = "To Year", minval = 1970)
 


startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)




len = input(3, minval=1, title="Length")
src = input(hl2, title="Source")
smma = 0.0
sma1 = sma(src, len)
smma := na(smma[1]) ? sma1 : (smma[1] * (len - 1) + src) / len

len2 = input(6, minval=1, title="Length")
src2 = input(hl2, title="Source")
smma2 = 0.0
sma2 = sma(src2, len2)
smma2 := na(smma2[1]) ? sma2 : (smma2[1] * (len2 - 1) + src2) / len2

len3 = input(9, minval=1, title="Length")
src3 = input(hl2, title="Source")
smma3 = 0.0
sma3 = sma(src3, len3)
smma3 := na(smma3[1]) ? sma3 : (smma3[1] * (len3 - 1) + src3) / len3

len4 = input(50, minval=1, title="Length")
src4 = input(close, title="Source")
smma4 = 0.0
sma4 = sma(src4, len4)
smma4 := na(smma4[1]) ? sma4  : (smma4[1] * (len4 - 1) + src4) / len4

len5 = input(200, minval=1, title="Length")
src5 = input(close, title="Source")
out5 = ema(src5, len5)

timeinrange(res, sess) => time(res, sess) != 0
london=timeinrange(timeframe.period, "0300-1045")
londonEntry=timeinrange(timeframe.period, "0300-0845")

time_cond = time >= startDate and time <= finishDate and londonEntry

fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
srcc = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)


// Calculating
fast_ma = sma_source ? sma(srcc, fast_length) : ema(srcc, fast_length)
slow_ma = sma_source ? sma(srcc, slow_length) : ema(srcc, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal


longCond = close > out5 and close > smma4 and close > smma3 and close > smma2 and close > smma and londonEntry and smma > smma2 and smma2>smma3 and smma3>smma4 and smma4>out5 
shortCond = close < out5 and close < smma4 and close < smma3 and close < smma2 and close < smma and londonEntry and smma < smma2 and smma2<smma3 and smma3<smma4 and smma4<out5 
//longCond2 = crossover(close,out5) and crossover(close,smma4) and crossover(close,smma3) and crossover(close,smma2) and crossover(close,smma) and time_cond
//shortCond2 = crossunder(close,out5) and crossunder(close,smma4) and crossunder(close,smma3) and crossunder(close,smma2) and crossunder(close,smma) and time_cond

length=input(14, title="ATR Length")
mult=input(1.0, title="Percentage Multiplier (for ex., 0.7 = 70%)", step=0.1, minval=0.1, maxval=5.0)

oa=input(false, title="Show actual ATR")

ii=syminfo.pointvalue==0
s=ii?na:oa?atr(length):(syminfo.pointvalue * mult * atr(length))

tp=input(300,title="tp")
sl=input(300,title="sl")


//tp = s*10000
//sl= s*10000



//if(tp>300)
//    tp:=300
//if(sl>300)
//    sl:=300
//if(sl<150)
//    sl:=150
//if(tp<150)
//    tp:=150
strategy.initial_capital = 50000
//MONEY MANAGEMENT--------------------------------------------------------------''
balance = strategy.netprofit + strategy.initial_capital //current balance
floating = strategy.openprofit          //floating profit/loss
risk = input(3,type=input.float,title="Risk %")/100           //risk % per trade


    //Calculate the size of the next trade
temp01 = balance * risk     //Risk in USD
temp02 = temp01/sl        //Risk in lots
temp03 = temp02*100000      //Convert to contracts
size = temp03 - temp03%1000 //Normalize to 1000s (Trade size)
if(size < 10000)
    size := 10000           //Set min. lot size



strategy.entry("long",1,when=longCond )
strategy.exit("closelong","long", profit=tp,loss=sl)
//strategy.close("long",when= crossunder(close[4],smma4) and close[4] > close[3] and close[3]>close[2] and close[2] > close[1] and close[1] > close)
strategy.entry("short",0,when=shortCond )
strategy.exit("closeshort","short", profit=tp,loss=sl)
//strategy.close("short",when= crossover(close[4],smma4) and close[4] < close[3] and close[3]< close[2] and close[2] < close[1] and close[1] < close)

strategy.close_all(when = not london)

maxEntry=input(2,title="max entries")
// strategy.risk.max_intraday_filled_orders(maxEntry)

더 많은