크로스 페어 볼링거 밴드 크로스 오버 양적 전략

저자:차오장, 날짜: 2023-12-27 14:28:21
태그:

img

전반적인 설명

이 전략은 MACD 지표의 빠른 라인과 느린 라인의 크로스오버를 비교하여 구매 및 판매 신호를 생성합니다. 구매 신호가 생성되면 계정 자본의 특정 비율로 포지션을 열 것입니다. 추가 포지션은 특정 리트레이싱 포인트에 추가됩니다. 포지션의 축적 된 이익이 구성 된 수익점까지 도달하면 모든 포지션은 닫힐 것입니다. 판매 신호의 논리는 구매 신호와 유사합니다.

전략 논리

이 전략의 핵심 논리는 추세를 결정하기 위해 MACD 빠른 라인과 느린 라인의 교차점을 비교하는 것입니다. MACD는 이동 평균 사이의 차이이며, 단기 및 장기 이동 평균의 차이를 계산하여 시장 추세와 동력을 판단합니다. 빠른 라인과 느린 라인의 교차점은 황금 십자가와 죽음의 십자가로 간주됩니다.

빠른 선이 느린 선 위에 넘어가면, 시장이 상승 추세에 있음을 나타내는 황금색 십자가가 생성되며 전략은 긴 포지션을 열 것입니다. 빠른 선이 느린 선 아래에 넘어가면, 하락 추세를 나타내는 죽음의 십자가가 생성되며 전략은 짧은 포지션을 열 것입니다.

포지션 개척 후, 전략은 특정 리트레이싱 포인트에서 기존의 긴 또는 짧은 포지션에 추가됩니다. 이것은 마르틴게일 원리를 통해 수익 잠재력을 증가시킬 수 있습니다. 축적 된 이익이 구성된 수익점까지 도달하면 전략은 모든 포지션을 닫습니다.

이점 분석

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

  1. MACD 지표를 사용하여 고전적이고 신뢰할 수 있는 기술 분석 지표인 시장 동향을 결정합니다.

  2. 한 거래의 위험을 제어할 수 있는 대량으로 포지션을 개설하는 접근 방식을 채택합니다.

  3. 포지션을 추가하면 마틴게일 원리를 통해 수익 잠재력을 늘릴 수 있습니다.

  4. 손실을 제한하기 위해 수익점 설정

위험 분석

이 전략에는 또한 몇 가지 위험이 있습니다.

  1. MACD 지표는 시장 움직임을 완벽하게 예측할 수 없으며 잘못된 신호가 발생할 수 있습니다.

  2. 전체 포지션 추가와 함께 retrace 확대 될 위험이 있습니다. 추가 각 포지션의 비율을 적절히 조정 할 수 있습니다.

  3. 이윤을 너무 낮게 설정하면 이윤 잠재력을 제한할 수 있습니다. 다른 제품에 따라 조정할 수 있습니다.

  4. 계정 한계를 초과하지 않도록 제품별로 포지션을 개설하기 위해 자본의 합리적인 비율을 구성해야 합니다.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. MACD 매개 변수를 테스트하고 특정 거래 제품에 더 적합한 매개 변수를 찾습니다.

  2. 추가된 각 포지션에 대한 돈 비율과 리트레이싱 비율을 최적화하고 최적의 매개 변수 조합을 찾습니다.

  3. 최적의 수준을 결정하기 위해 장기 및 단기 수익점을 테스트합니다.

  4. 계좌의 마진 역량을 평가하고 상품별로 합리적인 최대 포지션 제한을 설정합니다.

  5. 스톱 로스 로직을 추가합니다. 스톱 로스는 급격한 시장 변화가 발생했을 때 손실을 효과적으로 제어 할 수 있습니다.

요약

요약하자면, 이것은 전형적인 트렌드 다음 전략이다. 시장 트렌드 방향을 결정하기 위해 MACD 지표를 사용하며, 추세를 따르기 위해 대량으로 포지션을 추가하는 접근 방식을 취하고, 축적된 이익이 특정 수준에 도달하면 수익을 취한다. 이 간단하고 실용적인 전략은 구현하기가 쉽고 양적 거래 초보자에게 적합합니다. 매개 변수를 최적화하고 위험 제어 논리를 확장함으로써 전략이 더 견고해질 수 있습니다.


