diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 7323357e6..92cd7ead6 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -79,6 +79,7 @@ def populate_buy_trend(dataframe: DataFrame) -> DataFrame: return dataframe + def populate_sell_trend(dataframe: DataFrame) -> DataFrame: """ Based on TA indicators, populates the sell signal for the given dataframe diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index 4c126b64d..44c6b9bb8 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -54,6 +54,7 @@ def default_conf(): @pytest.fixture(scope="module") def backtest_conf(): return { + "max_open_trades": 3, "stake_currency": "BTC", "stake_amount": 0.01, "minimal_roi": { diff --git a/freqtrade/tests/test_backtesting.py b/freqtrade/tests/test_backtesting.py index 6b101d60e..ed58c59dc 100644 --- a/freqtrade/tests/test_backtesting.py +++ b/freqtrade/tests/test_backtesting.py @@ -85,22 +85,32 @@ def generate_text_table(data: Dict[str, Dict], results: DataFrame, stake_currenc def backtest(backtest_conf, processed, mocker): trades = [] + trade_count_lock = {} exchange._API = Bittrex({'key': '', 'secret': ''}) mocker.patch.dict('freqtrade.main._CONF', backtest_conf) for pair, pair_data in processed.items(): - pair_data['buy'] = 0 - pair_data['sell'] = 0 + pair_data['buy'], pair_data['sell'] = 0, 0 ticker = populate_sell_trend(populate_buy_trend(pair_data)) # for each buy point for row in ticker[ticker.buy == 1].itertuples(index=True): + # Check if max_open_trades has already been reached for the given date + if not trade_count_lock.get(row.date, 0) < backtest_conf['max_open_trades']: + continue + + # Increase lock + trade_count_lock[row.date] = trade_count_lock.get(row.date, 0) + 1 trade = Trade( open_rate=row.close, open_date=row.date, amount=backtest_conf['stake_amount'], fee=exchange.get_fee() * 2 ) + # calculate win/lose forwards from buy point - for row2 in ticker[row.Index:].itertuples(index=True): + for row2 in ticker[row.Index + 1:].itertuples(index=True): + # Increase trade_count_lock for every iteration + trade_count_lock[row2.date] = trade_count_lock.get(row2.date, 0) + 1 + if min_roi_reached(trade, row2.close, row2.date) or row2.sell == 1: current_profit = trade.calc_profit(row2.close) @@ -140,6 +150,8 @@ def test_backtest(backtest_conf, mocker): config['stake_currency'], config['stake_amount'] )) + print('Using max_open_trades: {} ...'.format(config['max_open_trades'])) + # Print timeframe min_date, max_date = get_timeframe(data) print('Measuring data from {} up to {} ...'.format(