相關標簽:
?
【zzc_python】移動止損范例
# 本Python代碼主要用于策略交易
# 可以自己import我們平臺支持的第三方python模塊,比如pandas、numpy等。
from PythonApi import *
from datetime import datetime
def init(context):
? ? context.hh = 0
? ??
?
?
?
# 你選擇的品種的數據更新將會觸發此段邏輯,例如日或分鐘歷史數據切片或者是實時數據切片更新。--(必須實現)
def handle_bar(context):
? ? year = context.now.year
? ? month = context.now.month? ??
? ? day = context.now.day
? ? #print((year,month,day))
? ? if year==2018 and month==12 and day==3:
? ? ? ? buy_open("SQRB00", "Market",0 ,1)
? ? portfolio = get_portfolio ("RB00", 2)? ??
? ? bar_close = history_bars(\'SQRB00\',1,\'1d\',\'CLOSE\')
? ? if portfolio.buy_quantity>0 and bar_close>context.hh:
? ? ? ? context.hh = bar_close
? ? #print((context.hh,bar_close))
? ? if portfolio.buy_quantity>0 and (context.hh - bar_close)/context.hh >0.1:
? ? ? ? sell_close("SQRB00", "Market",0 ,1)
? ? ? ? context.hh = 0
?
{別忘了將本網告訴您身邊的朋友,向朋友傳達有用資料,也是一種人情,你朋友會感謝你的。}
?