diff --git a/user_data/hyperopts/AverageHyperopt.py b/user_data/hyperopts/AverageHyperopt.py index 75b5f95..1c4fb23 100644 --- a/user_data/hyperopts/AverageHyperopt.py +++ b/user_data/hyperopts/AverageHyperopt.py @@ -43,9 +43,11 @@ class AverageHyperopt(IHyperOpt): conditions = [] # TRIGGERS if 'trigger' in params: + trigger = [int(item) for item in params['trigger'].split('-')] + conditions.append(qtpylib.crossed_above( - dataframe[f"maShort({params['trigger'][0]})"], - dataframe[f"maMedium({params['trigger'][1]})"]) + dataframe[f"maShort({trigger[0]})"], + dataframe[f"maMedium({trigger[1]})"]) ) # Check that volume is not 0 @@ -68,9 +70,13 @@ class AverageHyperopt(IHyperOpt): buyTriggerList = [] for short in range(shortRangeBegin, shortRangeEnd): for medium in range(mediumRangeBegin, mediumRangeEnd): - # The output will be (short, long) + """ + The output will be '{short}-{long}' so we can split it on the trigger + this will prevent an error on scikit-optimize not accepting tuples as + first argument to Categorical + """ buyTriggerList.append( - (short, medium) + '{}-{}'.format(short, medium) ) return [ Categorical(buyTriggerList, name='trigger') @@ -90,10 +96,12 @@ class AverageHyperopt(IHyperOpt): # TRIGGERS if 'sell-trigger' in params: + trigger = [int(item) for item in params['sell-trigger'].split('-')] + conditions.append(qtpylib.crossed_above( - dataframe[f"maMedium({params['sell-trigger'][1]})"], - dataframe[f"maShort({params['sell-trigger'][0]})"]) - ) + dataframe[f"maMedium({trigger[1]})"], + dataframe[f"maShort({trigger[0]})"]) + ) if conditions: dataframe.loc[ @@ -112,9 +120,13 @@ class AverageHyperopt(IHyperOpt): sellTriggerList = [] for short in range(shortRangeBegin, shortRangeEnd): for medium in range(mediumRangeBegin, mediumRangeEnd): - # The output will be (short, long) + """ + The output will be '{short}-{long}' so we can split it on the trigger + this will prevent an error on scikit-optimize not accepting tuples as + first argument to Categorical + """ sellTriggerList.append( - (short, medium) + '{}-{}'.format(short, medium) ) return [ @@ -151,4 +163,4 @@ class AverageHyperopt(IHyperOpt): ), 'sell'] = 1 - return dataframe + return dataframe \ No newline at end of file