金字塔PYTHON移動止損策略代碼[金字塔模型]
相關(guān)標(biāo)簽:
?
【zzc_python】移動止損范例
# 本Python代碼主要用于策略交易
# 可以自己import我們平臺支持的第三方python模塊,比如pandas、numpy等。
from PythonApi import *
from datetime import datetime
def init(context):
? ? context.hh = 0
? ??
?
?
?
# 你選擇的品種的數(shù)據(jù)更新將會觸發(fā)此段邏輯,例如日或分鐘歷史數(shù)據(jù)切片或者是實時數(shù)據(jù)切片更新。--(必須實現(xiàn))
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
?
{別忘了將本網(wǎng)告訴您身邊的朋友,向朋友傳達有用資料,也是一種人情,你朋友會感謝你的。}
?
有思路,想編寫各種指標(biāo)公式,交易模型,選股公式,還原公式的朋友
可聯(lián)系技術(shù)人員 QQ: 262069696 或微信:cxhjy888 進行 有償收費 編寫!(注:由于人數(shù)限制,QQ或微信請選擇方便的一個聯(lián)系我們就行,加好友時請簡單備注下您的需求,否則無法通過。謝謝您!)
(注:由于人數(shù)限制,QQ或微信請選擇方便的一個聯(lián)系我們就行,加好友時請簡單備注下您的需求,否則無法通過。謝謝您!)
相關(guān)文章
-
沒有相關(guān)內(nèi)容