Exemplo n.º 1
0
 def __init__(self, rw, sl, percent, ma, cad, pip):
     self.riskReward = rw
     self.stopLoss = sl
     self.lotSizePercent = percent
     self.movingAverage = ma
     self.candles = cad
     self.pip = pip
     self.otherPip = 1 / self.pip
     self.tr = trade.Trader()
     self.candleArr = []
     self.tempArr = []
     self.balance = 1000
Exemplo n.º 2
0
    def __init__(self, percent, cad, pip, length):

        self.length = length

        self.lotSizePercent = percent
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000
Exemplo n.º 3
0
    def __init__(self, percent, cad, pip, length, shouldPrint, stoploss,
                 riskreward):

        self.shouldPrint = shouldPrint
        self.length = length
        self.stopLoss = stoploss
        self.riskReward = riskreward
        self.lotSizePercent = percent
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000
Exemplo n.º 4
0
class strategy4(object):
    highestBalance = 1000
    highestDrawdown = 0

    totalTrades = 0
    winCounter = 0
    lossCount = 0
    com = 0
    pip = .0001
    otherPip = 1 / pip
    maxTrades = 30
    tempArr = []
    candleArr = []
    balance = 1000
    tr = trade.Trader()
    #cmp = candleCompressor.candleCompressor()
    currentCandle = 0

    #strategy variables
    riskReward = 8
    stopLoss = 10
    lotSizePercent = .001
    movingAverage = 10
    candles = 16  #number of 15m candles, 16 = 4hr

    def __init__(self, rw, sl, percent, ma, cad, pip):
        self.riskReward = rw
        self.stopLoss = sl
        self.lotSizePercent = percent
        self.movingAverage = ma
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000

    def getNumTrades(self):
        return self.tr.getNumTrades()

    def getWinRate(self):
        return self.tr.getWinRate()

    def drawdown(self, c):
        if (self.balance + self.closeAll(c) > self.highestBalance):
            self.highestBalance = self.balance + self.closeAll(c)

        if ((self.highestBalance - (self.balance + self.closeAll(c))) /
                self.highestBalance > self.highestDrawdown):
            self.highestDrawdown = (
                self.highestBalance -
                (self.balance + self.closeAll(c))) / self.highestBalance

        return self.highestDrawdown

    def MA(self):
        total = 0
        for i in range(0, self.movingAverage):
            value = (self.candleArr[i].getHigh() +
                     self.candleArr[i].getLow()) / 2
            total += value

        return total / self.movingAverage

    def update(self, h, l, print, c):
        self.balance += self.tr.update(h, l, self.balance, print, c)

    def len(self):
        return len(self.candleArr)

    def closeAll(self, c):
        total = self.tr.closeAll(c)
        return total

    def nextCandle(self, cand):

        self.tempArr.append(cand)
        self.currentCandle += 1
        self.drawdown(cand.getClose())

        if (self.currentCandle == self.candles):
            self.candleArr.append(candleCompressor.candleCompressor().compress(
                self.tempArr))
            self.currentCandle = 0
            self.tempArr = []
            if (len(self.candleArr) > self.movingAverage):

                self.candleArr.pop(0)

                currentHigh = self.candleArr[self.len() - 1].getHigh()
                currentLow = self.candleArr[self.len() - 1].getLow()
                currentOpen = self.candleArr[self.len() - 1].getOpen()
                currentClose = self.candleArr[self.len() - 1].getClose()
                prevOpen = self.candleArr[self.len() - 2].getOpen()
                maVal = self.MA()

                #print('open',str(currentOpen),'close: ',str(currentClose),'high',str(currentHigh),'low: ',str(currentLow))

                if (self.candleArr[self.len() - 4].getClose() > maVal
                        and self.candleArr[self.len() - 3].getClose() > maVal
                        and self.candleArr[self.len() - 2].getClose() > maVal
                        and currentClose <
                        self.candleArr[self.len() - 4].getOpen()):

                    totalPips = (self.stopLoss * self.pip)

                    # print(totalPips*otherPip)

                    thisTake = currentClose + totalPips
                    thisStop = currentClose - (totalPips * self.riskReward)

                    winLossGain = (self.balance * self.lotSizePercent)

                    comWinLoss = (self.com /
                                  (totalPips * self.otherPip)) * winLossGain
                    #print(comWinLoss)
                    comLossLoss = (self.com / ((totalPips * self.riskReward) *
                                               self.otherPip)) * winLossGain
                    # print('lossloss: ',comWinLoss,  'money lost per trade: ', (winLossGain*riskReward)+comWinLoss)
                    # def addTrade(self, entry, stop, take, win, loss):
                    self.totalTrades += 1

                    self.tr.addTrade(currentClose, thisTake, thisStop,
                                     (winLossGain * self.riskReward) -
                                     comWinLoss, (winLossGain) + comWinLoss)
