Ejemplo n.º 1
0
class DEMA(SingleValueIndicator):
    def __init__(self, period, timeSeries=None):
        super(DEMA, self).__init__()

        self.period = period

        self.ema = EMA(period)
        self.addSubIndicator(self.ema)

        self.emaEma = EMA(period)

        self.initialize(timeSeries)

    def _calculate(self):
        if len(self.ema) < 1:
            return

        self.emaEma.addValue(self.ema[-1])

        if len(self.emaEma) < 1:
            return

        self.values.append(2.0 * self.ema[-1] - self.emaEma[-1])

    def removeValue(self):
        super(DEMA, self).removeValue()

        self.emaEma.removeValue()

    def removeAll(self):
        super(DEMA, self).removeAll()

        self.emaEma.removeAll()
Ejemplo n.º 2
0
class MassIndex(SingleValueIndicator):
    def __init__(self,
                 emaPeriod,
                 emaEmaPeriod,
                 emaRatioPeriod,
                 timeSeries=None):
        super(MassIndex, self).__init__()

        self.emaPeriod = emaPeriod
        self.emaEmaPeriod = emaEmaPeriod
        self.emaRatioPeriod = emaRatioPeriod

        self.ema = EMA(emaPeriod)
        self.emaEma = EMA(emaEmaPeriod)
        self.emaRatio = []

        self.initialize(timeSeries)

    def _calculate(self):
        self.ema.addValue(self.timeSeries[-1].getHigh() -
                          self.timeSeries[-1].getLow())

        if len(self.ema) < 1:
            return

        self.emaEma.addValue(self.ema[-1])

        if len(self.emaEma) < 1:
            return

        self.emaRatio.append(self.ema[-1] / float(self.emaEma[-1]))

        if len(self.emaRatio) < self.emaRatioPeriod:
            return

        self.values.append(sum(self.emaRatio[-self.emaRatioPeriod:]))

    def removeValue(self):
        super(MassIndex, self).removeValue()

        self.ema.removeValue()
        self.emaEma.removeValue()
        if len(self.emaRatio) > 1:
            self.emaRatio.pop(-1)

    def removeAll(self):
        super(MassIndex, self).removeAll()

        self.ema.removeAll()
        self.emaEma.removeAll()
        self.emaRatio = []
Ejemplo n.º 3
0
class MACD(Indicator):
	def __init__(self, fastPeriod, slowPeriod, signalPeriod, timeSeries = None):
		super(MACD, self).__init__()

		self.fastPeriod = fastPeriod
		self.slowPeriod = slowPeriod
		self.signalPeriod = signalPeriod

		self.emaFast = EMA(fastPeriod)
		self.emaSlow = EMA(slowPeriod)
		self.signalLine = EMA(signalPeriod)
		self.macdLine = []

		self.addSubIndicator(self.emaFast)
		self.addSubIndicator(self.emaSlow)

		self.initialize(timeSeries)

	def _calculate(self):
		if len(self.emaFast) > 0 and len(self.emaSlow) > 0:
			self.macdLine.append(self.emaFast[-1] - self.emaSlow[-1])
			self.signalLine.addValue(self.macdLine[-1])

	def removeValue(self):
		super(MACD, self).removeValue()

		if len(self.macdLine) > 0:
			self.macdLine.pop(-1)
		self.signalLine.removeValue()

	def removeAll(self):
		super(MACD, self).removeAll()

		self.macdLine = []
		self.signalLine.removeAll()

	def getMACDLine(self):
		return self.macdLine

	def getSignalLine(self):
		return self.signalLine
Ejemplo n.º 4
0
class ChaikinOsc(SingleValueIndicator):
    def __init__(self, periodFast, periodSlow, timeSeries=None):
        super(ChaikinOsc, self).__init__()

        self.periodFast = periodFast
        self.periodSlow = periodSlow

        self.accuDist = AccuDist()

        self.emaFast = EMA(periodFast)
        self.emaSlow = EMA(periodSlow)

        self.addSubIndicator(self.accuDist)

        self.initialize(timeSeries)

    def _calculate(self):
        if len(self.accuDist) < 1:
            return

        self.emaFast.addValue(self.accuDist[-1])
        self.emaSlow.addValue(self.accuDist[-1])

        if len(self.emaFast) < 1 or len(self.emaSlow) < 1:
            return

        self.values.append(self.emaFast[-1] - self.emaSlow[-1])

    def removeValue(self):
        super(ChaikinOsc, self).removeValue()

        self.emaFast.removeValue()
        self.emaSlow.removeValue()

    def removeAll(self):
        super(ChaikinOsc, self).removeAll()

        self.emaFast.removeAll()
        self.emaSlow.removeAll()