コード例 #1
0
    def run(self):
        flag = False
        real_body = self.true_body()
        upper_shadow, lower_shadow = self.get_shadow_length()

        try:
            if float(upper_shadow) / real_body >= 2 and (
                (float(lower_shadow) / self.l) * 100) <= self.threshold:
                flag = True
        except ZeroDivisionError as e:
            print_stock_data(self.stock_name, self.o, self.h, self.l, self.c)
            print(e)

        if self.find_trend:
            if not self.uptrend:
                self.uptrend = is_uptrend(self.stock_name)

        if flag:
            if self.uptrend:
                self.candle = True
                self.trade_setting["action"] = "sell"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = self.h
                self.trade_setting["candle"] = "shooting_star"
                self.trade_setting["target"] = ""
                self.trade_setting["info"] = general_info("shooting_star")

        return self.candle, self.trade_setting
コード例 #2
0
    def run(self):
        flag = False
        if is_small_body(self.o, self.h, self.l, self.c, self.body_threshold):
            flag = True

        if self.find_trend:
            if not self.uptrend and not self.downtrend:
                self.uptrend = is_uptrend(self.stock_name)
                self.downtrend = is_downtrend(self.stock_name)

        if flag:
            if self.uptrend:
                self.candle = True
                self.trade_setting["action"] = "sell"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = self.l
                self.trade_setting["candle"] = "doji_in_uptrend"
                self.trade_setting["target"] = ""
                self.trade_setting["info"] = general_info("doji_in_uptrend")

            elif self.downtrend:
                self.candle = True
                self.trade_setting["action"] = "buy"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = self.h
                self.trade_setting["candle"] = "doji_in_downtrend"
                self.trade_setting["target"] = ""
                self.trade_setting["info"] = general_info("doji_in_downtrend")

        return self.candle, self.trade_setting
コード例 #3
0
    def run(self):
        if self.previous_day:
            po, ph, pl, pc, pv = self.previous_day
        else:
            date = get_latest_date_for_stock(self.stock_name)
            po, ph, pl, pc, pv = get_previous_day_stats(self.stock_name, date=date)

        if self.find_trend:
            if not self.uptrend and not self.downtrend:
                self.uptrend = is_uptrend(self.stock_name)
                self.downtrend = is_downtrend(self.stock_name)
        day1_range  = abs(po - pc)
        day2_range  = abs(self.o - self.c)
        day1_middle = float(day1_range)/2

        if self.downtrend and (is_bearish(po, pc)) and (is_bullish(self.o, self.c)):
            if (self.c > po and self.o <= pc):
                self.trade_setting["candle"] = "bullish_engulfing"
                self.trade_setting["info"]   = general_info("bullish_engulfing")
                self.candle = True
            elif (day1_middle <= day2_range < day1_range):
                self.trade_setting["candle"] = "piercing_pattern"
                self.trade_setting["info"]   = general_info("piercing_pattern")
                self.candle = True

            if self.candle:
                self.trade_setting["action"] = "buy"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = min(self.l, pl)
                self.trade_setting["target"] = ""

        elif self.uptrend and (is_bullish(po, pc)) and (is_bearish(self.o, self.c)):
            if (self.c < po and self.o > pc):
                self.trade_setting["candle"] = "bearish_engulfing"
                self.trade_setting["info"]   = general_info("bearish_engulfing")
                self.candle = True
            elif (day1_middle <= day2_range < day1_range):
                self.trade_setting["candle"] = "dark_cloud_cover"
                self.trade_setting["info"]   = general_info("dark_cloud_cover")
                self.candle = True

            if self.candle:
                self.trade_setting["action"] = "short"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = max(self.h, ph)
                self.trade_setting["target"] = ""

        return self.candle, self.trade_setting
コード例 #4
0
    def run(self):
        if self.previous_day:
            po, ph, pl, pc, pv = self.previous_day
        else:
            date = get_latest_date_for_stock(self.stock_name)
            po, ph, pl, pc, pv = get_previous_day_stats(self.stock_name,
                                                        date=date)

        if self.find_trend:
            if not self.uptrend and not self.downtrend:
                self.uptrend = is_uptrend(self.stock_name)
                self.downtrend = is_downtrend(self.stock_name)

        if self.downtrend and (is_bearish(
                po, pc)) and (self.o > pc) and is_bullish(
                    self.o, self.c) and (self.c < po):
            self.candle = True
            self.trade_setting["action"] = "buy"
            self.trade_setting["buy"] = self.c
            self.trade_setting["stoploss"] = min(self.l, pl)
            self.trade_setting["candle"] = "bullish_harami"
            self.trade_setting["target"] = ""
            self.trade_setting["info"] = general_info("bullish_harami")
            return self.candle, self.trade_setting

        elif self.uptrend and (is_bullish(
                po, pc)) and (self.o < pc) and is_bearish(
                    self.o, self.c) and (self.c > po):
            self.candle = True
            self.trade_setting["action"] = "short"
            self.trade_setting["buy"] = self.c
            self.trade_setting["stoploss"] = max(self.h, ph)
            self.trade_setting["candle"] = "bearish_harami"
            self.trade_setting["target"] = ""
            self.trade_setting["info"] = general_info("bearish_harami")
            return self.candle, self.trade_setting

        return self.candle, self.trade_setting
コード例 #5
0
    def run(self):
        flag = False
        if is_small_body(self.o, self.h, self.l, self.c, self.body_threshold):
            upper_shadow, lower_shadow = self.get_shadow_length()
            # Check if the shadow lengths are almost equal
            if float(abs(upper_shadow - lower_shadow)) / max(
                    upper_shadow, lower_shadow) * 100 <= self.shadow_threshold:
                flag = True

        if self.find_trend:
            if not self.uptrend and not self.downtrend:
                self.uptrend = is_uptrend(self.stock_name)
                self.downtrend = is_downtrend(self.stock_name)

        if flag:
            if self.uptrend:
                self.candle = True
                self.trade_setting["action"] = "sell"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = self.l
                self.trade_setting["candle"] = "spinning_top_in_uptrend"
                self.trade_setting["target"] = ""
                self.trade_setting["info"] = general_info(
                    "spinning_top_in_uptrend")

            elif self.downtrend:
                self.candle = True
                self.trade_setting["action"] = "buy"
                self.trade_setting["buy"] = self.c
                self.trade_setting["stoploss"] = self.h
                self.trade_setting["candle"] = "spinning_top_in_downtrend"
                self.trade_setting["target"] = ""
                self.trade_setting["info"] = general_info(
                    "spinning_top_in_downtrend")

        return self.candle, self.trade_setting