재화 선물 R-Breaker 전략

저자:선함, 제작: 2020-06-02 08:57:10, 업데이트: 2023-11-02 19:52:44

img

요약

R-Breaker 전략은 리처드 사이든베르크가 개발하고 1994년에 발표하였다. 미국 퓨처스 트루트?? 매거진에 의해 15년 연속 가장 수익성이 높은 10대 거래 전략 중 하나로 선정되었다. 다른 전략과 비교하면, R-Breaker는 트렌드와 트렌드 역전을 결합한 거래 전략이다. 큰 이익을 얻기 위해 트렌드 시장을 포착할 수 있을 뿐만 아니라 시장 트렌드가 역전될 때, 이윤을 취하고 트렌드 역전을 추적할 수 있다.

저항과 지원

간단히 말해서, R-Breaker 전략은 가격 지원 및 저항 전략입니다. 그것은 어제의 최고, 최저 및 폐쇄 가격에 기초하여 7 개의 가격을 계산합니다: 중앙 가격 (피보트) 및 3 개의 지원 수준 (s1 s2, s3), 3 개의 저항 수준 (r1, r2, r3). 다음 현재 가격과 이러한 지원 및 저항 수준 사이의 위치 관계에 따라 구매 및 판매의 트리거 조건을 형성하고 특정 알고리즘 조정을 통해 이들 7 개의 가격 사이의 거리를 조정하여 거래의 트리거 값을 추가로 변경합니다.

  • 매수 가격 (항항상 수준 r3) 를 깨는 값 = 어제의 최고 가격 + 2 * (중심 가격 - 어제의 최저 가격) / 2

  • 판매 가격 관찰 (항항항 레벨 r2) = 중앙 가격 + (어젯밤의 최고 가격 - 어제의 최저 가격)

  • 역 판매 가격 (항항위 수준 r1) = 2 * 중앙 가격 - 어제의 최저 가격

  • 중앙 가격 (피보트) = (내일의 최고 가격 + 어제의 종료 가격 + 어제의 최저 가격) / 3

  • 역 구매 가격 (지원 수준 s1) = 2 * 중앙 가격 - 어제의 최고 가격

  • 관찰 구매 가격 (지원 수준 s2) = 중앙 가격 - (어제 최고 가격 - 어제 최저 가격)

  • 판매 가격 (지원 수준 s3) 를 깨는 것 = 어제의 최저 가격 - 2 * (어제의 최고 가격 - 중앙 가격)

이로부터 우리는 R-Breaker 전략이 어제의 가격에 기초하여 격자형 가격선을 그리며, 이러한 가격선을 하루에 한 번 업데이트한다는 것을 알 수 있습니다. 기술 분석에서 지원 및 저항 수준과 둘의 역할은 서로 변환 될 수 있습니다. 가격이 저항 수준을 성공적으로 깨면 저항 수준이 지원 수준이됩니다. 가격이 성공적으로 지원 수준을 깨면 지원 수준이 저항 수준이됩니다.

실제 거래에서 이러한 지원 및 저항 수준은 거래자에게 개시 및 폐쇄 지점의 방향과 정확한 거래 지점을 알려줍니다. 특정 개시 및 폐쇄 조건을 가진 거래자는 내일 가격, 중앙 가격, 저항 수준 및 지원 수준에 따라 유연하게 사용자 정의 할 수 있으며 또한 이러한 그리드 가격 라인에 기반한 포지션을 관리 할 수 있습니다.

전략 논리

다음으로, R-Breaker 전략이 이러한 지원 및 저항 수준을 어떻게 사용하는지 살펴보자. 그것의 논리는 전혀 복잡하지 않습니다. 보유 지위가 없다면 트렌드 모드에 입력하십시오. 가격이 파격 구매 가격보다 크면 긴 지위를 열고 가격이 파격 판매 가격보다 작을 때 짧은 지위를 열십시오.

  • 경향 모드

오픈 롱 포지션: 보유 포지션이 없으며 가격이 파격 구매 가격보다 높으면

오픈 쇼트 포지션: 보유 포지션이 없으며 가격이 파업 가격보다 낮다면

긴 포지션을 닫습니다. 만약 당신이 긴 포지션을 보유하고 있고, 하루의 최고 가격은 관찰 판매 가격보다 높고, 가격은 역 판매 가격보다 낮다면

짧은 포지션을 닫습니다: 당신이 짧은 포지션을 보유하고, 하루의 최저 가격이 관찰 구매 가격보다 낮고 가격이 역 구매 가격보다 높다면

  • 역행 모드

오픈 긴 위치: 당신이 짧은 위치를 보유하고, 하루의 최저 가격은 관찰 구매 가격보다 작고 가격이 역 구매 가격보다 크다면

오픈 쇼트 포지션: 만약 당신이 긴 포지션을 보유하고 있고, 하루의 최고 가격은 관찰 판매 가격보다 높고, 가격은 역 판매 가격보다 낮다면

긴 포지션을 닫는 경우: 긴 포지션이 유지되고 가격이 파헤팅 판매 가격보다 낮으면

