Added short and exit_short to strategy
This commit is contained in:
@@ -58,7 +58,11 @@ def merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,
|
||||
return dataframe
|
||||
|
||||
|
||||
def stoploss_from_open(open_relative_stop: float, current_profit: float) -> float:
|
||||
def stoploss_from_open(
|
||||
open_relative_stop: float,
|
||||
current_profit: float,
|
||||
for_short: bool = False
|
||||
) -> float:
|
||||
"""
|
||||
|
||||
Given the current profit, and a desired stop loss value relative to the open price,
|
||||
@@ -72,14 +76,17 @@ def stoploss_from_open(open_relative_stop: float, current_profit: float) -> floa
|
||||
|
||||
:param open_relative_stop: Desired stop loss percentage relative to open price
|
||||
:param current_profit: The current profit percentage
|
||||
:return: Positive stop loss value relative to current price
|
||||
:return: Stop loss value relative to current price
|
||||
"""
|
||||
|
||||
# formula is undefined for current_profit -1, return maximum value
|
||||
if current_profit == -1:
|
||||
return 1
|
||||
|
||||
stoploss = 1-((1+open_relative_stop)/(1+current_profit))
|
||||
stoploss = 1-((1+open_relative_stop)/(1+current_profit)) # TODO-lev: Is this right?
|
||||
|
||||
# negative stoploss values indicate the requested stop price is higher than the current price
|
||||
return max(stoploss, 0.0)
|
||||
if for_short:
|
||||
return min(stoploss, 0.0)
|
||||
else:
|
||||
return max(stoploss, 0.0)
|
||||
|
||||
Reference in New Issue
Block a user