Exemplo n.º 1
0
class GapUpEntryManager:
    def __init__(self, settings):
        self.minPrice = settings.getfloat("GapAndGoSwingEntry", "minPrice")
        self.minAvgVol = settings.getint("GapAndGoSwingEntry", "minAvgVol")
        self.minPercent = settings.getfloat("GapAndGoSwingEntry", "minPercent")
        targetstr = settings.get("GapAndGoSwingEntry", "target")
        if targetstr == "None":
            self.target = None
        else:
            self.target = float(targetstr)
        self.volume = Volume()
        self.avgvol = SimpleMovingAverage(metric=self.volume, period=21)
        self.opn = AdjustedOpen()
        self.close = AdjustedClose()
        self.lastClose = HistoricMetric(metric=self.close, period=1)
        self.high = AdjustedHigh()
        self.lastHigh = HistoricMetric(metric=self.high, period=1)
        self.low = AdjustedLow()
        self.inBottomRange=0.1
        self.inTopRange=None
        
    def handle(self, perioddata):
        self.close.handle(perioddata)
        self.lastClose.handle(perioddata)
        self.high.handle(perioddata)
        self.lastHigh.handle(perioddata)
        self.opn.handle(perioddata)
        self.volume.handle(perioddata)
        self.avgvol.handle(perioddata)
        self.low.handle(perioddata)
        self.lastdd = perioddata

    def checkTrade(self):
        if self.close.ready() and self.lastClose.ready() \
                and self.opn.ready() and self.volume.ready() \
                and self.avgvol.ready():
            if self.lastdd.close >= self.minPrice and self.avgvol.value() >= self.minAvgVol \
                    and self.lastClose.value() > 0 and self.opn.value() > 0 \
                    and ((self.opn.value()-self.lastClose.value())/self.lastClose.value()) >= self.minPercent \
                    and self.low.value() >= self.lastHigh.value() \
                    and (self.inBottomRange == None or ((self.lastdd.adjustedHigh != self.lastdd.adjustedLow) and (self.close.value()-self.lastdd.adjustedLow)/(self.lastdd.adjustedHigh-self.lastdd.adjustedLow)) <= self.inBottomRange) \
                    and (self.inTopRange == None or ((self.lastdd.adjustedHigh != self.lastdd.adjustedLow) and (self.close.value()-self.lastdd.adjustedLow)/(self.lastdd.adjustedHigh-self.lastdd.adjustedLow)) >= self.inTopRange):
                stop = max(0.0, self.low.value() - 0.01)
#                 stop = max(0.0, self.lastHigh.value())
                trade = Trade(self.lastdd.stock, self.lastdd.date, self.close.value(), stop)
                if self.target != None:
                    target = self.close.value() + ((self.close.value()-stop)*self.target)
                    trade.target = target
                return trade
        return None
    
    def recommendedPreload(self):
        return 22
Exemplo n.º 2
0
    def __init__(self, settings):
        PriceVolumeDailyTrigger.__init__(self, settings)
        self.mingap = settings.getfloat("BulkowskiGapDailyTrigger", "mingap")
        self.open = AdjustedOpen()
        self.close = AdjustedClose()
        self.lastClose = HistoricMetric(self.close, 1)
        self.sma = SimpleMovingAverage(metric=self.close, period=50)
        self.lastsma = HistoricMetric(self.sma, 1)

        self._addMetrics(self.open, self.close, self.lastClose, self.sma, self.lastsma)
Exemplo n.º 3
0
class BulkowskiGapDailyTrigger(PriceVolumeDailyTrigger):
    def __init__(self, settings):
        PriceVolumeDailyTrigger.__init__(self, settings)
        self.mingap = settings.getfloat("BulkowskiGapDailyTrigger", "mingap")
        self.open = AdjustedOpen()
        self.close = AdjustedClose()
        self.lastClose = HistoricMetric(self.close, 1)
        self.sma = SimpleMovingAverage(metric=self.close, period=50)
        self.lastsma = HistoricMetric(self.sma, 1)

        self._addMetrics(self.open, self.close, self.lastClose, self.sma, self.lastsma)

    def check(self):
        if PriceVolumeDailyTrigger.check(self):
            if self.lastClose.value() > 0 and self.open.value() > 0:
                gap = (self.lastClose.value() - self.open.value())/self.lastClose.value()
                if gap >= self.mingap:
                    return True
        return False
Exemplo n.º 4
0
 def __init__(self, settings):
     self.minPrice = settings.getfloat("GapAndGoSwingEntry", "minPrice")
     self.minAvgVol = settings.getint("GapAndGoSwingEntry", "minAvgVol")
     self.minPercent = settings.getfloat("GapAndGoSwingEntry", "minPercent")
     targetstr = settings.get("GapAndGoSwingEntry", "target")
     if targetstr == "None":
         self.target = None
     else:
         self.target = float(targetstr)
     self.volume = Volume()
     self.avgvol = SimpleMovingAverage(metric=self.volume, period=21)
     self.opn = AdjustedOpen()
     self.close = AdjustedClose()
     self.lastClose = HistoricMetric(metric=self.close, period=1)
     self.high = AdjustedHigh()
     self.lastHigh = HistoricMetric(metric=self.high, period=1)
     self.low = AdjustedLow()
     self.inBottomRange=0.1
     self.inTopRange=None