/*backtest
start: 2023-11-26 00:00:00
end: 2023-12-26 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/
// © TradingSoft_tech

//@version=5
strategy("MAPM-V1", overlay=true, default_qty_value=10, max_bars_back=5000,default_qty_type = strategy.percent_of_equity, commission_value=0.1, initial_capital = 100, pyramiding=6, currency=currency.USD)

///////// Options
SignalFast = input.int(300, step=10)
SignalSlow = input.int(600, step=10)
StepAddPurchases = input.float(2.5, step=0.1)
VolumePurchases = input.int(6,step=1)
Buy = input(true)
Sell = input(true)
longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01
shortProfitPerc = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01
Martingale = input.float(1.6, minval = 1, step = 0.1)
VolumeDepo = input.int(100, step=1)
PercentOfDepo = input.float(10, step=1)
Close = (close)
EnterVolume = VolumeDepo*PercentOfDepo*0.01/Close

///////// Calculation indicator
fastAverage = ta.ema(close, 8)
slowAverage = ta.ema(close, 49)
macd = fastAverage - slowAverage
macdSignalF = ta.ema(macd,SignalFast)
macdSignalS = ta.ema(macd,SignalSlow)

// Test Start
startYear = input(2005, "Test Start Year")
startMonth = input(1, "Test Start Month")
startDay = input(1, "Test Start Day")
startTest = timestamp(startYear,startMonth,startDay,0,0)

//Test End
endYear = input(2050, "Test End Year")
endMonth = input(12, "Test End Month")
endDay = input(30, "Test End Day")
endTest = timestamp(endYear,endMonth,endDay,23,59)

timeRange = time > startTest and time < endTest ? true : false

///////// Plot Data
//plot(macd, style = plot.style_histogram)
//plot(macdSignalF*10000, style = plot.style_line, color=color.red)
//plot(macdSignalS*10000, style = plot.style_line, color=color.blue)
//plot(fastAverage, style = plot.style_line, color=color.red)
//plot(slowAverage, style = plot.style_line, color=color.blue)

///////// Calculation of the updated value
var x = 0.0
if strategy.opentrades>strategy.opentrades[1]
    x := x + 1
else if strategy.opentrades==0
    x := 0
y = x+1

///////// Calculation of reference price data
entryPrice = strategy.opentrades==0? 0 : strategy.opentrades.entry_price(0)
limitLong = strategy.position_avg_price * (1 + longProfitPerc)
limitShort = strategy.position_avg_price * (1 - shortProfitPerc)
SteplimitLong = entryPrice[0]*(1-StepAddPurchases*y/100)
SteplimitShort = entryPrice[0]*(1+StepAddPurchases*y/100)

///////// Conditions for a long
bool EntryLong = ta.crossover(macdSignalF, macdSignalS) and Buy and strategy.opentrades==0 and strategy.position_size==0
bool PurchasesLong = Buy and strategy.opentrades==x and strategy.position_size>0 and x<=VolumePurchases
bool CancelPurchasesLong = strategy.position_size==0 and strategy.opentrades==0
bool TPLong = strategy.position_size>0 and strategy.opentrades!=0
///////// Entry Long + add.purchases + cancel purchases + Take profit Long
switch 
    EntryLong => strategy.entry("Entry Long", strategy.long, qty = EnterVolume)
    PurchasesLong => strategy.entry("PurchasesLong", strategy.long, qty = EnterVolume*math.pow(Martingale,y), limit = SteplimitLong)
    CancelPurchasesLong => strategy.cancel("PurchasesLong")
switch
    TPLong => strategy.exit("TPLong", qty_percent = 100, limit = limitLong)

///////// Conditions for a Short
bool EntryShort = ta.crossunder(macdSignalF, macdSignalS) and Sell and strategy.opentrades==0 and strategy.position_size==0
bool PurchasesShort = Sell and strategy.opentrades==x and strategy.position_size<0 and x<=VolumePurchases
bool CancelPurchasesShort = strategy.position_size==0 and strategy.opentrades==0
bool TPShort = strategy.position_size<0 and strategy.opentrades!=0

///////// Entry Short + add.purchases + cancel purchases + Take profit Short
switch
    EntryShort => strategy.entry("Entry Short", strategy.short, qty = EnterVolume)
    PurchasesShort => strategy.entry("PurchasesShort", strategy.short, qty = EnterVolume*math.pow(Martingale,y), limit = SteplimitShort)
    CancelPurchasesShort => strategy.cancel("PurchasesShort")
switch
    TPShort => strategy.exit("TPShort", qty_percent = 100, limit = limitShort)
    
/////////Calculation of conditions and reference data for level drawing
InTradeLong = strategy.position_size<0
InTradeShort = strategy.position_size>0
PickInLong = strategy.opentrades.entry_price(0)*(1-StepAddPurchases*y/100)
PickInShort = strategy.opentrades.entry_price(0)*(1+StepAddPurchases*y/100)

/////////Displaying the level of Take Profit
plot(InTradeLong ? na : limitLong, color=color.new(#00d146, 0), style=plot.style_linebr, linewidth=1)
plot(InTradeShort ? na : limitShort, color=color.new(#00d146, 0), style=plot.style_linebr, linewidth=1)

/////////Displaying the level of add.purchases
plot(InTradeLong ? na : PickInLong, color=color.white, style=plot.style_linebr, linewidth=1)
plot(InTradeShort ? na : PickInShort, color=color.white, style=plot.style_linebr, linewidth=1)

더 많은