예제 #1
0
 def test_stopLow9(self):
     donchianLowStop = [1, 1, 2, 2, 3, 3, 2, 2, 4, 1, 2, 2, 3, 3]
     index = 13
     stopdays = 2
     timebase = 3
     e = utils.setStopLow(donchianLowStop, index, stopdays, timebase)
     self.assertEqual(e, 1)
예제 #2
0
 def test_stopLow4(self):
     donchianLowStop = [1, 1, 2, 2, 3, 3]
     index = 3
     stopdays = 1
     timebase = 1
     e = utils.setStopLow(donchianLowStop, index, stopdays, timebase)
     self.assertEqual(e, 2)
예제 #3
0
 def test_stopLow2(self):
     donchianLowStop = [1]
     index = 5
     stopdays = 1
     timebase = 1
     e = utils.setStopLow(donchianLowStop, index, stopdays, timebase)
     self.assertEqual(e, -1)
예제 #4
0
 def test_stopLow1(self):
     donchianLowStop = [1]
     index = 0
     stopdays = 3
     timebase = 1440
     e = utils.setStopLow(donchianLowStop, index, stopdays, timebase)
     self.assertEqual(e, -1)
예제 #5
0
 def test_stopLow11(self):
     donchianLowStop = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     stopdays = 2
     timebase = 2
     for index in donchianLowStop:
         #print("---" + str(index) + "---")
         e = utils.setStopLow(donchianLowStop, index, stopdays, timebase)
예제 #6
0
        donchianHighStop, donchianLowStop = utils.buildDonchian2(
            STOPDAYS, TIMEBASE, highList, lowList)
        gAccountMoney = STARTMONEY  # money
        gAmountAssets = 0  # assets
        state = State.EQUAL
        file.write('----' + str(dd) + '|' + str(sd) + '----\n')
        #---buy and sell---
        if 1:
            index = 0
            for price in closeList[:len(donchianHigh)]:
                #for price in closeList[:100000]:
                if 1:
                    AMOUNTOFMONEY = gAccountMoney
                    #trailing Stop Long
                    if (state == State.LONG):
                        stop = utils.setStopLow(donchianLowStop, index, 1,
                                                TIMEBASE)
                        gStop = stop = donchianLowStop[index - TIMEBASE]
                        stopDict[int(index / TIMEBASE) * TIMEBASE] = stop

                    #sellLong
                    if ((state == State.LONG) and (price < gStop)):
                        sellLong(gAmountAssets, price, FEE, index)
                        state = State.EQUAL
                    # buyLong
                    if ((index > ((DONCHIANDAYS + 1) * TIMEBASE))
                            and (state == State.EQUAL)):
                        if (utils.checkLong(price, donchianHigh, index,
                                            TIMEBASE)):
                            print("---------" + str(dd) + '|' + str(sd) +
                                  "-----------")
                            stop = donchianLowStop[index - TIMEBASE]