fix backtest testcase

This commit is contained in:
kevinjulian 2021-07-20 23:25:00 +07:00
parent c558fc0b17
commit cbfedf8b29
4 changed files with 238 additions and 218 deletions

View File

@ -30,7 +30,7 @@ BT_DATA_COLUMNS = ['pair', 'stake_amount', 'amount', 'open_date', 'close_date',
'fee_open', 'fee_close', 'trade_duration', 'fee_open', 'fee_close', 'trade_duration',
'profit_ratio', 'profit_abs', 'sell_reason', 'profit_ratio', 'profit_abs', 'sell_reason',
'initial_stop_loss_abs', 'initial_stop_loss_ratio', 'stop_loss_abs', 'initial_stop_loss_abs', 'initial_stop_loss_ratio', 'stop_loss_abs',
'stop_loss_ratio', 'min_rate', 'max_rate', 'is_open', ] 'stop_loss_ratio', 'min_rate', 'max_rate', 'is_open', 'buy_signal_name']
def get_latest_optimize_filename(directory: Union[Path, str], variant: str) -> str: def get_latest_optimize_filename(directory: Union[Path, str], variant: str) -> str:

View File

@ -453,6 +453,8 @@ class Backtesting:
row_index = indexes[pair] row_index = indexes[pair]
try: try:
row = data[pair][row_index] row = data[pair][row_index]
print('weeee')
print(row)
except IndexError: except IndexError:
# missing Data for one pair at the end. # missing Data for one pair at the end.
# Warnings for this are shown during data loading # Warnings for this are shown during data loading

View File

@ -18,6 +18,7 @@ class BTrade(NamedTuple):
sell_reason: SellType sell_reason: SellType
open_tick: int open_tick: int
close_tick: int close_tick: int
buy_signal_name: Optional[str] = ''
class BTContainer(NamedTuple): class BTContainer(NamedTuple):
@ -43,7 +44,7 @@ def _get_frame_time_from_offset(offset):
def _build_backtest_dataframe(data): def _build_backtest_dataframe(data):
columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'buy', 'sell'] columns = ['date', 'open', 'high', 'low', 'close', 'volume', 'buy', 'sell', 'buy_signal_name']
frame = DataFrame.from_records(data, columns=columns) frame = DataFrame.from_records(data, columns=columns)
frame['date'] = frame['date'].apply(_get_frame_time_from_offset) frame['date'] = frame['date'].apply(_get_frame_time_from_offset)

View File