Exemplo n.º 5
0
class strategy7(object):
    highestBalance = 1000
    highestDrawdown = 0
    shouldPrint = True

    firstTrade = True
    liveBuy = False
    inBuy = False
    totalTrades = 0
    winCounter = 0
    lossCount = 0
    com = .2
    pip = .0001
    otherPip = 1 / pip
    maxTrades = 30
    tempArr = []
    candleArr = []
    balance = 70000
    tr = trade.Trader()
    #cmp = candleCompressor.candleCompressor()
    currentCandle = 0
    length = 118
    #strategy variables
    riskReward = 8
    stopLoss = 10
    lotSizePercent = .001
    movingAverage = 10
    candles = 16  #number of 15m candles, 16 = 4hr

    def __init__(self, percent, cad, pip, length):

        self.length = length

        self.lotSizePercent = percent
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000

    def getNumTrades(self):
        return self.totalTrades

    def getWinRate(self):
        return self.tr.getWinRate()

    def drawdown(self, c):
        if (self.balance + self.closeAll(c) > self.highestBalance):
            self.highestBalance = self.balance + self.closeAll(c)

        if ((self.highestBalance - (self.balance + self.closeAll(c))) /
                self.highestBalance > self.highestDrawdown):
            self.highestDrawdown = (
                self.highestBalance -
                (self.balance + self.closeAll(c))) / self.highestBalance

        return self.highestDrawdown

    def update(self, h, l, print, c):
        self.balance += self.tr.update(h, l, self.balance, print, c)

    def len(self):
        return len(self.candleArr)

    def closeAll(self, c):
        total = self.tr.closeAll(c)
        return total

    def calculateHigh(self):
        high = -9868
        low = 8765875876587
        for x in range(
                len(self.candleArr) - self.length - 1,
                len(self.candleArr) - 1):
            thisHigh = self.candleArr[x].getHigh()
            thisLow = self.candleArr[x].getLow()
            if (thisHigh > high):
                high = thisHigh
            if (thisLow < low):
                low = thisLow
        return high

    def calculateLow(self):
        high = -9868
        low = 8765875876587
        for x in range(
                len(self.candleArr) - self.length - 1,
                len(self.candleArr) - 1):
            thisHigh = self.candleArr[x].getHigh()
            thisLow = self.candleArr[x].getLow()
            if (thisHigh > high):
                high = thisHigh
            if (thisLow < low):
                low = thisLow

        return low

    def updateStrat(self, price):
        if (len(self.candleArr) > self.length + 1):
            margin = self.lotSizePercent
            units = (self.balance * margin) / price
            if (price >= self.calculateHigh() and self.liveBuy == False):
                print('live buy. entry: ' + str(price) + 'units: ' +
                      str(units))
                self.liveBuy = True
                if (not self.firstTrade):
                    mt4.close_sell_order()

                mt4.buy_order(symbol="USDJPY_",
                              stop_loss=10000,
                              take_profit=10000)
                print("buy order sucess")
                self.firstTrade = False
            elif (price <= self.calculateLow() and self.liveBuy == True):
                print('live sell. entry: ' + str(price) + 'units: ' +
                      str(units))
                self.liveBuy = False
                if (not self.firstTrade):
                    mt4.close_buy_order()
                mt4.sell_order(symbol="USDJPY_",
                               stop_loss=10000,
                               take_profit=10000)
                print("sell order sucess")
                self.firstTrade = False

    def nextCandle(self, cand):

        self.tempArr.append(cand)
        self.currentCandle += 1
        self.drawdown(cand.getClose())

        if (self.currentCandle == self.candles):
            thisCand = candleCompressor.candleCompressor().compress(
                self.tempArr)

            print("# of candles: " + str(len(self.candleArr)) +
                  "needed length to trade: >" + str(self.length + 1))
            if (len(self.candleArr) > self.length + 1):
                print("high channel: " + str(self.calculateHigh()) +
                      "low channel: " + str(self.calculateLow()) +
                      "this candle low and high: " + str(thisCand.getLow()) +
                      ', ' + str(thisCand.getHigh()))

                if (thisCand.getHigh() >= self.calculateHigh()
                        and thisCand.getLow() < self.calculateHigh()
                        and self.inBuy == False):
                    #print("buy")
                    self.balance += self.tr.crossClose(self.calculateHigh(),
                                                       self.shouldPrint)
                    self.tr.crossOpen(self.calculateHigh(), .00003, True,
                                      self.balance, self.lotSizePercent,
                                      self.shouldPrint)
                    self.totalTrades += 1
                    self.inBuy = True
                    print('backtester entered buy(and closed sell) at: ' +
                          str(self.calculateHigh()))

                elif (thisCand.getLow() <= self.calculateLow()
                      and thisCand.getHigh() > self.calculateLow()
                      and self.inBuy == True):
                    #print("sell")
                    self.balance += self.tr.crossClose(self.calculateLow(),
                                                       self.shouldPrint)
                    self.tr.crossOpen(self.calculateLow(), .00003, False,
                                      self.balance, self.lotSizePercent,
                                      self.shouldPrint)
                    self.totalTrades += 1
                    self.inBuy = False
                    print('backtester entered sell(and closed buy) at: ' +
                          str(self.calculateLow()))
            self.candleArr.append(thisCand)
            self.currentCandle = 0
            self.tempArr = []
