
이중 MACD 양적 거래 전략은 이중 시간 프레임 MACD 지표를 활용하여 구현되는 양적 거래 전략이다. 이 전략은 순환선 MACD 지표가 골드 포크를 형성할 때 포즈를 더하고, 일선 MACD 지표가 데드 포크를 형성할 때 평소한다. 포지션이 빈 상태일 때, 일선 MACD 지표가 다시 골드 포크를 형성할 경우, 다시 포즈를 더하고 할 수 있다.
이중 MACD 양적 거래 전략은 주간 MACD 지표와 일일 MACD 지표의 조합을 사용하여 입시 및 출구 신호를 판단한다.
첫째, 주일 MACD 지표의 MACD 라인 상의 신호 라인을 통과할 때 구매 신호가 생성되어, 이 때 입장을 더하게 한다. 그리고 그 날 MACD 지표의 MACD 라인 아래의 신호 라인을 통과할 때 판매 신호가 생성되어, 이 때 입장을 평하게 한다.
포지션이 빈 상태일 때, 만약 MACD 지표의 MACD 라인이 다시 신호 라인을 뚫면, 다시 포지션을 한다. 즉, MACD 지표의 골드 포크가 다시 포지션을 시작하는 조건이 된다.
주의할 점은, 일일 MACD 지표의 데드포크가 평점으로 가는 것이지만, 주일 MACD 지표의 MACD 라인이 신호 라인보다 높을 수 있는 ?? 거래 창 ?? 안에서는 다시 포지션이 허용되어야 한다는 것이다.
이중 MACD 양적 거래 전략은 이중 시간 프레임 분석을 결합하여 가짜 신호를 효과적으로 필터링하여 신호의 품질을 향상시킬 수 있습니다. 구체적으로 다음과 같은 몇 가지 장점이 있습니다.
주간 시간 프레임은 주요 트렌드 방향을 판단하여 역동적인 거래를 피하는 데 도움이 됩니다.
일간 시간 프레임은 출입과 출퇴근 시간을 판단하여 단기 거래 기회를 적시에 잡을 수 있습니다.
거래 창 메커니즘은 단기 조정으로 인해 너무 자주 포지션을 열거나 평정하는 것을 피할 수 있습니다.
MACD 지표의 매개 변수는 조정할 수 있으며, 다른 품종과 시장 환경에 따라 최적화할 수 있다.
스톱, 스피드, 모바일 스피드 기능을 통합하여 위험을 효과적으로 제어할 수 있다.
이중 MACD 양적 거래 전략에는 다음과 같은 위험도 있습니다.
MACD 지표는 잘못된 신호를 발생시키고 자주 교차하며, 다른 지표의 조합이 확인되어야 한다.
주, 달, 시간 프레임 판단의 주요 추세는 전환될 수 있으며, 적시에 중단될 필요가 있다.
매개 변수는 다양한 품종과 시장 환경에 따라 지속적으로 최적화되고 조정되어야 합니다.
재검토 결과에 과도하게 의존해서는 안 되며, 실디 디스크는 재검토와 차이가 있을 수 있다.
대응방법:
다른 지표들과 함께 사용해서 논리적으로 최적화된 전략 시스템을 구축한다.
합리적인 스톱 손실을 설정하여 최대 손실을 피하십시오.
계속 최적화하고, 최적의 조합을 찾습니다.
최소한의 자금으로 시작하여 실전 투자가 가능하며, 전략의 안정성을 확인합니다.
이중 MACD 양적 거래 전략에는 더 많은 최적화가 가능합니다.
부린 라인, KDJ 등 다른 지표를 도입하여 다중 지표 조합 전략을 구축하고 신호 품질을 향상시킬 수 있다.
거래량 지표와 결합하여 가격 상승과 거래량이 부족한 가짜 돌파구를 피할 수 있습니다.
기계 학습 방법을 사용하여 매개 변수를 자동으로 최적화하여 매개 변수를 동적으로 조정할 수 있다.
전략에 대한 추가적인 위험조정이 가능하며, 손실비율과 같은 고급 중지 방법을 추가한다.
전략 적합성 검사 및 최적화 조정, 과도한 적합 문제를 피한다.
쌍MACD 양자 거래 전략은 쌍 시간 프레임 분석을 통합하여 주 및 부 동향을 판단하여 각 지표의 장점을 발휘합니다. 전략 최적화 공간은 여전히 넓고, 다른 지표를 도입하여 기계 학습을 사용하여 변수 최적화와 같은 방법을 통해 전략 효과를 더욱 향상시킬 수 있습니다. 실물 검증은 필수적인 단계이며 전략의 추가 개선을위한 중요한 근거입니다.
/*backtest
start: 2023-01-29 00:00:00
end: 2024-01-11 05:20:00
period: 1d
basePeriod: 1h
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/
// © maxits
// Long Position: Weekly Macd line crosses above Signal line
// [Trading Window Macd Line > Signal Line] (Weekly)
// Close Position: Daily Macd Line crosses above Daily Signal line.
// Re Entry Condition: Macd line crosses above Signal line only if [Trading Window MacdLine > Sgnal Line] (Weekly)
//@version=4
strategy("Dual MACD Strategy",
shorttitle="Dual Macd Tester",
overlay=false,
initial_capital=1000,
default_qty_value=20,
default_qty_type=strategy.percent_of_equity,
commission_value=0.1,
pyramiding=0)
// Define user inputs
i_time = input(defval = timestamp("01 May 2018 13:30 +0000"), title = "Start Time", type = input.time) // Starting time for Backtesting
f_time = input(defval = timestamp("9 Sep 2021 13:30 +0000"), title = "Finish Time", type = input.time) // Finishing time for Backtesting
sep1 = input(false, title="------ Profit & Loss ------")
enable_TP = input(true, title="Enable Just a Profit Level?")
enable_SL = input(false, title="Enable Just a S.Loss Level?")
enable_TS = input(true, title=" Enable Only Trailing Stop")
long_TP_Input = input(30.0, title='Take Profit %', type=input.float, minval=0)/100
long_SL_Input = input(1.0, title='Stop Loss %', type=input.float, minval=0)/100
long_TS_Input = input(5.0, title='Trailing Stop %', type=input.float, minval=0)/100
cl_low_Input = input(low, title="Trailing Stop Source")
long_TP = strategy.position_avg_price * (1 + long_TP_Input)
long_SL = strategy.position_avg_price * (1 - long_SL_Input)
long_TS = cl_low_Input * (1 - long_TS_Input)
sep2 = input(false, title="------ Macd Properties ------")
d_res = input(title="Short Term TimeFrame", type=input.resolution, defval="D") // Daily Time Frame
w_res = input(title="Long Term TimeFrame", type=input.resolution, defval="W") // Weekly Time Frame
src = input(close, title="Source") // Indicator Price Source
fast_len = input(title="Fast Length", type=input.integer, defval=12) // Fast MA Length
slow_len = input(title="Slow Length", type=input.integer, defval=26) // Slow MA Length
sign_len = input(title="Sign Length", type=input.integer, defval=9) // Sign MA Length
d_w = input(title="Daily or Weekly?", type=input.bool, defval=true) // Plot Daily or Weekly MACD
// Color Plot for Macd
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
// BG Color
bg_color = color.rgb(127, 232, 34, 75)
// Daily Macd
[d_macdLine, d_singleLine, d_histLine] = security(syminfo.tickerid, d_res, macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resolución
plot(d_w ? d_macdLine : na, color=color.blue)
plot(d_w ? d_singleLine : na, color=color.orange)
plot(d_w ? d_histLine : na, style=plot.style_columns,
color=(d_histLine>=0 ? (d_histLine[1] < d_histLine ? col_grow_above : col_fall_above) :
(d_histLine[1] < d_histLine ? col_grow_below : col_fall_below)))
// Weekly Macd
[w_macdLine, w_singleLine, w_histLine] = security(syminfo.tickerid, w_res, macd(src, fast_len, slow_len, sign_len)) // Funcion Security para poder usar correcta resolución
plot(d_w ? na : w_macdLine, color=color.blue)
plot(d_w ? na : w_singleLine, color=color.orange)
plot(d_w ? na : w_histLine, style=plot.style_columns,
color=(w_histLine>=0 ? (w_histLine[1] < w_histLine ? col_grow_above : col_fall_above) :
(w_histLine[1] < w_histLine ? col_grow_below : col_fall_below)))
///////////////////////////////// Entry Conditions
inTrade = strategy.position_size != 0 // Posición abierta
notInTrade = strategy.position_size == 0 // Posición Cerrada
start_time = true
trading_window = w_macdLine > w_singleLine // Weekly Macd Signal enables a trading window
bgcolor(trading_window ? bg_color : na)
buy_cond = crossover (w_macdLine, w_singleLine)
sell_cond = crossunder(d_macdLine, d_singleLine)
re_entry_cond = crossover (d_macdLine, d_singleLine) and trading_window
// Entry Exit Conditions
trailing_stop = 0.0 // Code for calculating Long Positions Trailing Stop Loss
trailing_stop := if (strategy.position_size != 0)
stopValue = long_TS
max(trailing_stop[1], stopValue)
else
0
if (buy_cond and notInTrade and start_time)
strategy.entry(id="First Entry", long=strategy.long, comment="First Long")
if (sell_cond and inTrade)
strategy.close(id="First Entry", comment="Close First Long")
if (re_entry_cond and notInTrade and start_time)
strategy.entry(id="Further Entry", long=strategy.long, comment="Further Entry")
if (sell_cond and inTrade)
strategy.close(id="Further Entry", comment="Close First Long")
if enable_TP
if (enable_TS and not enable_SL)
strategy.exit("Long TP & TS FiEn", "First Entry", limit = long_TP, stop = trailing_stop)
strategy.exit("Long TP & TS FuEn", "Further Entry", limit = long_TP, stop = trailing_stop)
else
if (enable_SL and not enable_TS)
strategy.exit("Long TP & TS FiEn", "First Entry", limit = long_TP, stop = long_SL)
strategy.exit("Long TP & TS FuEn", "Further Entry", limit = long_TP, stop = long_SL)
else
strategy.exit("Long TP & TS FiEn", "First Entry", limit = long_TP)
strategy.exit("Long TP & TS FuEn", "Further Entry", limit = long_TP)
else
if not enable_TP
if (enable_TS and not enable_SL)
strategy.exit("Long TP & TS FiEn", "First Entry", stop = trailing_stop)
strategy.exit("Long TP & TS FuEn", "Further Entry", stop = trailing_stop)
else
if (enable_SL and not enable_TS)
strategy.exit("Long TP & TS FiEn", "First Entry", stop = long_SL)
strategy.exit("Long TP & TS FuEn", "Further Entry", stop = long_SL)
plot(enable_TP ? long_TP : na, title="TP Level", color=color.green, style=plot.style_linebr, linewidth=2)
plot(enable_SL ? long_SL : na, title="SL Level", color=color.red, style=plot.style_linebr, linewidth=2)
plot(enable_TS and trailing_stop ? trailing_stop : na, title="TS Level", color=color.red, style=plot.style_linebr, linewidth=2)