골든 크로스와 데스 크로스 더블 이동 평균 거래 전략


생성 날짜: 2023-12-01 14:36:33 마지막으로 수정됨: 2023-12-01 14:36:33
복사: 9 클릭수: 614
avatar of ChaoZhang ChaoZhang
1
집중하다
1619
수행원

골든 크로스와 데스 크로스 더블 이동 평균 거래 전략

개요

이중 평행 거래 전략은 다른 주기에서 지수 이동 평균을 계산하여 빠른 선과 느린 선을 형성하고 그들의 황금 포크와 죽은 포크 형태를 관찰하여 거래 신호를 생성합니다. 빠른 선이 아래에서 느린 선을 통과하면 더 많은 것을하고 빠른 선이 아래에서 느린 선을 통과하면 공백을 만듭니다. 이 전략은 평행 선의 트렌드 역점을 포착하며, 더 일반적인 트렌드 추적 전략입니다.

전략 원칙

양평선 거래 전략의 핵심 지표는 빠른 선과 느린 선을 계산하는 것이다. 빠른 선은 짧은 기간의 지수 이동 평균을 나타내고, 기본 파라미터는 12 일선이다. 느린 선은 긴 기간의 지수 이동 평균을 나타내고, 기본 파라미터는 26 일선이다. 지수 이동 평균의 계산 공식은 다음과 같다:

EMA(t) = (C(t) - EMA(t-1)) * SF + EMA(t-1)

그 중 C (t) 는 당일 종식 가격이고 SF는 부드러운 요인이다. 지수 이동 평균은 일반적인 수학 이동 평균과 다른 점은 지수 이동 평균은 최근의 데이터에 더 큰 무게를 부여하여 가격 변화에 더 빠르게 반응 할 수 있습니다.

이중 일률 전략의 거래 규칙은 다음과 같습니다.

  • 빠른 선이 아래에서 느린 선을 통과하면 골든 크로스 골든 포크가 형성되어 더 많은 진출을합니다.
  • 빠른 선이 위에서 아래로 느린 선을 통과할 때, 즉, 데드 크로스 사다리가 형성되고, 공백으로 진입한다.
  • 빠른 선과 느린 선이 갈라지면 평상시에서 출발한다.

Capture는 평행선의 교차형을 감시하고, 시장의 수요와 공급 관계의 변화와 동향에 신속하게 반응하여 수익을 창출합니다.

우위 분석

쌍방향 거래 전략은 보다 성숙한 기술 지표 전략으로서 다음과 같은 장점을 가지고 있다:

  1. 이 아이디어는 명확하고, 이해하기 쉽고, 실행할 수 있습니다.
  2. 시장의 수요와 공급에 대한 판단이 정확하고, 승률이 높습니다.
  3. 시장의 소음을 효과적으로 필터링하여 주요 트렌드를 포착합니다.
  4. 다른 시장과 시간 프레임에 적용할 수 있습니다.
  5. 다른 기술 지표와 결합하여 전략을 강화할 수 있습니다.
  6. 자금 활용률이 높아서 큰 자금 요구에 부합합니다.

위험 분석

이중 일선 거래 전략에는 몇 가지 단점과 위험도 있습니다.

  1. “이런 상황에서는 시장이 급격하게 성장하는 것을 막을 수 없습니다.
  2. 이 경우, 거래가 매우 밀집되어서 잘못된 신호가 발생하고, 작은 흔들림이 자주 발생한다.
  3. 다양한 품종과 시간적 순환에 맞춰 최적화해야 합니다.
  4. 이 트렌드 전환의 합리적인 위치를 판단할 수 없습니다.

위와 같은 위험에 대해, 평균주기 파라미터를 조정하거나, 부가적인 필터를 도입하는 등의 방법을 통해 최적화하여, 전략이 더 안정되도록 할 수 있다.

최적화 방향

쌍방향 거래 전략은 다음과 같은 측면에서 최적화될 수 있다.

  1. 강하고 약한 동향을 판단하는 MACD 지표를 도입하여 약하고 흔들리는 동향의 잘못된 거래를 피하십시오.
  2. 트레이딩 볼륨을 높여서 트렌드 반전의 가짜 브레이크를 방지하는 확인 지표로 사용한다.
  3. 브린 라인, K 라인 등과 같은 다른 기술 지표와 결합하여 더 정확한 입출장 조건을 설정합니다.
  4. LSTM와 같은 기계 학습 방법을 사용하여 평균 선 변수를 자동으로 최적화하여 더 나은 시장 적응성을 달성합니다.

요약하다

