diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index bed644e03..9b7a3b080 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -177,15 +177,15 @@ class Analyze(object): return True # Check if time matches and current rate is above threshold - time_diff = (current_time - trade.open_date).total_seconds() / 60 - for duration, threshold in sorted(self.strategy.minimal_roi.items()): - if time_diff > float(duration) and current_profit > threshold: + time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60 + for duration_string, threshold in self.strategy.minimal_roi.items(): + duration = float(duration_string) + if time_diff > duration and current_profit > threshold: return True - self.logger.debug( - 'Threshold not reached. (cur_profit: %1.2f%%)', - float(current_profit) * 100.0 - ) + if time_diff < duration: + return False + return False def tickerdata_to_dataframe(self, tickerdata: Dict[str, List]) -> Dict[str, DataFrame]: diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index d02691886..dfe5a5f49 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -114,15 +114,13 @@ class Backtesting(object): ) # calculate win/lose forwards from buy point - sell_subset = ticker[ticker.index > row.Index][['close', 'sell']] + sell_subset = ticker[ticker.index > row.Index][['close', 'sell', 'buy']] for row2 in sell_subset.itertuples(index=True): if max_open_trades > 0: # Increase trade_count_lock for every iteration trade_count_lock[row2.Index] = trade_count_lock.get(row2.Index, 0) + 1 - # Buy is on is in the buy_subset there is a row that matches the date - # of the sell event - buy_signal = (buy_subset.index == row2.Index).any() + buy_signal = row2.buy if( self.analyze.should_sell( trade=trade, diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index ea6603795..e0d433a24 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -194,8 +194,8 @@ class Trade(_DECL_BASE): """ open_trade_price = self.calc_open_trade_price() close_trade_price = self.calc_close_trade_price( - rate=Decimal(rate or self.close_rate), - fee=Decimal(fee or self.fee) + rate=(rate or self.close_rate), + fee=(fee or self.fee) ) return float("{0:.8f}".format(close_trade_price - open_trade_price)) @@ -213,8 +213,8 @@ class Trade(_DECL_BASE): open_trade_price = self.calc_open_trade_price() close_trade_price = self.calc_close_trade_price( - rate=Decimal(rate or self.close_rate), - fee=Decimal(fee or self.fee) + rate=(rate or self.close_rate), + fee=(fee or self.fee) ) return float("{0:.8f}".format((close_trade_price / open_trade_price) - 1)) diff --git a/freqtrade/strategy/strategy.py b/freqtrade/strategy/strategy.py index 24ad31190..3d077a7e0 100644 --- a/freqtrade/strategy/strategy.py +++ b/freqtrade/strategy/strategy.py @@ -6,6 +6,7 @@ This module load custom strategies import importlib import os import sys +from collections import OrderedDict from pandas import DataFrame from freqtrade.logger import Logger from freqtrade.constants import Constants @@ -56,7 +57,9 @@ class Strategy(object): ) # Minimal ROI designed for the strategy - self.minimal_roi = self.custom_strategy.minimal_roi + self.minimal_roi = OrderedDict(sorted( + self.custom_strategy.minimal_roi.items(), + key=lambda tuple: float(tuple[0]))) # sort after converting to number # Optimal stoploss designed for the strategy self.stoploss = self.custom_strategy.stoploss diff --git a/freqtrade/tests/test_persistence.py b/freqtrade/tests/test_persistence.py index 401de7acb..f6c5318ce 100644 --- a/freqtrade/tests/test_persistence.py +++ b/freqtrade/tests/test_persistence.py @@ -271,10 +271,6 @@ def test_calc_profit(limit_buy_order, limit_sell_order): # Lower than open rate assert trade.calc_profit(rate=0.00000123, fee=0.003) == -0.00089092 - # Only custom fee without sell order applied - with pytest.raises(TypeError): - trade.calc_profit(fee=0.003) - # Test when we apply a Sell order. Sell higher than open rate @ 0.00001173 trade.update(limit_sell_order) assert trade.calc_profit() == 0.00006217 @@ -299,10 +295,6 @@ def test_calc_profit_percent(limit_buy_order, limit_sell_order): # Get percent of profit with a custom rate (Lower than open rate) assert trade.calc_profit_percent(rate=0.00000123) == -0.88863827 - # Only custom fee without sell order applied - with pytest.raises(TypeError): - trade.calc_profit_percent(fee=0.003) - # Test when we apply a Sell order. Sell higher than open rate @ 0.00001173 trade.update(limit_sell_order) assert trade.calc_profit_percent() == 0.06201057