Example #1
0
    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
        [5, 5000, 5025, 4975, 4987, 6172, 0, 1],  # no action
        [6, 5000, 5025, 4975, 4987, 6172, 0, 0],  # should sell
    ],
    stop_loss=-0.99,
    roi={"0": float('inf')},
    profit_perc=0.00,
    trades=[
        BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=1, close_tick=2),
        BTrade(exit_reason=ExitType.EXIT_SIGNAL, open_tick=4, close_tick=6)
    ])

# 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss
tc2 = BTContainer(
    data=[
        # D  O     H     L     C     V    B  S
        [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
        [1, 5000, 5025, 4600, 4987, 6172, 0, 0],  # enter trade, stoploss hit
        [2, 5000, 5025, 4975, 4987, 6172, 0, 0],
    ],
    stop_loss=-0.01,
    roi={"0": float('inf')},
    profit_perc=-0.01,
    trades=[BTrade(exit_reason=ExitType.STOP_LOSS, open_tick=1, close_tick=1)])
Example #2
0
    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, 4986, 6172, 0, 0],  # exit with stoploss hit
        [3, 5010, 5010, 4980, 5010, 6172, 0, 1],
        [4, 5010, 5011, 4977, 4995, 6172, 0, 0],
        [5, 4995, 4995, 4950, 4950, 6172, 0, 0]
    ],
    stop_loss=-0.01,
    roi={"0": 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],
        [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, 4975, 4977, 6172, 0, 0],
        [4, 4977, 4995, 4977, 4995, 6172, 0, 0],
        [5, 4995, 4995, 4950, 4950, 6172, 0, 0]
    ],
Example #3
0
from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
                            _get_frame_time_from_offset, tests_timeframe)


# 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={"0": 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],
    [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={"0": 1}, profit_perc=-0.01,
    trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)]
)
Example #4
0
    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
    [5, 5000, 5025, 4975, 4987, 6172, 0, 1],  # no action
    [6, 5000, 5025, 4975, 4987, 6172, 0, 0],  # should sell
],
    stop_loss=-0.99, roi={"0": float('inf')}, profit_perc=0.00,
    trades=[BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=1, close_tick=2),
            BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=4, close_tick=6)]
)

# 3) Entered, sl 1%, candle drops 8% => Trade closed, 1% loss
tc2 = BTContainer(data=[
    # D  O     H     L     C     V    B  S
    [0, 5000, 5025, 4975, 4987, 6172, 1, 0],
    [1, 5000, 5025, 4600, 4987, 6172, 0, 0],  # enter trade, stoploss hit
    [2, 5000, 5025, 4975, 4987, 6172, 0, 0],
],
    stop_loss=-0.01, roi={"0": float('inf')}, profit_perc=-0.01,
    trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
)

# 4) Entered, sl 3 %, candle drops 4%, recovers to 1 % = > Trade closed, 3 % loss
    data=[
        # D   O     H     L     C    V    EL XL ES Xs  BT
        [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, 4986, 6172, 0, 0],  # exit with stoploss hit
        [3, 5010, 5010, 4980, 5010, 6172, 0, 1],
        [4, 5010, 5011, 4977, 4995, 6172, 0, 0],
        [5, 4995, 4995, 4950, 4950, 6172, 0, 0]
    ],
    stop_loss=-0.01,
    roi={"0": 1},
    profit_perc=0.002,
    use_exit_signal=True,
    trades=[
        BTrade(exit_reason=ExitType.EXIT_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    EL XL ES Xs  BT
        [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, 4975, 4977, 6172, 0, 0],
        [4, 4977, 4995, 4977, 4995, 6172, 0, 0],
        [5, 4995, 4995, 4950, 4950, 6172, 0, 0]
    ],