Exemplo n.º 6
0
class strategy6(object):
    highestBalance = 1000
    highestDrawdown = 0

    prevHullVal = 0
    prevMAVal = 0
    totalTrades = 0
    winCounter = 0
    lossCount = 0
    com = 0
    pip = .0001
    otherPip = 1 / pip
    maxTrades = 30
    tempArr = []
    candleArr = []
    hullArr = []
    balance = 1000
    tr = trade.Trader()
    #cmp = candleCompressor.candleCompressor()
    currentCandle = 0

    #strategy variables
    riskReward = 8
    stopLoss = 10
    lotSizePercent = .001
    movingAverage = 10
    wMovingAverage = 10
    candles = 16  #number of 15m candles, 16 = 4hr

    def __init__(self, rw, sl, percent, ma, cad, pip, wma):
        self.riskReward = rw
        self.stopLoss = sl
        self.lotSizePercent = percent
        self.movingAverage = ma
        self.wMovingAverage = wma
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000

    def getNumTrades(self):
        return self.totalTrades

    def getWinRate(self):
        return self.tr.getWinRate()

    def drawdown(self, c):
        if (self.balance + self.closeAll(c) > self.highestBalance):
            self.highestBalance = self.balance + self.closeAll(c)

        if ((self.highestBalance - (self.balance + self.closeAll(c))) /
                self.highestBalance > self.highestDrawdown):
            self.highestDrawdown = (
                self.highestBalance -
                (self.balance + self.closeAll(c))) / self.highestBalance

        return self.highestDrawdown

    def MA(self):
        total = 0
        for i in range(
                len(self.candleArr) - self.movingAverage, len(self.candleArr)):
            value = (self.candleArr[i].getHigh() +
                     self.candleArr[i].getLow()) / 2
            total += value

        return total / self.movingAverage

    def HMA(self, period):
        total = 0
        divide = 0
        inc = 1
        for i in range(len(self.hullArr) - period, len(self.hullArr)):
            value = (self.hullArr[i]) * inc
            total += value
            divide += inc
            inc += 1

        return total / divide

    def WMA(self, period):
        total = 0
        divide = 0
        inc = 1
        for i in range(len(self.candleArr) - period, len(self.candleArr)):

            value = (
                (self.candleArr[i].getHigh() + self.candleArr[i].getLow()) /
                2) * inc
            total += value
            divide += inc
            inc += 1

        return total / divide

    def update(self, h, l, print, c):
        self.balance += self.tr.update(h, l, self.balance, print, c)

    def len(self):
        return len(self.candleArr)

    def closeAll(self, c):
        total = self.tr.closeAll(c)
        return total

    def nextCandle(self, cand):

        self.tempArr.append(cand)
        self.currentCandle += 1
        self.drawdown(cand.getClose())

        if (self.currentCandle == self.candles):
            self.candleArr.append(candleCompressor.candleCompressor().compress(
                self.tempArr))
            self.currentCandle = 0
            self.tempArr = []
            if (len(self.candleArr) >
                    self.movingAverage + self.wMovingAverage):

                self.candleArr.pop(0)

                currentHigh = self.candleArr[self.len() - 1].getHigh()
                currentLow = self.candleArr[self.len() - 1].getLow()
                currentOpen = self.candleArr[self.len() - 1].getOpen()
                currentClose = self.candleArr[self.len() - 1].getClose()
                prevOpen = self.candleArr[self.len() - 2].getOpen()
                wmaVal = self.WMA(self.wMovingAverage)
                maVal = self.MA()
                hullMA = (2 * self.WMA(int(self.wMovingAverage / 2)) -
                          self.WMA(self.wMovingAverage))
                self.hullArr.append(hullMA)
                if (len(self.hullArr) > self.wMovingAverage):
                    crossUp = False
                    crossDown = False
                    hVal = self.HMA(int(math.sqrt(self.wMovingAverage)))
                    if (not self.prevHullVal == 0
                            and self.prevHullVal < self.prevMAVal
                            and hVal > maVal):
                        crossUp = True
                    if (not self.prevHullVal == 0
                            and self.prevHullVal > self.prevMAVal
                            and hVal < maVal):
                        crossDown = True

                    self.prevHullVal = hVal
                    self.prevMAVal = maVal

                    #print('open',str(currentOpen),'close: ',str(currentClose),'high',str(currentHigh),'low: ',str(currentLow))

                    if (crossUp):
                        self.balance += self.tr.crossClose(currentClose)
                        self.tr.crossOpen(currentClose, .0000, True,
                                          self.balance, self.lotSizePercent)
                        self.totalTrades += 1

                    if (crossDown):
                        self.balance += self.tr.crossClose(currentClose)
                        self.tr.crossOpen(currentClose, .0000, False,
                                          self.balance, self.lotSizePercent)
                        self.totalTrades += 1
