단계적 피라미딩 이동 평균 브레이크업 전략

저자:차오장, 날짜: 2024-02-05 14:09:14
태그:

img

전반적인 설명

이 전략은 시장 방향을 결정하기 위해 현재 클로즈 가격과 이전 클로즈 가격의 비교를 기반으로 단계적 피라미드 접근 방식을 사용합니다. 긴 기회가 확인되면 여러 점진적 엔트리로 길게됩니다. 짧은 기회가 확인되면 여러 점진적 엔트리로 짧게됩니다. 엔트리의 수는 매개 변수를 통해 설정할 수 있습니다. 동시에 전략에는 시간 프레임 필터가 포함되어 있으며 거래 신호는 구성된 거래 시간 프레임 내에서만 생성됩니다.

전략 논리

  1. 현재 바의 닫기 가격 (close) 을 이전 바의 닫기 가격 (close[1]) 과 비교한다. 닫기 > 닫는 경우[1], 그것은 긴 기회로 결정되고 longCondition=1을 설정한다. 닫기 < 닫는 경우[1], 그것은 짧은 기회로 결정되고 shortCondition=1을 설정한다.

  2. 허용된 거래 기간 내에, longCondition=1이라면, 여러 점진적 엔트리로 롱이 됩니다. shortCondition=1라면, 여러 점진적 엔트리로 롱이 됩니다.

  3. 엔트리 수는 피라미드 매개 변수를 통해 설정되며, 1에서 5까지 구성할 수 있으며, 기본은 4입니다.

  4. 시장이 역전될 경우 매 입시에 스톱 로스 조건이 설정됩니다.

  5. 거래 신호는 토스트 또는 텔레그램과 같은 다른 거래 인터페이스로 출력 될 수 있습니다.

이 전략은 주로 브레이크아웃 및 이동 평균 전략의 장점을 고려합니다. 긴 또는 짧은 기회 동안, 위험을 제어하면서 트렌드를 더 잘 따라가기 위해 단계적 피라미드 접근 방식을 사용합니다. 또한 주요 거래 세션이 아닌 동안 신호를 생성하지 않도록 시간 프레임 필터를 통합합니다.

이점 분석

  1. 단계적인 피라미딩은 추세를 더 잘 따라갑니다.

  2. 입력 수를 조절할 수 있어 더 유연합니다.

  3. 확장성을 위해 다른 거래 인터페이스를 지원합니다.

  4. 위험을 통제하기 위한 스톱 로스 메커니즘이 있습니다.

  5. 시간 프레임 필터는 잘못된 신호를 피합니다.

위험 분석

  1. 부적절한 매개 변수 설정은 더 큰 손실로 이어질 수 있습니다.

  2. 네트워크 문제로 인해 제때 중단 손실이 발생할 수 있습니다.

  3. 매개 변수들은 다른 제품들에 따라 조정되어야 합니다.

  4. 적시에 손해를 막아야 이윤을 얻을 수 있습니다.

해결책:

  1. 기본 4개의 항목이 적절합니다.

  2. 네트워크 연결을 확인해

  3. 제품 특성에 따라 매개 변수를 조정합니다.

  4. 손해를 막는 레벨을 설정해

최적화 방향

  1. 신호 강도를 판단하기 위해 더 많은 지표를 추가하는 것을 고려하십시오.

  2. 다른 제품에서 테스트 매개 변수 최적화 결과

  3. 매개 변수를 최적화하기 위해 기계 학습 알고리즘을 통합합니다.

  4. 위험 관리 메커니즘을 강화합니다.

요약

이 단계적 피라미드화 이동 평균 브레이크아웃 전략은 트렌드 추적 및 위험 통제의 장점을 통합합니다. 효과적인 신호가 확인되면 구성 가능한 엔트리 수를 통해 위험 노출을 제어하는 동안 트렌드를 따라 단계적 피라미드를 사용합니다. 또한 잘못된 신호를 피하기 위해 시간 프레임 필터와 같은 기능을 통합합니다. 전략은 많은 측면에서 더 이상 최적화 될 수 있으며 확장성이 있습니다. 일반적으로 트렌딩 제품에 매우 효과적이며 강력하게 권장됩니다.


