Exemplo n.º 1
0
def test_trending_down():

    df = to_dataframe(data)
    ma = TA.HMA(df)
    assert isinstance(trending_down(ma, 10), Series)

    assert trending_down(ma, 10).values[-1]
Exemplo n.º 2
0
    def sell(self,
             period: int = 14,
             period2: int = 14,
             upper_bound: int = 90) -> np.bool_:
        """
        :param period:
        :param period2:
        :param upper_bound:
        :return:
        """
        try:
            raw_mfi = TA.MFI(self.df, period)
        except TradeSignalException as error:
            raise error
        else:
            selling = raw_mfi.iloc[-1] < upper_bound and raw_mfi.iloc[
                -2] >= upper_bound and trending_down(
                    raw_mfi.iloc[:-2], period=int(period / 2)).iloc[-1]
            if SU.is_valid_dataframe(self.df2):
                try:
                    raw_mfi2 = TA.MFI(self.df2, period)
                except TradeSignalException as error:
                    raise error
                else:
                    selling = selling and raw_mfi2.iloc[
                        -1] < upper_bound and raw_mfi2.iloc[
                            -2] >= upper_bound and trending_down(
                                raw_mfi2.iloc[:-2], period=int(
                                    period2 / 2)).iloc[-1]

            return selling
Exemplo n.º 3
0
    def sell(self, column: str = "close", lookback: int = 5) -> np.bool_:

        try:
            raw_obv = TA.OBV(self.df, column)
        except TradeSignalException as error:
            raise error
        else:
            selling = trending_down(self.df["close"], lookback).iloc[-1] and trending_up(raw_obv, lookback).iloc[-1]
            if SU.is_valid_dataframe(self.df2):
                try:
                    raw_obv2 = TA.OBV(self.df2, column)
                except TradeSignalException as error:
                    raise error
                else:
                    selling = selling and trending_down(self.df2["close"], lookback).iloc[-1] and trending_up(raw_obv2, lookback).iloc[-1]

            return selling
Exemplo n.º 4
0
    def sell(self,
            period_fast: int = 12,
            period_slow: int = 26,
            signal: int = 9,
            column: str = "close",
            adjust: bool = True,
            period_fast2: int = 12,
            period_slow2: int = 26,
            signal2: int = 9) -> np.bool_:
        """Calculate a moving average convergence-divergence sell signal from a bullish signal crossover.

        An optional second dataframe can be used to calculate the signal for a different time period
        :param period_fast:
        :param period_slow:
        :param signal:
        :param column:
        :param adjust:
        :param period_fast2:
        :param period_slow2:
        :param signal2:
        :return bool:
        """
        try:
            raw_macd = TA.MACD(self.df, period_fast, period_slow, signal, column, adjust)
        except TradeSignalException as error:
            raise error

        else:

            _is_positive = raw_macd["MACD"].iloc[-1] > 0
            _above_signal = raw_macd["MACD"].iloc[-1] > raw_macd["SIGNAL"].iloc[-1]
            _trending_down = trending_down(raw_macd["MACD"].iloc[:-2], period=int(period_fast/2)).iloc[-1]
            selling = _is_positive and _above_signal and _trending_down

            if SU.is_valid_dataframe(self.df2):
                try:
                    raw_macd2 = TA.MACD(self.df2, period_fast2, period_slow2, signal2, column, adjust)
                except TradeSignalException as error:
                    raise error
                else:
                    _is_positive2 = raw_macd2["MACD"].iloc[-1] > 0
                    _above_signal2 = raw_macd2["MACD"].iloc[-1] < raw_macd2["SIGNAL"].iloc[-1]
                    _trending_down2 = trending_down(raw_macd2["MACD"].iloc[:-2], period=int(period_fast2/2)).iloc[-1]
                    selling = selling and _is_positive2 and _above_signal2 and _trending_down2

            return selling
Exemplo n.º 5
0
    def sell(self,
             period: int = 14,
             ema_period: int = 60,
             column: str = "close",
             adjust: bool = True,
             period2: int = 14,
             ema_period2: int = 60) -> np.bool_:
        """Bearish sell signal calculation based on volume zone oscillator (VZO).

        The flag is generated based on a number of conditional statements generated from technical indicators.
        The basic buy rule is to sell when a bearish crossover happens -- the VZO crossing below the 40% line

        Along with the bearish crossover, we can use a 14 period average directional index (ADX), directional
        movement index (DMI), and a 60 period EMA to confirm the trend. We do this by making sure the close
        price has crossed below the 60 day EMA and either an ADX less than 20 or a downward DMI (DI- > DI+).

        An example usage might look like:

        if vzo.sell() or difference(current_price, entry_price) == profit_target:
            execute_sell_order()

        :param period:
        :param ema_period:
        :param column:
        :param adjust:
        :param period2:
        :param ema_period2:
        :return:
        """
        try:
            # grab the indicators we need (VZO, ADX, DMI, EMA) for this signal
            vzo = TA.VZO(self.df, period, column, adjust)
            adx = TA.ADX(self.df, period, adjust)
            dmi = TA.DMI(self.df, period, adjust)
            ema = TA.EMA(self.df, ema_period, column, adjust)
        except TradeSignalException as error:
            raise error
        else:
            _vzo_bearish_cross = vzo.iloc[-1] < 40 and trending_down(vzo.iloc[:-2], period=int(period/2)).iloc[-1]
            _adx_trending = adx.iloc[-1] < 20
            _dmi_negative = dmi["DI-"].iloc[-1] > dmi["DI+"].iloc[-1]
            _ema_bearish_cross = self.df["close"].iloc[-1] < ema.iloc[-1] and \
                trending_down(self.df["close"].iloc[:-2], period=int(period/2)).iloc[-1]
            selling = _vzo_bearish_cross and (_adx_trending or _dmi_negative) and _ema_bearish_cross

            if SU.is_valid_dataframe(self.df2):
                try:
                    # grab the indicators we need (VZO, ADX, DMI, EMA) for this signal
                    vzo2 = TA.VZO(self.df2, period2, column, adjust)
                    adx2 = TA.ADX(self.df2, period2, adjust)
                    dmi2 = TA.DMI(self.df2, period2, adjust)
                    ema2 = TA.EMA(self.df2, ema_period2, column, adjust)
                except TradeSignalException as error:
                    raise error
                else:
                    _vzo_bearish_cross2 = vzo2.iloc[-1] < 40 and trending_down(vzo2.iloc[:-2], period=int(period2/2)).iloc[-1]
                    _adx_trending2 = adx2.iloc[-1] < 20
                    _dmi_negative2 = dmi2["DI-"].iloc[-1] > dmi2["DI+"].iloc[-1]
                    _ema_bearish_cross2 = self.df2["close"].iloc[-1] < ema2.iloc[-1] and \
                        trending_down(self.df2["close"].iloc[:-2], period=int(period2/2)).iloc[-1]
                    selling = selling and _vzo_bearish_cross2 and (_adx_trending2 or _dmi_negative2) and _ema_bearish_cross2

            return selling