포지션 종료: 포지션 종료 시 포지션 종료 시 포지션 종료 시 포지션 종료 시 포지션 종료 시 포지션 종료

홀딩 포지션이 있으면 역전 모드에 들어간다. 홀딩 롱 포지션이 있을 때, 하루의 가장 높은 가격이 관찰 판매 가격보다 높고 가격이 역전 판매 가격보다 낮아지면, 롱 포지션이 닫히고 짧은 포지션이 동기적으로 열릴 것이다. 홀딩 롱 포지션이 있을 때, 하루의 가장 낮은 가격이 관찰 구매 가격보다 낮고 가격이 역전 구매 가격을 넘어서면, 롱 포지션이 닫히고 긴 포지션이 열릴 것이다.

전략 작성

'''backtest
start: 2019-01-01 00:00:00
end: 2020-01-01 00:00:00
period: 5m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
'''

# Strategy main function
def onTick():
    # retrieve data
    exchange.SetContractType(contract_type)   # Subscribe to futures products
    bars_arr = exchange.GetRecords(PERIOD_D1)  # Get daily K line array
    if len(bars_arr) < 2:  # If the number of K lines is less than 2
        return
    yesterday_open = bars_arr[-2]['Open']     # Yesterday's opening price
    yesterday_high = bars_arr[-2]['High']     # Yesterday's highest price
    yesterday_low = bars_arr[-2]['Low']       # Yesterday's lowest price
    yesterday_close = bars_arr[-2]['Close']   # Yesterday's closing price

    # Calculation
    pivot = (yesterday_high + yesterday_close + yesterday_low) / 3 # Pivot point
    r1 = 2 * pivot - yesterday_low # Resistance level 1
    r2 = pivot + (yesterday_high - yesterday_low) # Resistance level 2
    r3 = yesterday_high + 2 * (pivot - yesterday_low) # Resistance level 3
    s1 = 2 * pivot - yesterday_high  # Support level 1
    s2 = pivot - (yesterday_high - yesterday_low)  # Support level 2
    s3 = yesterday_low - 2 * (yesterday_high - pivot)  # Support level 3

    today_high = bars_arr[-1]['High'] # Today's highest price
    today_low = bars_arr[-1]['Low'] # Today's lowest price
    current_price = _C(exchange.GetTicker).Last # Current price

    # Get positions
    position_arr = _C(exchange.GetPosition)  # Get array of positions
    if len(position_arr) > 0:  # If the position array length is greater than 0
        for i in position_arr:
            if i['ContractType'] == contract_type:  # If the position variety equals the subscription variety
                if i['Type'] % 2 == 0:  # If it is long position
                    position = i['Amount']  # The number of assigned positions is positive
                else:
                    position = -i['Amount']  # The number of assigned positions is negative
                profit = i['Profit']  # Get position profit and loss
    else:
        position = 0  # The number of assigned positions is 0
        profit = 0  # The value of the assigned position is 0
        
    if position == 0:  # If there is no position
        if current_price > r3:  # If the current price is greater than Resistance level 3
            exchange.SetDirection("buy")  # Set transaction direction and type
            exchange.Buy(current_price + 1, 1)  # open long position
        if current_price < s3:  # If the current price is less than Support level 3
            exchange.SetDirection("sell")  # Set transaction direction and type
            exchange.Sell(current_price - 1, 1)  # open short position
        
    if position > 0:  # if holding long position
        if today_high > r2 and current_price < r1 or current_price < s3:  # If today's highest price is greater than Resistance level 2, and the current price is less than Resistance level 1
            exchange.SetDirection("closebuy")  # Set transaction direction and type
            exchange.Sell(current_price - 1, 1)  # close long position
            exchange.SetDirection("sell")  # Set transaction direction and type
            exchange.Sell(current_price - 1, 1)  # open short position

    if position < 0:  # if holding short position
        if today_low < s2 and current_price > s1 or current_price > r3:  # If today's lowest price is less than Support level 2, and the current price is greater than Support level 1
            exchange.SetDirection("closesell")  # Set transaction direction and type
            exchange.Buy(current_price + 1, 1)  # close short position
            exchange.SetDirection("buy")  # Set transaction direction and type
            exchange.Buy(current_price + 1, 1)  # open long position

            
# Program main function
def main():
    while True:     # loop
        onTick()    # Execution strategy main function
        Sleep(1000) # Sleep for 1 second

전체 전략 복사

전체 전략은 FMZ 플랫폼에서 공개되었습니다 (FMZ.COM), 아래 링크를 클릭하여 직접 복사하면 구성 없이 백테스트를 할 수 있습니다:https://www.fmz.com/strategy/187009

요약

R-Breaker 전략이 인기를 끌고 있는 이유는 단순히 트렌드 추적 전략이 아니라 트렌드 알파와 역 알파 수익을 모두 얻는 복합 전략이기 때문이다. 이 문서의 전략은 적절한 매개 변수와 품종을 최적화하지 않고, 시범용일 뿐이다. 또한, 전체 전략에는 스톱 로스 기능도 포함되어야 하며, 관심 있는 친구들도 이를 개선할 수 있다.


관련

더 많은