Пример #1
0
        # 如果上一根K的收盤價觸及停利價位,則在最新時間出場
        elif KBar['close'][n] > TakeProfitPoint:
            OrderRecord.Cover('Sell', KBar['product'][n + 1],
                              KBar['time'][n + 1], KBar['open'][n + 1], 1)
            print(KBar['close'][n])
        # 如果上一根K的收盤價觸及停損價位,則在最新時間出場
        elif KBar['close'][n] < StopLossPoint:
            OrderRecord.Cover('Sell', KBar['product'][n + 1],
                              KBar['time'][n + 1], KBar['open'][n + 1], 1)
            print(KBar['close'][n])
    # 如果有空單部位,則在1330點以後立即平倉
    elif OrderRecord.GetOpenInterest() == -1:
        # 判斷到期出場
        if KBar['time'][n].strftime('%H%M') >= "1330":
            OrderRecord.Cover('Buy', KBar['product'][n], KBar['time'][n],
                              KBar['open'][n], 1)
        # 如果上一根K的收盤價觸及停利價位,則在最新時間出場
        elif KBar['close'][n] < TakeProfitPoint:
            OrderRecord.Cover('Buy', KBar['product'][n + 1],
                              KBar['time'][n + 1], KBar['open'][n + 1], 1)
        # 如果上一根K的收盤價觸及停損價位,則在最新時間出場
        elif KBar['close'][n] > StopLossPoint:
            OrderRecord.Cover('Buy', KBar['product'][n + 1],
                              KBar['time'][n + 1], KBar['open'][n + 1], 1)

# 將回測紀錄寫至MicroTest中
OrderRecord.FutureMicroTestRecord('4-5-1-F', 200, 50)

# 繪製走勢圖以及下單點位
from chart import ChartOrder
ChartOrder(KBar, OrderRecord.GetTradeRecord())
Пример #2
0
                OrderRecord.Cover('Sell', KBar['product'][n + 1],
                                  KBar['time'][n + 1], KBar['open'][n + 1], 1)
                continue
        # 如果有空單部位
        elif OrderRecord.GetOpenInterest() == -1:
            # 結算平倉
            if KBar['product'][n + 1] != KBar['product'][n]:
                OrderRecord.Cover('Buy', KBar['product'][n], KBar['time'][n],
                                  KBar['close'][n], 1)
                continue
            # 逐筆更新移動停損價位
            if KBar['close'][n] + MoveStopLoss < StopLossPoint:
                StopLossPoint = KBar['close'][n] + MoveStopLoss
            # 如果上一根K的收盤價觸及停損價位,則在最新時間出場
            elif KBar['close'][n] > StopLossPoint:
                OrderRecord.Cover('Buy', KBar['product'][n + 1],
                                  KBar['time'][n + 1], KBar['open'][n + 1], 1)
                continue
            # 若小於 布林通道下界 則停利出場
            if KBar['close'][n] <= KBar['Lower'][n]:
                OrderRecord.Cover('Buy', KBar['product'][n + 1],
                                  KBar['time'][n + 1], KBar['open'][n + 1], 1)
                continue

# 將回測紀錄寫至MicroTest中
OrderRecord.FutureMicroTestRecord('5-4-4-F', 200, 50)

# 繪製走勢圖加上MA以及下單點位
from chart import ChartOrder_BBANDS
ChartOrder_BBANDS(KBar, OrderRecord.GetTradeRecord())