/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © torresbitmex

//@version=5
strategy("torres_strategy_real_test_v1.0", process_orders_on_close=true, overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.03, calc_on_order_fills=false, pyramiding=4)

in_trade(int start_time, int end_time) =>    
    allowedToTrade = (time>=start_time) and (time<=end_time)
    if barstate.islastconfirmedhistory
        var myLine = line(na)
        line.delete(myLine)
        myLine := line.new(start_time, low, start_time, high, xloc=xloc.bar_time, color = color.rgb(255, 153, 0, 50), width = 3, extend = extend.both, style = line.style_dashed)
    allowedToTrade

// 매매시간세팅
start_time = input(timestamp("31 Jan 2024 00:00 +0900"), title="매매 시작", group='매매 시간세팅')
end_time = input(timestamp("31 Dec 2030 00:00 +0900"), title="매매 종료", group='매매 시간세팅')
start_trade = true
bgcolor(start_trade ? color.new(color.gray, 90)   : color(na))


var bool Alarm_TVExtbot = false
var bool Alarm_Alert = false

bot_mode = input.string(title='봇선택', defval = "POA", options = ["TVEXTBOT", "POA"], group = "봇선택", inline = '1')
if bot_mode == "TVEXTBOT"
    Alarm_TVExtbot := true
else if bot_mode == "POA"
    Alarm_Alert := true
else
    Alarm_TVExtbot := false
    Alarm_Alert := false

// 계정정보
account = input.string(title='계정', defval='아무거나입력', inline='1', group='계정정보')
token = input.string(title='TVExtBot 인증키', defval='', inline='1', group='계정정보')

mul_input = input.float(4, minval=1, maxval=5, step=1, title="분할진입수", group='진입 세팅', inline='1')
// 진입주문메세지입력
buyOrderid = input.string(title='롱 진입1', defval='', group='진입주문 메세지입력', inline='2')
buyOrderid2 = input.string(title='롱 진입2', defval='', group='진입주문 메세지입력', inline='3')
buyOrderid3 = input.string(title='롱 진입3', defval='', group='진입주문 메세지입력', inline='4')
buyOrderid4 = input.string(title='롱 진입4', defval='', group='진입주문 메세지입력', inline='5')
buyOrderid5 = input.string(title='롱 진입5', defval='', group='진입주문 메세지입력', inline='6')
sellOrderid = input.string(title='숏 진입1', defval='', group='진입주문 메세지입력', inline='2')
sellOrderid2 = input.string(title='숏 진입2', defval='', group='진입주문 메세지입력', inline='3')
sellOrderid3 = input.string(title='숏 진입3', defval='', group='진입주문 메세지입력', inline='4')
sellOrderid4 = input.string(title='숏 진입4', defval='', group='진입주문 메세지입력', inline='5')
sellOrderid5 = input.string(title='숏 진입5', defval='', group='진입주문 메세지입력', inline='6')

// 종료주문메세지입력
buycloseOrderid = input.string(title='롱 전체종료', defval='', group='종료주문 메세지입력', inline='1')
sellcloseOrderid = input.string(title='숏 전체종료', defval='', group='종료주문 메세지입력', inline='1')

longCondition = 0, shortCondition = 0

if(close[1] < close)
    longCondition := 1
else
    longCondition := 0
if(close[1] > close)
    shortCondition := 1
else
    shortCondition := 0

