R-Breaker Strategy for Commodity Futures

1. Summary

The R-Breaker strategy was developed by Richard Saidenberg and published in 1994.After that, it was ranked one of the top 10 most profitable trading strategies by Futures Truth magazine in the United States for 15 consecutive years.Compared with other strategies, R-Breaker is a combination of trend and reversal.Not only can you capture the trend and get Italian profits, but you can also take the initiative to stop profits and backtrack when the situation is reversed.

2. Resistance and Support Positions

Simply put, the R-Breaker strategy is a support and resistance level strategy, which calculates seven prices based on yesterday's highest, lowest and closing prices: one pivot, three support levels (s1, s2, s3), and three resistance levels (r1, r2, r3).Then, according to the position relationship between the current price and these support and resistance positions, to form trigger conditions for buying and selling, and adjust the distance between these seven prices through a certain algorithm to further change the trigger values of transactions.

  • Break-through purchase price (resistance level r3) = Yesterday's highest price + 2 * (center price - Yesterday's lowest price) 2
  • Observed Sell Price (Resistance Level r2) = Central Price+ (Yesterday's Highest Price - Yesterday's Lowest Price)
  • Reverse Sell Price (Resistance Level r1) = 2 * Central Price - Yesterday's Lowest Price
  • Pivot = Yesterday's highest price + Yesterday's closing price + Yesterday's lowest price) / 3
  • Reverse Buy Price (Support Level s1) = 2 * Central Price - Highest Price Yesterday
  • Observed Buy Price (Support s2) = Central Price - (Yesterday's Highest Price - Yesterday's Lowest Price)
  • Breakthrough Sell Price (Support Level s3) = Yesterday's Lowest Price - 2 * (Yesterday's Highest Price - Central Price)

As we can see, the R-Breaker strategy draws grid-like price lines based on yesterday's prices and updates them once a day.The support position and resistance position in technical analysis, and their roles can be converted to each other.When the price successfully breaks up the resistance level, the resistance level becomes the support level; when the price successfully breaks down the support level, the support level becomes the resistance level.

In the actual transaction, these support and resistance levels indicate the direction of opening the position and the exact trading point for the trader.Specific opening conditions traders can customize flexibly according to the price in the tray, center price, resistance level, support level, or add or reduce positions according to these grid price lines.

3. Strategic Logic

Next, let's see how the R-Breaker strategy uses these support and resistance positions.It has no complicated logic at all.If there is no open position at present, enter the trend mode, open more when the price is greater than the breakthrough purchase price, and open more when the price is less than the breakthrough sale price.

  • Trend pattern
    • Multi-open: If there is no open position and the price is greater than the breakthrough purchase price
    • Open short: If there is no open position and the price is less than the breakthrough selling price
    • Multiple-ended closing: If you hold multiple orders and the highest price on the day is greater than the observed selling price and the price is less than the reverse selling price
    • Short position closing: If a blank order is held and the lowest price on the day is less than the observed purchase price and the price is greater than the reverse purchase price
  • inversion mode
    • Open multi-ended: if you hold a blank order and the lowest price on the day is less than the observed purchase price and the price is greater than the reverse purchase price
    • Open short: If you hold multiple orders and the highest price on the day is greater than the observed selling price and the price is less than the reverse selling price
    • Multi-ended closing: If you hold multiple orders and the price is less than the breakthrough selling price
    • Short position closing: if you have a blank order and the price is greater than the breakthrough purchase price

If there is a position, enter the reversal mode. When holding multiple orders, and the highest price on the day is greater than the observed selling price, and the price falls below the reversal selling price, the multi-position is eliminated and the short-hand is made.When holding a blank order, and the lowest price on the day is less than the observed purchase price, and if the price breaks through the reverse purchase price, the short position will be eliminated and backhand will do more.

IV. Strategy Writing

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

# Policy Main Function
def onTick():
    # get data
    exchange.SetContractType(contract_type)   # Subscribe to futures
    bars_arr =exchange.GetRecords(PERIOD_D1)  # Get the K-line array of days
    if len(bars_arr) < 2:  # If the number of K lines is less than 2
        return
    yesterday_open = bars_arr[-2]['Open']     # Opening price yesterday
    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']   # Closing price yesterday

    # 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 1
    s2 = pivot - (yesterday_high - yesterday_low)  # Support Position 2
    s3 = yesterday_low - 2 * (yesterday_high - pivot)  # Support 3

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

    # Get hold
    position_arr = _C(exchange.GetPosition)  # Get Holding Array
    if len(position_arr) > 0:  # If the length of the holdings array is greater than 0
        for i in position_arr:
            if i['ContractType'] == contract_type:  # If the holding variety equals the subscription variety
                if i['Type'] % 2 == 0:  # If multiple orders
                    position = i['Amount']  # Positive number of assigned positions
                else:
                    position = -i['Amount']  # Number of assigned positions is negative
                profit = i['Profit']  # Acquire Warehouse Profit and Loss
    else:
        position = 0  # Number of assigned positions is 0
        profit = 0  # Valuated warehouse holding profit and loss is 0
        
    if position == 0:  # If no position is available
        if current_price > r3:  # If the current price is greater than resistance level 3
            exchange.SetDirection("buy")  # Set up direction and type of transaction
            exchange.Buy(current_price + 1, 1)  # Multiple Bills
        if current_price < s3:  # If the current price is less than support level 3
            exchange.SetDirection("sell")  # Set up direction and type of transaction
            exchange.Sell(current_price - 1, 1)  # Empty Order
        
    if position > 0:  # If holding multiple orders
        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 up direction and type of transaction
            exchange.Sell(current_price - 1, 1)  # Pingdao Single
            exchange.SetDirection("sell")  # Set up direction and type of transaction
            exchange.Sell(current_price - 1, 1)  # Backhand empty order

    if position < 0:  # If you have an empty bill
        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 up direction and type of transaction
            exchange.Buy(current_price + 1, 1)  # Blank sheet
            exchange.SetDirection("buy")  # Set up direction and type of transaction
            exchange.Buy(current_price + 1, 1)  # Backhand multiple order

            
# Program Main Function
def main():
    while True:     # loop
        onTick()    # Execution Policy Main Function
        Sleep(1000) # Hibernate for 1 second
        

5. Replication Complete Strategy

The complete strategy has been published to Inventor Quantification ( FMZ.COM ) Click on the link below to copy directly and test without configuring:
https://www.fmz.com/strategy/187009

6. Summary

The key to the popularity of the R-Breaker strategy is that it is not purely a trend-tracking strategy, but rather a composite strategy that earns both alpha of the trend and alpha of the reverse.The strategy in this article is just a demonstration. It does not optimize the appropriate parameters and varieties. In addition, the complete strategy must include stop loss function, which can be improved by interested friends.

Keywords: Blockchain less Hibernate

Added by maltech on Thu, 09 Apr 2020 06:00:53 +0300