Example #1
0
from freqtrade.tests.optimize import (BTContainer, BTrade,
                                      _build_backtest_dataframe,
                                      _get_frame_time_from_offset,
                                      tests_ticker_interval)

# Test 0: Sell with signal sell in candle 3
# Test with Stop-loss at 1%
tc0 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
        [1, 5000, 5025, 4975, 4987, 6172, 0,
         0],  # enter trade (signal on last candle)
        [2, 4987, 5012, 4986, 4600, 6172, 0, 0],  # exit with stoploss hit
        [3, 5010, 5000, 4980, 5010, 6172, 0, 1],
        [4, 5010, 4987, 4977, 4995, 6172, 0, 0],
        [5, 4995, 4995, 4995, 4950, 6172, 0, 0]
    ],
    stop_loss=-0.01,
    roi=1,
    profit_perc=0.002,
    use_sell_signal=True,
    trades=[
        BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=1, close_tick=4)
    ])

# Test 1: Stop-Loss Triggered 1% loss
# Test with Stop-loss at 1%
tc1 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
Example #2
0
    'date': 0,
    'buy': 1,
    'open': 2,
    'high': 3,
    'low': 4,
    'close': 5,
    'sell': 6,
    'volume': 7
}

# Open trade should be removed from the end
tc0 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
        [1, 5000, 5025, 4975, 4987, 6172, 0, 1]
    ],  # enter trade (signal on last candle)
    stop_loss=-0.99,
    roi=float('inf'),
    profit_perc=0.00,
    trades=[])

# Two complete trades within dataframe(with sell hit for all)
tc1 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
        [1, 5000, 5025, 4975, 4987, 6172, 0,
         1],  # enter trade (signal on last candle)
        [2, 5000, 5025, 4975, 4987, 6172, 0, 0],  # exit at open
        [3, 5000, 5025, 4975, 4987, 6172, 1, 0],  # no action
        [4, 5000, 5025, 4975, 4987, 6172, 0, 0],  # should enter the trade
Example #3
0
                                      _build_backtest_dataframe,
                                      _get_frame_time_from_offset,
                                      tests_ticker_interval)
from freqtrade.tests.conftest import patch_exchange

# Test 0 Minus 8% Close
# Test with Stop-loss at 1%
# TC1: Stop-Loss Triggered 1% loss
tc0 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
        [1, 5000, 5025, 4975, 4987, 6172, 0,
         0],  # enter trade (signal on last candle)
        [2, 4987, 5012, 4600, 4600, 6172, 0, 0],  # exit with stoploss hit
        [3, 4975, 5000, 4980, 4977, 6172, 0, 0],
        [4, 4977, 4987, 4977, 4995, 6172, 0, 0],
        [5, 4995, 4995, 4995, 4950, 6172, 0, 0]
    ],
    stop_loss=-0.01,
    roi=1,
    profit_perc=-0.01,
    trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)])

# Test 1 Minus 4% Low, minus 1% close
# Test with Stop-Loss at 3%
# TC2: Stop-Loss Triggered 3% Loss
tc1 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],