Exemplo n.º 7
0
class strategy9(object):
    highestBalance = 1000
    highestDrawdown = 0
    shouldPrint = True

    inBuy = False
    totalTrades = 0
    winCounter = 0
    lossCount = 0
    com = .3
    pip = .001
    otherPip = 1 / pip
    maxTrades = 30
    tempArr = []
    candleArr = []
    balance = 1000
    tr = trade.Trader()
    #cmp = candleCompressor.candleCompressor()
    currentCandle = 0
    length = 118
    #strategy variables
    riskReward = 8
    stopLoss = 10
    lotSizePercent = .001
    movingAverage = 10
    candles = 3  #number of 15m candles, 16 = 4hr

    def __init__(self, percent, cad, pip, length, shouldPrint, stoploss,
                 riskreward):

        self.shouldPrint = shouldPrint
        self.length = length
        self.stopLoss = stoploss
        self.riskReward = riskreward
        self.lotSizePercent = percent
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000

    def getNumTrades(self):
        return self.totalTrades

    def getWinRate(self):
        return self.tr.getWinRate()

    def drawdown(self, c):
        if (self.balance + self.closeAll(c) > self.highestBalance):
            self.highestBalance = self.balance + self.closeAll(c)

        if ((self.highestBalance - (self.balance + self.closeAll(c))) /
                self.highestBalance > self.highestDrawdown):
            self.highestDrawdown = (
                self.highestBalance -
                (self.balance + self.closeAll(c))) / self.highestBalance

        return self.highestDrawdown

    def update(self, h, l, print, c):
        self.balance += self.tr.update(h, l, self.balance, print, c)

    def len(self):
        return len(self.candleArr)

    def closeAll(self, c):
        total = self.tr.closeAll(c)
        return total

    def calculateHigh(self):
        high = -9868
        low = 8765875876587
        for x in range(
                len(self.candleArr) - self.length - 1,
                len(self.candleArr) - 1):
            thisHigh = self.candleArr[x].getHigh()
            thisLow = self.candleArr[x].getLow()
            if (thisHigh > high):
                high = thisHigh
            if (thisLow < low):
                low = thisLow
        return high

    def calculateLow(self):
        high = -9868
        low = 8765875876587
        for x in range(
                len(self.candleArr) - self.length - 1,
                len(self.candleArr) - 1):
            thisHigh = self.candleArr[x].getHigh()
            thisLow = self.candleArr[x].getLow()
            if (thisHigh > high):
                high = thisHigh
            if (thisLow < low):
                low = thisLow

        return low

    def nextCandle(self, cand):

        self.tempArr.append(cand)
        self.currentCandle += 1
        self.drawdown(cand.getClose())

        if (self.currentCandle == self.candles):
            thisCand = candleCompressor.candleCompressor().compress(
                self.tempArr)

            if (len(self.candleArr) > self.length + 1):
                #print("trade here")

                if (thisCand.getHigh() >= self.calculateHigh()
                        and thisCand.getLow() < self.calculateHigh()
                        and self.inBuy == False):
                    thisEntry = self.calculateHigh()

                    totalPips = (self.stopLoss * self.pip)
                    thisTake = thisEntry + (totalPips * self.riskReward)
                    thisStop = thisEntry - totalPips

                    winLossGain = (self.balance * self.lotSizePercent)

                    comWinLoss = (self.com /
                                  (totalPips * self.otherPip)) * winLossGain
                    self.tr.addTrade(thisEntry, thisTake, thisStop,
                                     (winLossGain) - comWinLoss,
                                     (winLossGain * self.riskReward) +
                                     comWinLoss)

                if (thisCand.getLow() <= self.calculateLow()
                        and thisCand.getHigh() > self.calculateLow()
                        and False):
                    thisEntry = self.calculateLow()

                    totalPips = (self.stopLoss * self.pip)
                    thisTake = thisEntry + (totalPips * self.riskReward)
                    thisStop = thisEntry - totalPips

                    winLossGain = (self.balance * self.lotSizePercent)

                    comWinLoss = (self.com /
                                  (totalPips * self.otherPip)) * winLossGain
                    self.tr.addTrade(thisEntry, thisTake, thisStop,
                                     (winLossGain) - comWinLoss,
                                     (winLossGain * self.riskReward) +
                                     comWinLoss)
            self.candleArr.append(thisCand)
            self.currentCandle = 0
            self.tempArr = []
