Merge pull request #4543 from brookmiles/fix-math-custom-stoploss-docs

correct math used in examples and clarify some terminology regarding …
This commit is contained in:
Matthias
2021-03-18 19:32:30 +01:00
committed by GitHub
5 changed files with 130 additions and 18 deletions

View File

@@ -2,4 +2,4 @@
from freqtrade.exchange import (timeframe_to_minutes, timeframe_to_msecs, timeframe_to_next_date,
timeframe_to_prev_date, timeframe_to_seconds)
from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy.strategy_helper import merge_informative_pair
from freqtrade.strategy.strategy_helper import merge_informative_pair, stoploss_from_open

View File

@@ -56,3 +56,30 @@ def merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,
dataframe = dataframe.ffill()
return dataframe
def stoploss_from_open(open_relative_stop: float, current_profit: float) -> float:
"""
Given the current profit, and a desired stop loss value relative to the open price,
return a stop loss value that is relative to the current price, and which can be
returned from `custom_stoploss`.
The requested stop can be positive for a stop above the open price, or negative for
a stop below the open price. The return value is always >= 0.
Returns 0 if the resulting stop price would be above the current price.
: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
"""
# 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))
# negative stoploss values indicate the requested stop price is higher than the current price
return max(stoploss, 0.0)