if start_trade
    if Alarm_Alert
        if strategy.position_size == 0
            if (longCondition == 1)
                strategy.entry("buy1", strategy.long, alert_message = buyOrderid)

            if (shortCondition == 1)
                strategy.entry("sell1", strategy.short, alert_message = sellOrderid)

        if strategy.position_size > 0
            if (longCondition == 1)
                if (strategy.opentrades == 1) and (mul_input == 2 or mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("buy2", strategy.long, alert_message = buyOrderid2)  
                if (strategy.opentrades == 2) and (mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("buy3", strategy.long, alert_message = buyOrderid3)  
                if (strategy.opentrades == 3) and (mul_input == 4 or mul_input == 5)
                    strategy.entry("buy4", strategy.long, alert_message = buyOrderid4)  
                if (strategy.opentrades == 4) and (mul_input == 5)
                    strategy.entry("buy5", strategy.long, alert_message = buyOrderid5)  

        if strategy.position_size < 0
            if (shortCondition == 1)
                if (strategy.opentrades == 1) and (mul_input == 2 or mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("sell2", strategy.short, alert_message = sellOrderid2)  
                if (strategy.opentrades == 2) and (mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("sell3", strategy.short, alert_message = sellOrderid3)  
                if (strategy.opentrades == 3) and (mul_input == 4 or mul_input == 5)
                    strategy.entry("sell4", strategy.short, alert_message = sellOrderid4)
                if (strategy.opentrades == 4) and (mul_input == 5)
                    strategy.entry("sell5", strategy.short, alert_message = sellOrderid5)

        if (longCondition == 1 and strategy.position_size > 0)
            if mul_input == 1 and strategy.opentrades == 1
                strategy.close_all(comment='롱전체종료', alert_message = buycloseOrderid)
            if mul_input == 2 and strategy.opentrades == 2
                strategy.close_all(comment='롱전체종료', alert_message = buycloseOrderid)
            if mul_input == 3 and strategy.opentrades == 3
                strategy.close_all(comment='롱전체종료', alert_message = buycloseOrderid)
            if mul_input == 4 and strategy.opentrades == 4
                strategy.close_all(comment='롱전체종료', alert_message = buycloseOrderid)
            if mul_input == 5 and strategy.opentrades == 5
                strategy.close_all(comment='롱전체종료', alert_message = buycloseOrderid)
        if (shortCondition == 1 and strategy.position_size < 0)
            if mul_input == 1 and strategy.opentrades == 1
                strategy.close_all(comment='숏전체종료', alert_message = sellcloseOrderid)
            if mul_input == 2 and strategy.opentrades == 2
                strategy.close_all(comment='숏전체종료', alert_message = sellcloseOrderid)
            if mul_input == 3 and strategy.opentrades == 3
                strategy.close_all(comment='숏전체종료', alert_message = sellcloseOrderid)
            if mul_input == 4 and strategy.opentrades == 4
                strategy.close_all(comment='숏전체종료', alert_message = sellcloseOrderid)
            if mul_input == 5 and strategy.opentrades == 5
                strategy.close_all(comment='숏전체종료', alert_message = sellcloseOrderid)
    else if Alarm_TVExtbot
        if strategy.position_size == 0
            if (longCondition == 1)
                strategy.entry("buy1", strategy.long, alert_message = '롱 1차 진입 📈📈 TVM:{"orderid":"' + buyOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')

            if (shortCondition == 1)
                strategy.entry("sell1", strategy.short, alert_message = '숏 1차 진입 📉📉 TVM:{"orderid":"' + sellOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')

        if strategy.position_size > 0
            if (longCondition == 1)
                if (strategy.opentrades == 1) and (mul_input == 2 or mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("buy2", strategy.long, alert_message = '롱 2차 진입 📈📈 TVM:{"orderid":"' + buyOrderid2 + '","memo":"' + account + '","token":"' + token + '"}:MVT')  
                if (strategy.opentrades == 2) and (mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("buy3", strategy.long, alert_message = '롱 3차 진입 📈📈 TVM:{"orderid":"' + buyOrderid3 + '","memo":"' + account + '","token":"' + token + '"}:MVT')  
                if (strategy.opentrades == 3) and (mul_input == 4 or mul_input == 5)
                    strategy.entry("buy4", strategy.long, alert_message = '롱 4차 진입 📈📈 TVM:{"orderid":"' + buyOrderid4 + '","memo":"' + account + '","token":"' + token + '"}:MVT')  
                if (strategy.opentrades == 4) and (mul_input == 5)
                    strategy.entry("buy5", strategy.long, alert_message = '롱 5차 진입 📈📈 TVM:{"orderid":"' + buyOrderid5 + '","memo":"' + account + '","token":"' + token + '"}:MVT') 

        if strategy.position_size < 0
            if (shortCondition == 1)
                if (strategy.opentrades == 1) and (mul_input == 2 or mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("sell2", strategy.short, alert_message = '숏 2차 진입 📉📉 TVM:{"orderid":"' + sellOrderid2 + '","memo":"' + account + '","token":"' + token + '"}:MVT')  
                if (strategy.opentrades == 2) and (mul_input == 3 or mul_input == 4 or mul_input == 5)
                    strategy.entry("sell3", strategy.short, alert_message = '숏 3차 진입 📉📉 TVM:{"orderid":"' + sellOrderid3 + '","memo":"' + account + '","token":"' + token + '"}:MVT')  
                if (strategy.opentrades == 3) and (mul_input == 4 or mul_input == 5)
                    strategy.entry("sell4", strategy.short, alert_message = '숏 4차 진입 📉📉 TVM:{"orderid":"' + sellOrderid4 + '","memo":"' + account + '","token":"' + token + '"}:MVT')
                if (strategy.opentrades == 4) and (mul_input == 5)
                    strategy.entry("sell5", strategy.short, alert_message = '숏 5차 진입 📉📉 TVM:{"orderid":"' + sellOrderid5 + '","memo":"' + account + '","token":"' + token + '"}:MVT')
        
        if (longCondition == 1 and strategy.position_size > 0)
            if mul_input == 1 and strategy.opentrades == 1
                strategy.close_all(comment='롱전체종료', alert_message = '롱 종료 📈⛔TVM:{"orderid":"' + buycloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 2 and strategy.opentrades == 2
                strategy.close_all(comment='롱전체종료', alert_message = '롱 종료 📈⛔TVM:{"orderid":"' + buycloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 3 and strategy.opentrades == 3
                strategy.close_all(comment='롱전체종료', alert_message = '롱 종료 📈⛔TVM:{"orderid":"' + buycloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 4 and strategy.opentrades == 4
                strategy.close_all(comment='롱전체종료', alert_message = '롱 종료 📈⛔TVM:{"orderid":"' + buycloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 5 and strategy.opentrades == 5
                strategy.close_all(comment='롱전체종료', alert_message = '롱 종료 📈⛔TVM:{"orderid":"' + buycloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')            
        if (shortCondition == 1 and strategy.position_size < 0)
            if mul_input == 1 and strategy.opentrades == 1
                strategy.close_all(comment='숏전체종료', alert_message = '숏 종료 📉⛔TVM:{"orderid":"' + sellcloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 2 and strategy.opentrades == 2
                strategy.close_all(comment='숏전체종료', alert_message = '숏 종료 📉⛔TVM:{"orderid":"' + sellcloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 3 and strategy.opentrades == 3
                strategy.close_all(comment='숏전체종료', alert_message = '숏 종료 📉⛔TVM:{"orderid":"' + sellcloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 4 and strategy.opentrades == 4
                strategy.close_all(comment='숏전체종료', alert_message = '숏 종료 📉⛔TVM:{"orderid":"' + sellcloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')
            if mul_input == 5 and strategy.opentrades == 5
                strategy.close_all(comment='숏전체종료', alert_message = '숏 종료 📉⛔TVM:{"orderid":"' + sellcloseOrderid + '","memo":"' + account + '","token":"' + token + '"}:MVT')

  

더 많은