Exemplo n.º 8
0
class strategy5(object):
    highestBalance = 1000
    highestDrawdown = 0

    totalTrades = 0
    winCounter = 0
    lossCount = 0
    com = .2
    higher = True
    pip = .0001
    otherPip = 1 / pip
    maxTrades = 30
    tempArr = []
    candleArr = []
    balance = 1000
    tr = trade.Trader()
    #cmp = candleCompressor.candleCompressor()
    currentCandle = 0

    #strategy variables
    riskReward = 8
    stopLoss = 10
    lotSizePercent = .001
    aroonVal = 14
    candles = 16  #number of 15m candles, 16 = 4hr

    def __init__(self, rw, sl, percent, aroon, cad, pip):
        self.riskReward = rw
        self.stopLoss = sl
        self.lotSizePercent = percent
        self.aroonVal = aroon
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000

    def getNumTrades(self):
        return self.tr.getNumTrades()

    def calcAroonDown(self):
        lowestAmnt = 21397456283945
        lowestAmntIndex = 0

        for i in range(0, self.len()):
            curr = self.candleArr[i]
            if (curr.getLow() < lowestAmnt):
                lowestAmnt = curr.getLow()
                lowestAmntIndex = i

        return lowestAmntIndex / self.aroonVal

    def calcAroonUp(self):
        highestAmnt = 0
        highestAmntIndex = 0

        for i in range(0, self.len()):
            curr = self.candleArr[i]
            if (curr.getHigh() > highestAmnt):
                highestAmnt = curr.getHigh()
                highestAmntIndex = i
        return highestAmntIndex / self.aroonVal

    def getWinRate(self):
        return self.tr.getWinRate()

    def drawdown(self, c):
        if (self.balance + self.closeAll(c) > self.highestBalance):
            self.highestBalance = self.balance + self.closeAll(c)

        if ((self.highestBalance - (self.balance + self.closeAll(c))) /
                self.highestBalance > self.highestDrawdown):
            self.highestDrawdown = (
                self.highestBalance -
                (self.balance + self.closeAll(c))) / self.highestBalance

        return self.highestDrawdown

    def update(self, h, l, print, c):
        self.balance += self.tr.update(h, l, self.balance, print, c)

    def len(self):
        return len(self.candleArr)

    def closeAll(self, c):
        total = self.tr.closeAll(c)
        return total

    def nextCandle(self, cand):

        self.tempArr.append(cand)
        self.currentCandle += 1
        self.drawdown(cand.getClose())

        if (self.currentCandle == self.candles):
            self.candleArr.append(candleCompressor.candleCompressor().compress(
                self.tempArr))
            self.currentCandle = 0
            self.tempArr = []
            if (len(self.candleArr) > self.aroonVal):

                self.candleArr.pop(0)

                currentHigh = self.candleArr[self.len() - 1].getHigh()
                currentLow = self.candleArr[self.len() - 1].getLow()
                currentOpen = self.candleArr[self.len() - 1].getOpen()
                currentClose = self.candleArr[self.len() - 1].getClose()
                prevOpen = self.candleArr[self.len() - 2].getOpen()
                aroonUp = self.calcAroonUp()
                aroonDown = self.calcAroonDown()
                crossed = False
                currentlyHigher = self.higher
                self.higher = aroonUp > aroonDown
                #print('aroonUp:',aroonUp,'aroonDown:',aroonDown)

                #print('open',str(currentOpen),'close: ',str(currentClose),'high',str(currentHigh),'low: ',str(currentLow))

                if (currentlyHigher and not self.higher):

                    totalPips = (self.stopLoss * self.pip)

                    # print(totalPips*otherPip)

                    thisTake = currentClose - totalPips
                    thisStop = currentClose + (totalPips * self.riskReward)

                    winLossGain = (self.balance * self.lotSizePercent)

                    comWinLoss = (self.com /
                                  (totalPips * self.otherPip)) * winLossGain
                    comLossLoss = (self.com / ((totalPips * self.riskReward) *
                                               self.otherPip)) * winLossGain
                    # print('lossloss: ',comWinLoss,  'money lost per trade: ', (winLossGain*riskReward)+comWinLoss)
                    # def addTrade(self, entry, stop, take, win, loss):
                    self.totalTrades += 1

                    self.tr.addTrade(currentClose, thisStop, thisTake,
                                     (winLossGain) - comWinLoss,
                                     (winLossGain * self.riskReward) +
                                     comWinLoss)
