Merge pull request #1601 from hroff-1902/no-recursion-edge

eliminate recursion in Edge
This commit is contained in:
Misagh 2019-02-27 11:18:23 +01:00 committed by GitHub
commit 4e291795a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 65 deletions

View File

@ -351,7 +351,7 @@ class Edge():
return result
def _detect_next_stop_or_sell_point(self, buy_column, sell_column, date_column,
ohlc_columns, stoploss, pair, start_point=0):
ohlc_columns, stoploss, pair):
"""
Iterate through ohlc_columns recursively in order to find the next trade
Next trade opens from the first buy signal noticed to
@ -362,12 +362,15 @@ class Edge():
"""
result: list = []
start_point = 0
while True:
open_trade_index = utf1st.find_1st(buy_column, 1, utf1st.cmp_equal)
# return empty if we don't find trade entry (i.e. buy==1) or
# we find a buy but at the of array
if open_trade_index == -1 or open_trade_index == len(buy_column) - 1:
return []
break
else:
open_trade_index += 1 # when a buy signal is seen,
# trade opens in reality on the next candle
@ -395,7 +398,7 @@ class Edge():
# It is not interesting for Edge to consider it so we simply ignore the trade
# And stop iterating there is no more entry
if stop_index == sell_index == float('inf'):
return []
break
if stop_index <= sell_index:
exit_index = open_trade_index + stop_index
@ -407,7 +410,7 @@ class Edge():
# check if we have the next candle
if len(ohlc_columns) - 1 < exit_index:
return []
break
exit_type = SellType.SELL_SIGNAL
exit_price = ohlc_columns[exit_index, 0]
@ -428,14 +431,11 @@ class Edge():
result.append(trade)
# Calling again the same function recursively but giving
# it a view of exit_index till the end of array
return result + self._detect_next_stop_or_sell_point(
buy_column[exit_index:],
sell_column[exit_index:],
date_column[exit_index:],
ohlc_columns[exit_index:],
stoploss,
pair,
(start_point + exit_index)
)
# giving a view of exit_index till the end of array
buy_column = buy_column[exit_index:]
sell_column = sell_column[exit_index:]
date_column = date_column[exit_index:]
ohlc_columns = ohlc_columns[exit_index:]
start_point += exit_index
return result