Exemplo n.º 1
0
    def trending(self, trendPoint):
        rsi = getattr(trendPoint, 'rsi')
        emaRsi = getattr(trendPoint, 'emaRsi')

        if self.currentTrend != None:
            self.currentTrend.addTrendRate(trendPoint)

        trendAction = self.WhatIsTrendDoing()

        if trendAction == "advancing":
            if rsi > emaRsi:
                if emaRsi < self.omega or emaRsi > self.alpha:
                    if self.currentTrend is None:
                        self.currentTrend = Trend(self.rsiRates, "dynamic", "upward", self.movingAverage, trendPoint)
                        print("opening upward dynamic trend")
                    else:
                        trendDirection = getattr(self.currentTrend, "direction")
                        if trendDirection is "downward":
                            database.saveTrend(self.currentTrend)
                            self.currentTrend = None
                            self.rsiRates = []
                            print("Closing dynamic downward trend")
        elif trendAction == "retreating":
            if rsi < emaRsi:
                if emaRsi < self.omega or emaRsi > self.alpha:
                    if self.currentTrend is None:
                        self.currentTrend = Trend(self.rsiRates, "dynamic", "downward", self.movingAverage, trendPoint)
                        print("Opening downward dynamic trend")
                    else:
                        trendDirection = getattr(self.currentTrend, "direction")
                        if trendDirection is "upward":
                            database.saveTrend(self.currentTrend)
                            self.currentTrend = None
                            self.rsiRates = []
                            print("Closing dynamic upward trend")
Exemplo n.º 2
0
    def run(self, trendPoint):
        if self.currentTrend is None:
            if self.trendingUpward(trendPoint):
                print("Upward Trend Detected")
            elif self.trendingDownward(trendPoint):
                print("Upward Trend Detected")
        else:
            self.currentTrend.addTrendRate(trendPoint)

            # Check if trend still valid
            if self.currentTrend.direction is "upward":
                trendLine = getattr(self.currentTrend, "trendLine")
                baseline = getattr(self.currentTrend, "baseline")
                baselineTime = getattr(baseline, "time")
                baselineVal = baseline.getMovingAverageVal(self.movingAverage)

                for point in reversed(trendLine):
                    pointTime = getattr(point, "time")
                    if pointTime < baselineTime:
                        break
                    else:
                        trendPointVal = point.getMovingAverageVal(self.movingAverage)
                        spread = baselineVal - trendPointVal
                        if spread >= self.alpha:
                            database.saveTrend(self.currentTrend)
                            self.currentTrend = None

            else:
                trendLine = getattr(self.currentTrend, "trendLine")
                baseline = getattr(self.currentTrend, "baseline")
                baselineTime = getattr(baseline, "time")
                baselineVal = baseline.getMovingAverageVal(self.movingAverage)

                for point in reversed(trendLine):
                    pointTime = getattr(point, "time")
                    if pointTime < baselineTime:
                        break
                    else:
                        trendPointVal = point.getMovingAverageVal(self.movingAverage)
                        spread = trendPointVal - baselineVal
                        if spread >= self.alpha:
                            database.saveTrend(self.currentTrend)
                            self.currentTrend = None