Exemplo n.º 9
0
class strategy8(object):
    highestBalance = 1000
    highestDrawdown = 0
    shouldPrint = True

    inBuy = False
    totalTrades = 0
    winCounter = 0
    lossCount = 0
    com = 0  #.0001
    pip = .0001
    otherPip = 1 / pip
    maxTrades = 30
    tempArr = []
    candleArr = []
    momArr = []
    balance = 1000
    tr = trade.Trader()
    #cmp = candleCompressor.candleCompressor()
    currentCandle = 0
    length = 118
    #strategy variables
    riskReward = 8
    stopLoss = 10
    lotSizePercent = .001
    movingAverage = 10
    candles = 3  #number of 15m candles, 16 = 4hr
    shouldPrint = False

    def __init__(self, percent, cad, pip, length, shouldPrint):

        self.shouldPrint = shouldPrint
        self.length = length

        self.lotSizePercent = percent
        self.candles = cad
        self.pip = pip
        self.otherPip = 1 / self.pip
        self.tr = trade.Trader()
        self.candleArr = []
        self.tempArr = []
        self.balance = 1000

    def getNumTrades(self):
        return self.totalTrades

    def getWinRate(self):
        return self.tr.getWinRate()

    def drawdown(self, c):
        if (self.balance + self.closeAll(c) > self.highestBalance):
            self.highestBalance = self.balance + self.closeAll(c)

        if ((self.highestBalance - (self.balance + self.closeAll(c))) /
                self.highestBalance > self.highestDrawdown):
            self.highestDrawdown = (
                self.highestBalance -
                (self.balance + self.closeAll(c))) / self.highestBalance

        return self.highestDrawdown

    def update(self, h, l, print, c):
        self.balance += self.tr.update(h, l, self.balance, print, c)

    def len(self):
        return len(self.candleArr)

    def closeAll(self, c):
        total = self.tr.closeAll(c)
        return total

    def calMomentum(self, length, arr):
        farCandle = arr[len(arr) - 1 - length].getClose()
        thisCandle = arr[len(arr) - 1].getClose()
        return thisCandle - farCandle

    def calMomentum2(self, length, arr):
        farCandle = arr[len(arr) - 1 - length]
        thisCandle = arr[len(arr) - 1]
        return thisCandle - farCandle

    def nextCandle(self, cand):

        self.tempArr.append(cand)
        self.currentCandle += 1
        self.drawdown(cand.getClose())

        if (self.currentCandle == self.candles):
            thisCand = candleCompressor.candleCompressor().compress(
                self.tempArr)

            thisMom = 0
            momOfMom = 0
            if (len(self.candleArr) > self.length + 1):
                #print("trade here")
                if (len(self.candleArr) > self.length):
                    thisMom = self.calMomentum(self.length, self.candleArr)
                    self.momArr.append(thisMom)
                    if (len(self.momArr) > 3):
                        momOfMom = self.calMomentum2(1, self.momArr)

                if (thisMom > 0 and momOfMom > 0 and not thisMom == 0
                        and not momOfMom == 0 and self.inBuy == False):
                    #print("buy")
                    self.balance += self.tr.crossClose(thisCand.getClose(),
                                                       self.shouldPrint)
                    self.tr.crossOpen(thisCand.getClose(), self.com, True,
                                      self.balance, self.lotSizePercent,
                                      self.shouldPrint)
                    self.totalTrades += 1
                    self.inBuy = True

                elif (thisMom < 0 and momOfMom < 0 and not thisMom == 0
                      and not momOfMom == 0 and self.inBuy == True):
                    #print("sell")
                    self.balance += self.tr.crossClose(thisCand.getClose(),
                                                       self.shouldPrint)
                    self.tr.crossOpen(thisCand.getClose(), self.com, False,
                                      self.balance, self.lotSizePercent,
                                      self.shouldPrint)
                    self.totalTrades += 1
                    self.inBuy = False
            self.candleArr.append(thisCand)
            self.currentCandle = 0
            self.tempArr = []