populate sell signal

This commit is contained in:
Janne Sinivirta 2017-11-14 20:28:31 +02:00 committed by gcarq
parent c12a9ebd92
commit 1db0a7d4ce
2 changed files with 26 additions and 2 deletions

View File

@ -7,7 +7,7 @@ import talib.abstract as ta
from pandas import DataFrame, to_datetime
from freqtrade.exchange import get_ticker_history
from freqtrade.vendor.qtpylib.indicators import awesome_oscillator
from freqtrade.vendor.qtpylib.indicators import awesome_oscillator, crossed_above, crossed_below
logger = logging.getLogger(__name__)
@ -62,7 +62,7 @@ def populate_indicators(dataframe: DataFrame) -> DataFrame:
def populate_buy_trend(dataframe: DataFrame) -> DataFrame:
"""
Based on TA indicators, populates the buy trend for the given dataframe
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
@ -77,6 +77,19 @@ def populate_buy_trend(dataframe: DataFrame) -> DataFrame:
return dataframe
def populate_sell_trend(dataframe: DataFrame) -> DataFrame:
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.ix[
(crossed_above(dataframe['rsi'], 70)),
'sell'] = 1
dataframe.ix[dataframe['sell'] == 1, 'sell_price'] = dataframe['close']
return dataframe
def analyze_ticker(pair: str) -> DataFrame:
"""
@ -92,6 +105,7 @@ def analyze_ticker(pair: str) -> DataFrame:
dataframe = parse_ticker_dataframe(ticker_hist)
dataframe = populate_indicators(dataframe)
dataframe = populate_buy_trend(dataframe)
dataframe = populate_sell_trend(dataframe)
return dataframe

View File

@ -37,3 +37,13 @@ def test_returns_latest_buy_signal(mocker):
buydf = DataFrame([{'buy': 0, 'date': datetime.today()}])
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=buydf)
assert not get_signal('BTC-ETH', SignalType.BUY)
def test_returns_latest_sell_signal(mocker):
selldf = DataFrame([{'sell': 1, 'date': datetime.today()}])
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=selldf)
assert get_signal('BTC-ETH', SignalType.SELL)
selldf = DataFrame([{'sell': 0, 'date': datetime.today()}])
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=selldf)
assert not get_signal('BTC-ETH', SignalType.SELL)