@ -14,13 +14,13 @@ from tests.optimize import (BTContainer, BTrade, _build_backtest_dataframe,
# Test 0: Sell with signal sell in candle 3 # Test 0: Sell with signal sell in candle 3
# Test with Stop-loss at 1% # Test with Stop-loss at 1%
tc0 = BTContainer(data=[ tc0 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [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 [2, 4987, 5012, 4986, 4600, 6172, 0, 0, ''], # exit with stoploss hit
[3, 5010, 5000, 4980, 5010, 6172, 0, 1], [3, 5010, 5000, 4980, 5010, 6172, 0, 1, ''],
[4, 5010, 4987, 4977, 4995, 6172, 0, 0], [4, 5010, 4987, 4977, 4995, 6172, 0, 0, ''],
[5, 4995, 4995, 4995, 4950, 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, 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)] trades=[BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=1, close_tick=4)]
) )
@ -28,13 +28,13 @@ tc0 = BTContainer(data=[
# Test 1: Stop-Loss Triggered 1% loss # Test 1: Stop-Loss Triggered 1% loss
# Test with Stop-loss at 1% # Test with Stop-loss at 1%
tc1 = BTContainer(data=[ tc1 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [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 [2, 4987, 5012, 4600, 4600, 6172, 0, 0, ''], # exit with stoploss hit
[3, 4975, 5000, 4980, 4977, 6172, 0, 0], [3, 4975, 5000, 4980, 4977, 6172, 0, 0, ''],
[4, 4977, 4987, 4977, 4995, 6172, 0, 0], [4, 4977, 4987, 4977, 4995, 6172, 0, 0, ''],
[5, 4995, 4995, 4995, 4950, 6172, 0, 0]], [5, 4995, 4995, 4995, 4950, 6172, 0, 0, '']],
stop_loss=-0.01, roi={"0": 1}, profit_perc=-0.01, stop_loss=-0.01, roi={"0": 1}, profit_perc=-0.01,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)] trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)]
) )
@ -43,13 +43,13 @@ tc1 = BTContainer(data=[
# Test 2: Minus 4% Low, minus 1% close # Test 2: Minus 4% Low, minus 1% close
# Test with Stop-Loss at 3% # Test with Stop-Loss at 3%
tc2 = BTContainer(data=[ tc2 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5012, 4962, 4975, 6172, 0, 0], [2, 4987, 5012, 4962, 4975, 6172, 0, 0, ''],
[3, 4975, 5000, 4800, 4962, 6172, 0, 0], # exit with stoploss hit [3, 4975, 5000, 4800, 4962, 6172, 0, 0, ''], # exit with stoploss hit
[4, 4962, 4987, 4937, 4950, 6172, 0, 0], [4, 4962, 4987, 4937, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.03, roi={"0": 1}, profit_perc=-0.03, stop_loss=-0.03, roi={"0": 1}, profit_perc=-0.03,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=3)]
) )
@ -62,14 +62,14 @@ tc2 = BTContainer(data=[
# Trade-A: Stop-Loss Triggered 2% Loss # Trade-A: Stop-Loss Triggered 2% Loss
# Trade-B: Stop-Loss Triggered 2% Loss # Trade-B: Stop-Loss Triggered 2% Loss
tc3 = BTContainer(data=[ tc3 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5012, 4800, 4975, 6172, 0, 0], # exit with stoploss hit [2, 4987, 5012, 4800, 4975, 6172, 0, 0, ''], # exit with stoploss hit
[3, 4975, 5000, 4950, 4962, 6172, 1, 0], [3, 4975, 5000, 4950, 4962, 6172, 1, 0, ''],
[4, 4975, 5000, 4950, 4962, 6172, 0, 0], # enter trade 2 (signal on last candle) [4, 4975, 5000, 4950, 4962, 6172, 0, 0, ''], # enter trade 2 (signal on last candle)
[5, 4962, 4987, 4000, 4000, 6172, 0, 0], # exit with stoploss hit [5, 4962, 4987, 4000, 4000, 6172, 0, 0, ''], # exit with stoploss hit
[6, 4950, 4975, 4975, 4950, 6172, 0, 0]], [6, 4950, 4975, 4975, 4950, 6172, 0, 0, '']],
stop_loss=-0.02, roi={"0": 1}, profit_perc=-0.04, stop_loss=-0.02, roi={"0": 1}, profit_perc=-0.04,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2), trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2),
BTrade(sell_reason=SellType.STOP_LOSS, open_tick=4, close_tick=5)] BTrade(sell_reason=SellType.STOP_LOSS, open_tick=4, close_tick=5)]
@ -80,13 +80,13 @@ tc3 = BTContainer(data=[
# Test with Stop-loss at 2% ROI 6% # Test with Stop-loss at 2% ROI 6%
# Stop-Loss Triggered 2% Loss # Stop-Loss Triggered 2% Loss
tc4 = BTContainer(data=[ tc4 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5750, 4850, 5750, 6172, 0, 0], # Exit with stoploss hit [2, 4987, 5750, 4850, 5750, 6172, 0, 0, ''], # Exit with stoploss hit
[3, 4975, 5000, 4950, 4962, 6172, 0, 0], [3, 4975, 5000, 4950, 4962, 6172, 0, 0, ''],
[4, 4962, 4987, 4937, 4950, 6172, 0, 0], [4, 4962, 4987, 4937, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.02, roi={"0": 0.06}, profit_perc=-0.02, stop_loss=-0.02, roi={"0": 0.06}, profit_perc=-0.02,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)] trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)]
) )
@ -94,13 +94,13 @@ tc4 = BTContainer(data=[
# Test 5: Drops 0.5% Closes +20%, ROI triggers 3% Gain # Test 5: Drops 0.5% Closes +20%, ROI triggers 3% Gain
# stop-loss: 1%, ROI: 3% # stop-loss: 1%, ROI: 3%
tc5 = BTContainer(data=[ tc5 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4980, 4987, 6172, 1, 0], [0, 5000, 5025, 4980, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4980, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4980, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5025, 4975, 4987, 6172, 0, 0], [2, 4987, 5025, 4975, 4987, 6172, 0, 0, ''],
[3, 4975, 6000, 4975, 6000, 6172, 0, 0], # ROI [3, 4975, 6000, 4975, 6000, 6172, 0, 0, ''], # ROI
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.01, roi={"0": 0.03}, profit_perc=0.03, stop_loss=-0.01, roi={"0": 0.03}, profit_perc=0.03,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -108,13 +108,13 @@ tc5 = BTContainer(data=[
# Test 6: Drops 3% / Recovers 6% Positive / Closes 1% positve, Stop-Loss triggers 2% Loss # Test 6: Drops 3% / Recovers 6% Positive / Closes 1% positve, Stop-Loss triggers 2% Loss
# stop-loss: 2% ROI: 5% # stop-loss: 2% ROI: 5%
tc6 = BTContainer(data=[ tc6 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5300, 4850, 5050, 6172, 0, 0], # Exit with stoploss [2, 4987, 5300, 4850, 5050, 6172, 0, 0, ''], # Exit with stoploss
[3, 4975, 5000, 4950, 4962, 6172, 0, 0], [3, 4975, 5000, 4950, 4962, 6172, 0, 0, ''],
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.02, roi={"0": 0.05}, profit_perc=-0.02, stop_loss=-0.02, roi={"0": 0.05}, profit_perc=-0.02,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)] trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=2)]
) )
@ -122,13 +122,13 @@ tc6 = BTContainer(data=[
# Test 7: 6% Positive / 1% Negative / Close 1% Positve, ROI Triggers 3% Gain # Test 7: 6% Positive / 1% Negative / Close 1% Positve, ROI Triggers 3% Gain
# stop-loss: 2% ROI: 3% # stop-loss: 2% ROI: 3%
tc7 = BTContainer(data=[ tc7 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
[2, 4987, 5300, 4950, 5050, 6172, 0, 0], [2, 4987, 5300, 4950, 5050, 6172, 0, 0, ''],
[3, 4975, 5000, 4950, 4962, 6172, 0, 0], [3, 4975, 5000, 4950, 4962, 6172, 0, 0, ''],
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.02, roi={"0": 0.03}, profit_perc=0.03, stop_loss=-0.02, roi={"0": 0.03}, profit_perc=0.03,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=2)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=2)]
) )
@ -137,12 +137,12 @@ tc7 = BTContainer(data=[
# Test 8: trailing_stop should raise so candle 3 causes a stoploss. # Test 8: trailing_stop should raise so candle 3 causes a stoploss.
# stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted in candle 2 # stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted in candle 2
tc8 = BTContainer(data=[ tc8 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5000, 6172, 0, 0], [1, 5000, 5050, 4950, 5000, 6172, 0, 0, ''],
[2, 5000, 5250, 4750, 4850, 6172, 0, 0], [2, 5000, 5250, 4750, 4850, 6172, 0, 0, ''],
[3, 4850, 5050, 4650, 4750, 6172, 0, 0], [3, 4850, 5050, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.055, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.055, trailing_stop=True,
trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=3)]
) )
@ -151,12 +151,12 @@ tc8 = BTContainer(data=[
# Test 9: trailing_stop should raise - high and low in same candle. # Test 9: trailing_stop should raise - high and low in same candle.
# stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted in candle 3 # stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted in candle 3
tc9 = BTContainer(data=[ tc9 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5000, 6172, 0, 0], [1, 5000, 5050, 4950, 5000, 6172, 0, 0, ''],
[2, 5000, 5050, 4950, 5000, 6172, 0, 0], [2, 5000, 5050, 4950, 5000, 6172, 0, 0, ''],
[3, 5000, 5200, 4550, 4850, 6172, 0, 0], [3, 5000, 5200, 4550, 4850, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.064, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.064, trailing_stop=True,
trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=3)]
) )
@ -165,12 +165,12 @@ tc9 = BTContainer(data=[
# without applying trailing_stop_positive since stoploss_offset is at 10%. # without applying trailing_stop_positive since stoploss_offset is at 10%.
# stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2 # stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2
tc10 = BTContainer(data=[ tc10 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 5100, 5100, 6172, 0, 0], [2, 5100, 5251, 5100, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4650, 4750, 6172, 0, 0], [3, 4850, 5050, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.1, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.1, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.10, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.10,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -181,12 +181,12 @@ tc10 = BTContainer(data=[
# applying a positive trailing stop of 3% since stop_positive_offset is reached. # applying a positive trailing stop of 3% since stop_positive_offset is reached.
# stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2 # stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2
tc11 = BTContainer(data=[ tc11 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 5100, 5100, 6172, 0, 0], [2, 5100, 5251, 5100, 5100, 6172, 0, 0, ''],
[3, 5000, 5150, 4650, 4750, 6172, 0, 0], [3, 5000, 5150, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=0.019, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=0.019, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -197,12 +197,12 @@ tc11 = BTContainer(data=[
# applying a positive trailing stop of 3% since stop_positive_offset is reached. # applying a positive trailing stop of 3% since stop_positive_offset is reached.
# stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2 # stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2
tc12 = BTContainer(data=[ tc12 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 4650, 5100, 6172, 0, 0], [2, 5100, 5251, 4650, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4650, 4750, 6172, 0, 0], [3, 4850, 5050, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=0.019, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=0.019, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -212,12 +212,12 @@ tc12 = BTContainer(data=[
# Test 13: Buy and sell ROI on same candle # Test 13: Buy and sell ROI on same candle
# stop-loss: 10% (should not apply), ROI: 1% # stop-loss: 10% (should not apply), ROI: 1%
tc13 = BTContainer(data=[ tc13 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5100, 4950, 5100, 6172, 0, 0], [1, 5000, 5100, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 4850, 5100, 6172, 0, 0], [2, 5100, 5251, 4850, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4850, 4750, 6172, 0, 0], [3, 4850, 5050, 4850, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4850, 4750, 6172, 0, 0]], [4, 4750, 4950, 4850, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.01}, profit_perc=0.01, stop_loss=-0.10, roi={"0": 0.01}, profit_perc=0.01,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=1)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=1)]
) )
@ -225,12 +225,12 @@ tc13 = BTContainer(data=[
# Test 14 - Buy and Stoploss on same candle # Test 14 - Buy and Stoploss on same candle
# stop-loss: 5%, ROI: 10% (should not apply) # stop-loss: 5%, ROI: 10% (should not apply)
tc14 = BTContainer(data=[ tc14 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5100, 4600, 5100, 6172, 0, 0], [1, 5000, 5100, 4600, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 4850, 5100, 6172, 0, 0], [2, 5100, 5251, 4850, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4850, 4750, 6172, 0, 0], [3, 4850, 5050, 4850, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.05, roi={"0": 0.10}, profit_perc=-0.05, stop_loss=-0.05, roi={"0": 0.10}, profit_perc=-0.05,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)] trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=1)]
) )
@ -239,12 +239,12 @@ tc14 = BTContainer(data=[
# Test 15 - Buy and ROI on same candle, followed by buy and Stoploss on next candle # Test 15 - Buy and ROI on same candle, followed by buy and Stoploss on next candle
# stop-loss: 5%, ROI: 10% (should not apply) # stop-loss: 5%, ROI: 10% (should not apply)
tc15 = BTContainer(data=[ tc15 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5100, 4900, 5100, 6172, 1, 0], [1, 5000, 5100, 4900, 5100, 6172, 1, 0, ''],
[2, 5100, 5251, 4650, 5100, 6172, 0, 0], [2, 5100, 5251, 4650, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4850, 4750, 6172, 0, 0], [3, 4850, 5050, 4850, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.05, roi={"0": 0.01}, profit_perc=-0.04, stop_loss=-0.05, roi={"0": 0.01}, profit_perc=-0.04,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=1), trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=1),
BTrade(sell_reason=SellType.STOP_LOSS, open_tick=2, close_tick=2)] BTrade(sell_reason=SellType.STOP_LOSS, open_tick=2, close_tick=2)]
@ -254,13 +254,13 @@ tc15 = BTContainer(data=[
# Causes negative profit even though sell-reason is ROI. # Causes negative profit even though sell-reason is ROI.
# stop-loss: 10%, ROI: 10% (should not apply), -100% after 65 minutes (limits trade duration) # stop-loss: 10%, ROI: 10% (should not apply), -100% after 65 minutes (limits trade duration)
tc16 = BTContainer(data=[ tc16 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
[2, 4987, 5300, 4950, 5050, 6172, 0, 0], [2, 4987, 5300, 4950, 5050, 6172, 0, 0, ''],
[3, 4975, 5000, 4940, 4962, 6172, 0, 0], # ForceSell on ROI (roi=-1) [3, 4975, 5000, 4940, 4962, 6172, 0, 0, ''], # ForceSell on ROI (roi=-1)
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10, "65": -1}, profit_perc=-0.012, stop_loss=-0.10, roi={"0": 0.10, "65": -1}, profit_perc=-0.012,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -270,13 +270,13 @@ tc16 = BTContainer(data=[
# stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration) # stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration)
# Uses open as sell-rate (special case) - since the roi-time is a multiple of the timeframe. # Uses open as sell-rate (special case) - since the roi-time is a multiple of the timeframe.
tc17 = BTContainer(data=[ tc17 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
[2, 4987, 5300, 4950, 5050, 6172, 0, 0], [2, 4987, 5300, 4950, 5050, 6172, 0, 0, ''],
[3, 4980, 5000, 4940, 4962, 6172, 0, 0], # ForceSell on ROI (roi=-1) [3, 4980, 5000, 4940, 4962, 6172, 0, 0, ''], # ForceSell on ROI (roi=-1)
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10, "120": -1}, profit_perc=-0.004, stop_loss=-0.10, roi={"0": 0.10, "120": -1}, profit_perc=-0.004,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -286,13 +286,13 @@ tc17 = BTContainer(data=[
# stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration) # stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration)
# uses open_rate as sell-price # uses open_rate as sell-price
tc18 = BTContainer(data=[ tc18 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
[2, 4987, 5300, 4950, 5200, 6172, 0, 0], [2, 4987, 5300, 4950, 5200, 6172, 0, 0, ''],
[3, 5200, 5220, 4940, 4962, 6172, 0, 0], # Sell on ROI (sells on open) [3, 5200, 5220, 4940, 4962, 6172, 0, 0, ''], # Sell on ROI (sells on open)
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4950, 4975, 4925, 4950, 6172, 0, 0]], [5, 4950, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10, "120": 0.01}, profit_perc=0.04, stop_loss=-0.10, roi={"0": 0.10, "120": 0.01}, profit_perc=0.04,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -301,13 +301,13 @@ tc18 = BTContainer(data=[
# stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration) # stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration)
# uses calculated ROI (1%) as sell rate, otherwise identical to tc18 # uses calculated ROI (1%) as sell rate, otherwise identical to tc18
tc19 = BTContainer(data=[ tc19 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
[2, 4987, 5300, 4950, 5200, 6172, 0, 0], [2, 4987, 5300, 4950, 5200, 6172, 0, 0, ''],
[3, 5000, 5300, 4940, 4962, 6172, 0, 0], # Sell on ROI [3, 5000, 5300, 4940, 4962, 6172, 0, 0, ''], # Sell on ROI
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4550, 4975, 4925, 4950, 6172, 0, 0]], [5, 4550, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10, "120": 0.01}, profit_perc=0.01, stop_loss=-0.10, roi={"0": 0.10, "120": 0.01}, profit_perc=0.01,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -316,13 +316,13 @@ tc19 = BTContainer(data=[
# stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration) # stop-loss: 10%, ROI: 10% (should not apply), -100% after 100 minutes (limits trade duration)
# uses calculated ROI (1%) as sell rate, otherwise identical to tc18 # uses calculated ROI (1%) as sell rate, otherwise identical to tc18
tc20 = BTContainer(data=[ tc20 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''],
[2, 4987, 5300, 4950, 5200, 6172, 0, 0], [2, 4987, 5300, 4950, 5200, 6172, 0, 0, ''],
[3, 5200, 5300, 4940, 4962, 6172, 0, 0], # Sell on ROI [3, 5200, 5300, 4940, 4962, 6172, 0, 0, ''], # Sell on ROI
[4, 4962, 4987, 4972, 4950, 6172, 0, 0], [4, 4962, 4987, 4972, 4950, 6172, 0, 0, ''],
[5, 4550, 4975, 4925, 4950, 6172, 0, 0]], [5, 4550, 4975, 4925, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10, "119": 0.01}, profit_perc=0.01, stop_loss=-0.10, roi={"0": 0.10, "119": 0.01}, profit_perc=0.01,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -332,12 +332,12 @@ tc20 = BTContainer(data=[
# which cannot happen in reality # which cannot happen in reality
# stop-loss: 10%, ROI: 4%, Trailing stop adjusted at the sell candle # stop-loss: 10%, ROI: 4%, Trailing stop adjusted at the sell candle
tc21 = BTContainer(data=[ tc21 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 4650, 5100, 6172, 0, 0], [2, 5100, 5251, 4650, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4650, 4750, 6172, 0, 0], [3, 4850, 5050, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.04}, profit_perc=0.04, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.04}, profit_perc=0.04, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -348,12 +348,12 @@ tc21 = BTContainer(data=[
# applying a positive trailing stop of 3% - ROI should apply before trailing stop. # applying a positive trailing stop of 3% - ROI should apply before trailing stop.
# stop-loss: 10%, ROI: 4%, stoploss adjusted candle 2 # stop-loss: 10%, ROI: 4%, stoploss adjusted candle 2
tc22 = BTContainer(data=[ tc22 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 5100, 5100, 6172, 0, 0], [2, 5100, 5251, 5100, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4650, 4750, 6172, 0, 0], [3, 4850, 5050, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.04}, profit_perc=0.04, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.04}, profit_perc=0.04, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -367,12 +367,12 @@ tc22 = BTContainer(data=[
# Stoploss would trigger in this candle too, but it's no longer relevant. # Stoploss would trigger in this candle too, but it's no longer relevant.
# stop-loss: 10%, ROI: 4%, stoploss adjusted candle 2, ROI adjusted in candle 3 (causing the sell) # stop-loss: 10%, ROI: 4%, stoploss adjusted candle 2, ROI adjusted in candle 3 (causing the sell)
tc23 = BTContainer(data=[ tc23 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 5100, 5100, 6172, 0, 0], [2, 5100, 5251, 5100, 5100, 6172, 0, 0, ''],
[3, 4850, 5251, 4650, 4750, 6172, 0, 0], [3, 4850, 5251, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.1, "119": 0.03}, profit_perc=0.03, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.1, "119": 0.03}, profit_perc=0.03, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -383,13 +383,13 @@ tc23 = BTContainer(data=[
# Stoploss at 1%. # Stoploss at 1%.
# Stoploss wins over Sell-signal (because sell-signal is acted on in the next candle) # Stoploss wins over Sell-signal (because sell-signal is acted on in the next candle)
tc24 = BTContainer(data=[ tc24 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5012, 4986, 4600, 6172, 0, 0], [2, 4987, 5012, 4986, 4600, 6172, 0, 0, ''],
[3, 5010, 5000, 4855, 5010, 6172, 0, 1], # Triggers stoploss + sellsignal [3, 5010, 5000, 4855, 5010, 6172, 0, 1, ''], # Triggers stoploss + sellsignal
[4, 5010, 4987, 4977, 4995, 6172, 0, 0], [4, 5010, 4987, 4977, 4995, 6172, 0, 0, ''],
[5, 4995, 4995, 4995, 4950, 6172, 0, 0]], [5, 4995, 4995, 4995, 4950, 6172, 0, 0, '']],
stop_loss=-0.01, roi={"0": 1}, profit_perc=-0.01, use_sell_signal=True, stop_loss=-0.01, roi={"0": 1}, profit_perc=-0.01, use_sell_signal=True,
trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.STOP_LOSS, open_tick=1, close_tick=3)]
) )
@ -398,13 +398,13 @@ tc24 = BTContainer(data=[
# Stoploss at 1%. # Stoploss at 1%.
# Sell-signal wins over stoploss # Sell-signal wins over stoploss
tc25 = BTContainer(data=[ tc25 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5012, 4986, 4600, 6172, 0, 0], [2, 4987, 5012, 4986, 4600, 6172, 0, 0, ''],
[3, 5010, 5000, 4986, 5010, 6172, 0, 1], [3, 5010, 5000, 4986, 5010, 6172, 0, 1, ''],
[4, 5010, 4987, 4855, 4995, 6172, 0, 0], # Triggers stoploss + sellsignal acted on [4, 5010, 4987, 4855, 4995, 6172, 0, 0, ''], # Triggers stoploss + sellsignal acted on
[5, 4995, 4995, 4995, 4950, 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, 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)] trades=[BTrade(sell_reason=SellType.SELL_SIGNAL, open_tick=1, close_tick=4)]
) )
@ -413,13 +413,13 @@ tc25 = BTContainer(data=[
# Stoploss at 10% (irrelevant), ROI at 5% (will trigger) # Stoploss at 10% (irrelevant), ROI at 5% (will trigger)
# Sell-signal wins over stoploss # Sell-signal wins over stoploss
tc26 = BTContainer(data=[ tc26 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5012, 4986, 4600, 6172, 0, 0], [2, 4987, 5012, 4986, 4600, 6172, 0, 0, ''],
[3, 5010, 5251, 4986, 5010, 6172, 0, 1], # Triggers ROI, sell-signal [3, 5010, 5251, 4986, 5010, 6172, 0, 1, ''], # Triggers ROI, sell-signal
[4, 5010, 4987, 4855, 4995, 6172, 0, 0], [4, 5010, 4987, 4855, 4995, 6172, 0, 0, ''],
[5, 4995, 4995, 4995, 4950, 6172, 0, 0]], [5, 4995, 4995, 4995, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.05, use_sell_signal=True, stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.05, use_sell_signal=True,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=3)]
) )
@ -429,13 +429,13 @@ tc26 = BTContainer(data=[
# TODO: figure out if sell-signal should win over ROI # TODO: figure out if sell-signal should win over ROI
# Sell-signal wins over stoploss # Sell-signal wins over stoploss
tc27 = BTContainer(data=[ tc27 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5025, 4975, 4987, 6172, 1, 0], [0, 5000, 5025, 4975, 4987, 6172, 1, 0, ''],
[1, 5000, 5025, 4975, 4987, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5025, 4975, 4987, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4987, 5012, 4986, 4600, 6172, 0, 0], [2, 4987, 5012, 4986, 4600, 6172, 0, 0, ''],
[3, 5010, 5012, 4986, 5010, 6172, 0, 1], # sell-signal [3, 5010, 5012, 4986, 5010, 6172, 0, 1, ''], # sell-signal
[4, 5010, 5251, 4855, 4995, 6172, 0, 0], # Triggers ROI, sell-signal acted on [4, 5010, 5251, 4855, 4995, 6172, 0, 0, ''], # Triggers ROI, sell-signal acted on
[5, 4995, 4995, 4995, 4950, 6172, 0, 0]], [5, 4995, 4995, 4995, 4950, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.05, use_sell_signal=True, stop_loss=-0.10, roi={"0": 0.05}, profit_perc=0.05, use_sell_signal=True,
trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=4)] trades=[BTrade(sell_reason=SellType.ROI, open_tick=1, close_tick=4)]
) )
@ -445,12 +445,12 @@ tc27 = BTContainer(data=[
# therefore "open" will be used # therefore "open" will be used
# stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2 # stop-loss: 10%, ROI: 10% (should not apply), stoploss adjusted candle 2
tc28 = BTContainer(data=[ tc28 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 4950, 5100, 6172, 0, 0], [1, 5000, 5050, 4950, 5100, 6172, 0, 0, ''],
[2, 5100, 5251, 5100, 5100, 6172, 0, 0], [2, 5100, 5251, 5100, 5100, 6172, 0, 0, ''],
[3, 4850, 5050, 4650, 4750, 6172, 0, 0], [3, 4850, 5050, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.03, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.03, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
@ -461,12 +461,12 @@ tc28 = BTContainer(data=[
# high of stoploss candle. # high of stoploss candle.
# stop-loss: 10%, ROI: 10% (should not apply) # stop-loss: 10%, ROI: 10% (should not apply)
tc29 = BTContainer(data=[ tc29 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5050, 5000, 4900, 6172, 0, 0], # enter trade (signal on last candle) [1, 5000, 5050, 5000, 4900, 6172, 0, 0, ''], # enter trade (signal on last candle)
[2, 4900, 5250, 4500, 5100, 6172, 0, 0], # Triggers trailing-stoploss [2, 4900, 5250, 4500, 5100, 6172, 0, 0, ''], # Triggers trailing-stoploss
[3, 5100, 5100, 4650, 4750, 6172, 0, 0], [3, 5100, 5100, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.02, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.02, trailing_stop=True,
trailing_stop_positive=0.03, trailing_stop_positive=0.03,
trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=2)] trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=2)]
@ -475,12 +475,12 @@ tc29 = BTContainer(data=[
# Test 30: trailing_stop should be triggered immediately on trade open candle. # Test 30: trailing_stop should be triggered immediately on trade open candle.
# stop-loss: 10%, ROI: 10% (should not apply) # stop-loss: 10%, ROI: 10% (should not apply)
tc30 = BTContainer(data=[ tc30 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5500, 5000, 4900, 6172, 0, 0], # enter trade (signal on last candle) and stop [1, 5000, 5500, 5000, 4900, 6172, 0, 0, ''], # enter trade (signal on last candle) and stop
[2, 4900, 5250, 4500, 5100, 6172, 0, 0], [2, 4900, 5250, 4500, 5100, 6172, 0, 0, ''],
[3, 5100, 5100, 4650, 4750, 6172, 0, 0], [3, 5100, 5100, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True,
trailing_stop_positive=0.01, trailing_stop_positive=0.01,
trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=1)] trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=1)]
@ -489,12 +489,12 @@ tc30 = BTContainer(data=[
# Test 31: trailing_stop should be triggered immediately on trade open candle. # Test 31: trailing_stop should be triggered immediately on trade open candle.
# stop-loss: 10%, ROI: 10% (should not apply) # stop-loss: 10%, ROI: 10% (should not apply)
tc31 = BTContainer(data=[ tc31 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5500, 5000, 4900, 6172, 0, 0], # enter trade (signal on last candle) and stop [1, 5000, 5500, 5000, 4900, 6172, 0, 0, ''], # enter trade (signal on last candle) and stop
[2, 4900, 5250, 4500, 5100, 6172, 0, 0], [2, 4900, 5250, 4500, 5100, 6172, 0, 0, ''],
[3, 5100, 5100, 4650, 4750, 6172, 0, 0], [3, 5100, 5100, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.10, roi={"0": 0.10}, profit_perc=0.01, trailing_stop=True, stop_loss=-0.10, roi={"0": 0.10}, profit_perc=0.01, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02,
trailing_stop_positive=0.01, trailing_stop_positive=0.01,
@ -504,18 +504,33 @@ tc31 = BTContainer(data=[
# Test 32: trailing_stop should be triggered immediately on trade open candle. # Test 32: trailing_stop should be triggered immediately on trade open candle.
# stop-loss: 1%, ROI: 10% (should not apply) # stop-loss: 1%, ROI: 10% (should not apply)
tc32 = BTContainer(data=[ tc32 = BTContainer(data=[
# D O H L C V B S # D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0], [0, 5000, 5050, 4950, 5000, 6172, 1, 0, ''],
[1, 5000, 5500, 5000, 4900, 6172, 0, 0], # enter trade (signal on last candle) and stop [1, 5000, 5500, 5000, 4900, 6172, 0, 0, ''], # enter trade (signal on last candle) and stop
[2, 4900, 5250, 4500, 5100, 6172, 0, 0], [2, 4900, 5250, 4500, 5100, 6172, 0, 0, ''],
[3, 5100, 5100, 4650, 4750, 6172, 0, 0], [3, 5100, 5100, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0]], [4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.01, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True, stop_loss=-0.01, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02,
trailing_stop_positive=0.01, use_custom_stoploss=True, trailing_stop_positive=0.01, use_custom_stoploss=True,
trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=1)] trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=1)]
) )
# Test 33: trailing_stop should be triggered immediately on trade open candle.
# stop-loss: 1%, ROI: 10% (should not apply)
tc33 = BTContainer(data=[
# D O H L C V B S SN
[0, 5000, 5050, 4950, 5000, 6172, 1, 0, 'buy_signal_01'],
[1, 5000, 5500, 5000, 4900, 6172, 0, 0, ''], # enter trade (signal on last candle) and stop
[2, 4900, 5250, 4500, 5100, 6172, 0, 0, ''],
[3, 5100, 5100, 4650, 4750, 6172, 0, 0, ''],
[4, 4750, 4950, 4350, 4750, 6172, 0, 0, '']],
stop_loss=-0.01, roi={"0": 0.10}, profit_perc=-0.01, trailing_stop=True,
trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.02,
trailing_stop_positive=0.01, use_custom_stoploss=True,
trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=1, buy_signal_name='buy_signal_01')]
)
TESTS = [ TESTS = [
tc0, tc0,
tc1, tc1,
@ -550,6 +565,7 @@ TESTS = [
tc30, tc30,
tc31, tc31,
tc32, tc32,
tc33,
] ]
@ -598,5 +614,6 @@ def test_backtest_results(default_conf, fee, mocker, caplog, data) -> None:
for c, trade in enumerate(data.trades): for c, trade in enumerate(data.trades):
res = results.iloc[c] res = results.iloc[c]
assert res.sell_reason == trade.sell_reason.value assert res.sell_reason == trade.sell_reason.value
assert res.buy_signal_name == trade.buy_signal_name
assert res.open_date == _get_frame_time_from_offset(trade.open_tick) assert res.open_date == _get_frame_time_from_offset(trade.open_tick)
assert res.close_date == _get_frame_time_from_offset(trade.close_tick) assert res.close_date == _get_frame_time_from_offset(trade.close_tick)