사자 균열 균형 전략

저자:차오장, 날짜: 2023-11-02 16:55:00
태그:

img

전반적인 설명

사자 균열 균형 전략은 이동 평균 크로스오버를 기반으로 한 간단한 단기 거래 전략이다. 주로 두 개의 이동 평균을 사용합니다. 빠른 MA가 밑에서 느린 MA보다 높을 때 길게 이동합니다. 빠른 MA가 위에서 느린 MA보다 낮을 때 포지션을 닫습니다. 전략 이름은 인기있는 거래 용어 사자 균열에서 유래하여 소규모 가격 행동을 캡처하고 MA 사이의 좁은 격차에서 이익을 얻음을 의미합니다.

전략 논리

이 전략은 두 개의 이동 평균을 사용합니다: 빠른 MA (smallMAPeriod) 및 느린 MA (bigMAPeriod). 두 개의 MA는 가격 채널을 형성하며, 빠른 MA는 채널 기반이며 느린 MA는 채널 천장입니다. 가격이 채널 기반 이상으로 넘어지면 길게 이동합니다. 가격이 채널 천장을 넘어지면 닫습니다.

구체적으로, 전략은 먼저 빠른 MA (smallMA) 와 느린 MA (bigMA) 를 계산합니다. 그 다음 느린 MA의 (100-percentBelowToBuy) %인 구매 라인 (buyMA) 을 계산합니다. 빠른 MA가 구매 라인 위로 넘을 때 길게 이동합니다. 1%의 이익에 도달하거나 수익없이 7 바를 보유하면 포지션을 닫습니다.

요약하자면, 전략은 단기 수익을 위해 MAs 사이의 "사자 균열"을 포착하는 것을 목표로합니다. 또한 거래 위험을 제어하기 위해 수익 취득 및 중단 손실 조건을 설정합니다.

이점 분석

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

  1. 이해하기 쉽고 구현하기 쉬운 간단한 개념입니다. 이중 MA 크로스오버는 가장 기본적인 기술 지표 전략입니다.

  2. 쉬운 백테스팅. 전략은 추가 구현 없이 직접 트레이딩뷰 내장 백테스터를 사용합니다.

  3. 강력한 시각화. 트레이딩뷰는 직접 차트에 무역 신호와 통계 데이터를 표시 할 수 있습니다.

  4. 통제 가능한 위험. 전략은 거래 손실을 효과적으로 제어하기 위해 수익을 취하고 손실을 멈추는 조건을 설정합니다.

  5. 유연한 사용자 지정. 사용자는 다른 제품과 거래 스타일에 맞게 MA 매개 변수 및 기타 지표를 조정할 수 있습니다.

위험 분석

이 전략은 또한 다음과 같은 위험을 가지고 있습니다.

  1. 잠재적으로 과도한 신호입니다. 이중 MA 전략은 통합 중에 잘못된 신호를 생성하는 경향이 있습니다.

  2. 단일 지표 의존성: MA 크로스만 사용하면 다른 요인을 무시하여 신호 품질이 떨어질 수 있습니다.

  3. 어려운 매개 변수 최적화. 최적의 MA 조합을 찾는 것은 광범위한 계산이 필요합니다.

  4. 백테스트 편향. 간단한 듀얼 MA 전략은 종종 라이브 거래보다 백테스트에서 더 잘 수행됩니다.

  5. 어려운 스톱 로스: 고정 스톱 로스 레벨은 변화하는 시장 조건에 적응하지 못할 수 있습니다.

최적화 방향

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

  1. 부피와 변동성 같은 다른 필터를 추가하여 통합 중에 비효율적인 신호를 피합니다.

  2. 트렌드 편향을 포함하여 역 트렌드 거래를 피합니다. 트렌드 방향을 결정하기 위해 더 긴 기간 MAs를 추가 할 수 있습니다.

  3. 기계 학습을 이용하여 최적의 매개 변수를 찾습니다. 예를 들어 순차적인 매개 변수 최적화나 유전 알고리즘 같은 것이죠.

  4. 더 나은 유연성을 위해 후속 스톱 손실과 적응 스톱 손실과 같은 스톱 손실 전략을 개선하십시오.

  5. 더 높은 확률의 진입 지점을 식별하기 위해 다른 지표를 사용하여 진입 시기를 최적화하십시오.

  6. 최적화된 매개 변수 집합의 안정성을 향상시키기 위해 정량적 연구와 백테스팅을 수행합니다.

  7. 패러미터 조합을 체계적으로 최적화하고 평가하기 위한 자동화 거래 시스템을 개발합니다.

결론

사자 균열 균형 전략은 초보자가 배울 수있는 훌륭한 시작 전략입니다. 간단한 이중 MA 크로스오버 논리를 적용하고 단기 가격 변동을 포착하기 위해 이익 취득 및 손실 중지 규칙을 설정합니다. 전략은 이해하기 쉽고 실행하며 좋은 백테스트 결과를 보여줍니다. 그러나 최적화 어려움과 의문스러운 라이브 성능으로 고통 받고 있습니다. 다른 지표, 매개 변수 최적화 및 자동화 거래 시스템을 개발함으로써 전략을 개선 할 수 있습니다. 전반적으로 사자 균열 균형 전략은 양적 거래 초보자에게 훌륭한 학습 플랫폼을 제공합니다.


