def __init__(self, settings, name=None):
        EntryManager.__init__(self, settings, name)

        self.minhour = settings.getint("Strategy", "minhour")
        self.maxhour = settings.getint("Strategy", "maxhour")
        self.target = self._getintsetting("Strategy", "target")
        self.minmove = settings.getfloat("Strategy", "minmove")
        self.maxprice = self._getfloatsetting("Strategy", "maxprice")
        self.maperiod = self._getintsetting("Strategy", "ma")
        self.stopPercentToLow = self._getfloatsetting("Strategy", "stopPercentToLow")

        self.hod = None
        self.open = None
        self.hoddate = None

        self.low = None
        self.close = Close()
        self.ma = ExponentialMovingAverage(metric=self.close, period=self.maperiod)

        self.mademove = False
        self.lastpd = None
class MomoPullbackEntryManager(EntryManager):
    """
    Enter at a moving average after a minimum move.  Stop is set at a percentage
    between the moving average and the low of day.
    """

    def __init__(self, settings, name=None):
        EntryManager.__init__(self, settings, name)

        self.minhour = settings.getint("Strategy", "minhour")
        self.maxhour = settings.getint("Strategy", "maxhour")
        self.target = self._getintsetting("Strategy", "target")
        self.minmove = settings.getfloat("Strategy", "minmove")
        self.maxprice = self._getfloatsetting("Strategy", "maxprice")
        self.maperiod = self._getintsetting("Strategy", "ma")
        self.stopPercentToLow = self._getfloatsetting("Strategy", "stopPercentToLow")

        self.hod = None
        self.open = None
        self.hoddate = None

        self.low = None
        self.close = Close()
        self.ma = ExponentialMovingAverage(metric=self.close, period=self.maperiod)

        self.mademove = False
        self.lastpd = None

    def handle(self, perioddata):
        self.close.handle(perioddata)
        self.ma.handle(perioddata)

        if self.lastpd is not None and self.lastpd.date.day != perioddata.date.day:
            self.low = None
            self.hod = None
            self.hoddate = None
            self.mademove = False

        if self.open is None:
            self.open = perioddata.open
        if self.lastpd is not None and (self.low is None or self.lastpd.low < self.low):
            self.low = self.lastpd.low
        if self.periodData is not None:
            # quick, use previous value to update hod
            if self.hod is None or self.periodData.high >= self.hod:
                self.hod = self.periodData.high
                self.hoddate = self.periodData.date
        if not self.mademove and self.low is not None and self.hod is not None and self.open is not None and (
                    self.hod - self.open) / self.open >= self.minmove:
            logger.debug("saw minimum desired move in MomoPullbackManager, waiting for pullback")
            self.mademove = True

        EntryManager.handle(self, perioddata)

        self.lastpd = perioddata

    def checkTrade(self, trade):
        if trade is not None:
            # no scale ins
            return trade
        if self.mademove \
                and self.periodData.date.hour >= self.minhour \
                and (self.periodData.date.hour < self.maxhour
                     or (self.periodData.date.hour == self.maxhour and self.periodData.date.minute == 0)) \
                and self.periodData.low <= self.ma.value():
            # we have an entry
            entry = min(self.periodData.open, self.ma.value())
            if self.maxprice is None or entry <= self.maxprice:
                stop = self.low - 0.01
                if self.stopPercentToLow is not None:
                    stop = entry - (self.stopPercentToLow * (entry - self.low))
                # at least 10c
                if stop >= entry - 0.1:
                    stop = entry - 0.1

                trade = Trade(self.periodData.stock, self.periodData.date, entry, stop)
                if self.target is not None:
                    target = entry + ((entry - stop) * self.target)
                    trade.target = target

                if self.periodData.low < stop:
                    trade.exit = self.periodData.date
                    trade.exitPrice = stop

                return trade
        return None