쌍평선 거래 전략은 평선의 황금 포크와 죽은 포크 거래 기회를 포착하여 가격 추세 반전 지점을 판단하여 안정적인 수익을 달성합니다. 이 전략의 장점은 간결하고 명확하며, 자본 효율성이 높으며, 양적 입문을위한 최고의 전략입니다. 그러나 가짜 신호를 생성하는 것과 같은 특정 결점도 있습니다. 특정 품종과 거래 환경에 더 잘 적응하도록 더 많은 지표를 도입하여 최적화해야합니다.

전략 소스 코드
/*backtest
start: 2022-11-24 00:00:00
end: 2023-11-30 00:00: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/
// © antondmt

//@version=5
strategy("Returns & Drawdowns Table", "R & DD", true, calc_on_every_tick = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, process_orders_on_close = true)
i_eq_to_dd =            input.string("Compound Equity", "Mode", ["Simple Equity", "Compound Equity", "Drawdown"], group = "R & DD Table")
i_precision =           input.int(2, "Return Precision", group = "R & DD Table")
i_headers_col =         input.color(#D4D4D4, "Headers Color", group = "R & DD Table")
i_headers_text_col =    input.color(color.black, "Headers Text Color", group = "R & DD Table")
i_pos_col =             input.color(color.green, "Positive Color", group = "R & DD Table")
i_neg_col =             input.color(color.red, "Negative Color", group = "R & DD Table")
i_zero_col =            input.color(#DDDDDD, "Zero Color", group = "R & DD Table")
i_cell_text_col =       input.color(color.white, "Cell Text Color", group = "R & DD Table")

// TIME {
var month_times = array.new_int(0)                                                              // Array of all month times  
new_month = month(time) != month(time[1]) 
if(new_month or barstate.isfirst)
    array.push(month_times, time)

var year_times = array.new_int(0)                                                               
new_year = year(time) != year(time[1])  
if (new_year or barstate.isfirst)
    array.push(year_times, time)
//}

// SIMPLE EQUITY CALCULATIONS {
// Simple equity is strictly calculated from start to end of each month/year equity. There is no compound
var monthly_simp_pnls = array.new_float(0)                                                      // Array of all monthly profits and losses
var yearly_simp_pnls = array.new_float(0)                                                       

if(i_eq_to_dd == "Simple Equity")
    var initial_monthly_equity = strategy.equity                                                // Starting equity for each month
    cur_month_pnl = nz((strategy.equity - initial_monthly_equity) / initial_monthly_equity)     // Current month's equity change
    if(new_month or barstate.isfirst)
        initial_monthly_equity := strategy.equity
        array.push(monthly_simp_pnls, cur_month_pnl)
    else 
        array.set(monthly_simp_pnls, array.size(monthly_simp_pnls) - 1, cur_month_pnl)
    
    var initial_yearly_equity = strategy.equity
    cur_year_pnl = nz((strategy.equity - initial_yearly_equity) / initial_yearly_equity)
    if (new_year or barstate.isfirst)
        initial_yearly_equity := strategy.equity
        array.push(yearly_simp_pnls, cur_year_pnl)
    else 
        array.set(yearly_simp_pnls, array.size(yearly_simp_pnls) - 1, cur_year_pnl)
// }

// COMPOUND EQUITY CALCULATIONS {
// Compound equity is strictly calculated based on equity state from the beginning of time until the end of each month/year equity. It shows the exact equity movement through time
var monthly_comp_pnls = array.new_float(0)                                                      // Array of all monthly profits and losses
var yearly_comp_pnls = array.new_float(0)                                                       

if(i_eq_to_dd == "Compound Equity")
    var initial_equity = strategy.equity                                                
    cur_month_pnl = nz((strategy.equity - initial_equity) / initial_equity)                     // Current month's equity change
    if(new_month or barstate.isfirst)
        array.push(monthly_comp_pnls, cur_month_pnl)
    else 
        array.set(monthly_comp_pnls, array.size(monthly_comp_pnls) - 1, cur_month_pnl)
    
    cur_year_pnl = nz((strategy.equity - initial_equity) / initial_equity)
    if (new_year or barstate.isfirst)
        array.push(yearly_comp_pnls, cur_year_pnl)
    else 
        array.set(yearly_comp_pnls, array.size(yearly_comp_pnls) - 1, cur_year_pnl)
// }
    
// DRAWDOWN CALCULATIONS {
// Drawdowns are calculated from highest equity to lowest trough for the month/year
var monthly_dds = array.new_float(0)                                                            // Array of all monthly drawdowns
var yearly_dds = array.new_float(0)                                                             

if (i_eq_to_dd == "Drawdown")
    total_equity = strategy.equity - strategy.openprofit                        
    
    var cur_month_dd = 0.0  
    var m_ATH = total_equity                                                                    // Monthly All-Time-High (ATH). It is reset each month
    m_ATH := math.max(total_equity, nz(m_ATH[1]))
    m_drawdown = -math.abs(total_equity / m_ATH * 100 - 100) / 100                              // Drawdown at current bar
    if(m_drawdown < cur_month_dd)
        cur_month_dd := m_drawdown
    if(new_month or barstate.isfirst)
        cur_month_dd := 0.0
        m_ATH := strategy.equity - strategy.openprofit
        array.push(monthly_dds, 0)
    else 
        array.set(monthly_dds, array.size(monthly_dds) - 1, cur_month_dd)
    
    var cur_year_dd = 0.0
    var y_ATH = total_equity
    y_ATH := math.max(total_equity, nz(y_ATH[1]))
    y_drawdown = -math.abs(total_equity / y_ATH * 100 - 100) / 100
    if(y_drawdown < cur_year_dd)
        cur_year_dd := y_drawdown
    if (new_year or barstate.isfirst)
        cur_year_dd := 0.0
        y_ATH := strategy.equity - strategy.openprofit
        array.push(yearly_dds, 0)
    else 
        array.set(yearly_dds, array.size(yearly_dds) - 1, cur_year_dd) 
// }

// TABLE LOGIC { 
var main_table = table(na)
table.clear(main_table, 0, 0, 13, new_year ? array.size(year_times) - 1 : array.size(year_times))
main_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_times) + 1, border_width = 1)

t_set_headers() =>                                                                              // Sets time headers of the table
    // Set month headers
    table.cell(main_table, 0,  0, "",     text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 1,  0, "Jan",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 2,  0, "Feb",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 3,  0, "Mar",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 4,  0, "Apr",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 5,  0, "May",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 6,  0, "Jun",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 7,  0, "Jul",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 8,  0, "Aug",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 9,  0, "Sep",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 10, 0, "Oct",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 11, 0, "Nov",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 12, 0, "Dec",  text_color = i_headers_text_col, bgcolor = i_headers_col)
    table.cell(main_table, 13, 0, str.tostring(i_eq_to_dd), text_color = i_headers_text_col, bgcolor = i_headers_col)

    // Set year headers
    for i = 0 to array.size(year_times) - 1
        table.cell(main_table, 0,  i + 1, str.tostring(year(array.get(year_times, i))), text_color = i_headers_text_col, bgcolor = i_headers_col)

t_set_months() =>                                                                               // Sets inner monthly data of the table
    display_array = switch i_eq_to_dd 
        "Simple Equity" => monthly_simp_pnls 
        "Compound Equity" => monthly_comp_pnls
        => monthly_dds
    for i = 0 to array.size(month_times) - 1
        m_row = year(array.get(month_times, i)) - year(array.get(year_times, 0)) + 1
        m_col = month(array.get(month_times, i)) 
        m_color = array.get(display_array, i) == 0 ? color.new(i_zero_col, transp = 30) : array.get(display_array, i) > 0 ? color.new(i_pos_col, transp = 30) : color.new(i_neg_col, transp = 30)
        table.cell(main_table, m_col, m_row, str.tostring(math.round(array.get(display_array, i) * 100, i_precision)), bgcolor = m_color, text_color = i_cell_text_col)
        
t_set_years() =>                                                                                // Sets inner yearly data of the table
    display_array = switch i_eq_to_dd 
        "Simple Equity" => yearly_simp_pnls 
        "Compound Equity" => yearly_comp_pnls
        => yearly_dds
    for i = 0 to array.size(year_times) - 1
        y_color = array.get(display_array, i) == 0 ? color.new(i_zero_col, transp = 30) : array.get(display_array, i) > 0 ? color.new(i_pos_col, transp = 20) : color.new(i_neg_col, transp = 20)
        table.cell(main_table, 13, i + 1, str.tostring(math.round(array.get(display_array, i) * 100, i_precision)), bgcolor = y_color, text_color = i_cell_text_col)

t_set_headers() 
t_set_months()
t_set_years()
// }

// PLACE YOUR STRATEGY CODE HERE {
// This is a sample code of a working strategy to show the table in action
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
if (ta.crossover(delta, 0))
	strategy.entry("MacdLE", strategy.long, comment = "MacdLE")
if (ta.crossunder(delta, 0))
	strategy.entry("MacdSE", strategy.short, comment = "MacdSE")
// }