/*backtest
start: 2023-10-02 00:00:00
end: 2023-11-01 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/
// © TraderHalai
// This script was born out of my quest to be able to display strategy back test statistics on charts to allow for easier backtesting on devices that do not natively support backtest engine (such as mobile phones, when I am backtesting from away from my computer). There are already a few good ones on TradingView, but most / many are too complicated for my needs.
//
//Found an excellent display backtest engine by 'The Art of Trading'. This script is a snippet of his hard work, with some very minor tweaks and changes. Much respect to the original author.
//
//Full credit to the original author of this script. It can be found here: https://www.tradingview.com/script/t776tkZv-Hammers-Stars-Strategy/?offer_id=10&aff_id=15271
//
// This script can be copied and airlifted onto existing strategy scripts of your own, and integrates out of the box without implementation of additional functions. I've also added Max Runup, Average Win and Average Loss per trade to the orignal script.
//
//Will look to add in more performance metrics in future, as I further develop this script.
//
//Feel free to use this display panel in your scripts and strategies.

//Thanks and enjoy! :)
//@version=5
// strategy("Strategy BackTest Display Statistics - TraderHalai", overlay=true, default_qty_value= 5, default_qty_type = strategy.percent_of_equity, initial_capital=10000,  commission_type=strategy.commission.percent, commission_value=0.1)

//DEMO basic strategy - Use your own strategy here -  Jaws Mean Reversion from my profile used here
source = input(title = "Source", defval = close)
smallMAPeriod = input(title = "Small Moving Average", defval = 2)
bigMAPeriod = input(title = "Big Moving Average", defval = 8)
percentBelowToBuy = input(title = "Percent below to buy %", defval = 1)

smallMA = ta.sma(source, smallMAPeriod)
bigMA =  ta.sma(source, bigMAPeriod) 
buyMA = ((100 - percentBelowToBuy) / 100) * ta.sma(source, bigMAPeriod)[0]

buy = ta.crossunder(smallMA, buyMA)
if(buy)
    strategy.entry("BUY", strategy.long)

if(strategy.openprofit >= strategy.position_avg_price * 0.01) // 1% profit target
    strategy.close("BUY")

if(ta.barssince(buy) >= 7) //Timed Exit, if you fail to make 1 percent in 7 candles.
    strategy.close("BUY")
    
///////////////////////////// --- BEGIN TESTER CODE --- ////////////////////////
// COPY below into your strategy to enable display
////////////////////////////////////////////////////////////////////////////////

// strategy.initial_capital = 50000
// // Declare performance tracking variables
// drawTester = input.bool(true, "Draw Tester")
// var balance = strategy.initial_capital
// var drawdown = 0.0
// var maxDrawdown = 0.0
// var maxBalance = 0.0
// var totalWins = 0
// var totalLoss = 0

// // Prepare stats table
// var table testTable = table.new(position.top_right, 5, 2, border_width=1)
// f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>
//     _cellText = _title + "\n" + _value
//     table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor)
    
// // Custom function to truncate (cut) excess decimal places
// truncate(_number, _decimalPlaces) =>
//     _factor = math.pow(10, _decimalPlaces)
//     int(_number * _factor) / _factor
    
// // Draw stats table
// var bgcolor = color.new(color.black,0)
// if drawTester
//     if barstate.islastconfirmedhistory
//         // Update table
//         dollarReturn = strategy.netprofit
//         f_fillCell(testTable, 0, 0, "Total Trades:", str.tostring(strategy.closedtrades), bgcolor, color.white)
//         f_fillCell(testTable, 0, 1, "Win Rate:", str.tostring(truncate((strategy.wintrades/strategy.closedtrades)*100,2)) + "%", bgcolor, color.white)
//         f_fillCell(testTable, 1, 0, "Starting:", "$" + str.tostring(strategy.initial_capital), bgcolor, color.white)
//         f_fillCell(testTable, 1, 1, "Ending:", "$" + str.tostring(truncate(strategy.initial_capital + strategy.netprofit,2)), bgcolor, color.white)
//         f_fillCell(testTable, 2, 0, "Avg Win:", "$"+ str.tostring(truncate(strategy.grossprofit / strategy.wintrades, 2)), bgcolor, color.white)
//         f_fillCell(testTable, 2, 1, "Avg Loss:", "$"+ str.tostring(truncate(strategy.grossloss / strategy.losstrades, 2)), bgcolor, color.white)
//         f_fillCell(testTable, 3, 0, "Profit Factor:", str.tostring(truncate(strategy.grossprofit / strategy.grossloss,2)), strategy.grossprofit > strategy.grossloss ? color.green : color.red, color.white)
//         f_fillCell(testTable, 3, 1, "Max Runup:",  str.tostring(truncate(strategy.max_runup, 2 )), bgcolor, color.white)
//         f_fillCell(testTable, 4, 0, "Return:", (dollarReturn > 0 ? "+" : "") + str.tostring(truncate((dollarReturn / strategy.initial_capital)*100,2)) + "%", dollarReturn > 0 ? color.green : color.red, color.white)
//         f_fillCell(testTable, 4, 1, "Max DD:", str.tostring(truncate((strategy.max_drawdown / strategy.equity) * 100 ,2)) + "%", color.red, color.white)
// // --- END TESTER CODE --- ///////////////

더 많은