Esempio n. 1
0
             StopLossPoint = OrderPrice * (1-MoveStopLoss)
             LastOrderDay = KBar['time'][n].strftime('%Y%m%d')
         elif KBar['close'][n] < FloorPrice[Date] - Spread[Date] :
             OrderRecord.Order('Sell', KBar['product'][n+1],KBar['time'][n+1],KBar['open'][n+1],1)
             OrderPrice = KBar['open'][n+1]
             StopLossPoint = OrderPrice * (1+MoveStopLoss)
             LastOrderDay = KBar['time'][n].strftime('%Y%m%d')
         
 # 如果有多單部位,則在1330點以後立即平倉    
 elif OrderRecord.GetOpenInterest()==1 :
     # 逐筆更新移動停損價位
     if KBar['close'][n] * (1-MoveStopLoss) > StopLossPoint :
         StopLossPoint = KBar['close'][n] * (1-MoveStopLoss)
     # 判斷到期出場
     if KBar['time'][n].strftime('%H%M') >= "1330" :
         OrderRecord.Cover('Sell', KBar['product'][n],KBar['time'][n],KBar['open'][n],1)
     # 如果上一根K的收盤價觸及停損價位,則在最新時間出場
     elif KBar['close'][n] < StopLossPoint :
         OrderRecord.Cover('Sell', KBar['product'][n+1],KBar['time'][n+1],KBar['open'][n+1],1)
 
 # 如果有空單部位,則在1330點以後立即平倉    
 elif OrderRecord.GetOpenInterest()==-1 :
     # 逐筆更新移動停損價位
     if KBar['close'][n] * (1+MoveStopLoss) < StopLossPoint :
         StopLossPoint = KBar['close'][n] * (1+MoveStopLoss)
     # 判斷到期出場
     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] > StopLossPoint :
         OrderRecord.Cover('Buy', KBar['product'][n+1],KBar['time'][n+1],KBar['open'][n+1],1)
Esempio n. 2
0
# 訂閱報價
GO = haohaninfo.GOrder.GOQuote()

# 進場判斷
for row in GO.Subscribe(Broker, 'match', Product):
    # 取得時間、價格欄位
    Time = datetime.datetime.strptime(row[0], '%Y/%m/%d %H:%M:%S.%f')
    Price = float(row[2])
    # 無條件進場多單
    OrderRecord.Order('B', Product, Time, Price, 1)
    # 進場後判斷最高價變數
    AfterOrder = Price
    print(Time, '價格', Price, '無條件進場多單')
    GO.EndSubscribe()

# 出場判斷
for row in GO.Subscribe(Broker, 'match', Product):
    # 取得時間、價格欄位
    Time = datetime.datetime.strptime(row[0], '%Y/%m/%d %H:%M:%S.%f')
    Price = float(row[2])
    # 判斷移動停損
    if Price > AfterOrder:
        AfterOrder = Price
    elif Price <= AfterOrder - StopLoss:
        # 空單出場
        OrderRecord.Cover('S', Product, Time, Price, 1)
        print(Time, '價格', Price, '進場後最高價', AfterOrder, '移動停損出場')
        GO.EndSubscribe()

print('全部交易紀錄', OrderRecord.GetTradeRecord())