大伊人青草狠狠久久-大伊香蕉精品视频在线-大伊香蕉精品一区视频在线-大伊香蕉在线精品不卡视频-大伊香蕉在线精品视频75-大伊香蕉在线精品视频人碰人

您現(xiàn)在的位置:程序化交易>> 期貨公式>> 金字塔等>> 金字塔模型>>正文內(nèi)容

金字塔PYTHON海龜交易策略源碼[金字塔模型]

# 本Python代碼主要用于策略交易

?

?


# 可以自己import我們平臺支持的第三方python模塊,比如pandas、numpy等。
from PythonApi import *
import numpy as np
import talib
import math


#? 在這個方法中編寫任何的初始化邏輯。context對象將會在你的算法策略的任何方法之間做傳遞。--(必須實現(xiàn))
def init(context):
??? #入場周期
??? context.X = 20
??? #出場周期
??? context.Y = 10
??? #記錄建倉的atr
??? context.entry = 0
??? #記錄交易次數(shù)
??? context.num = 0
??? #交易標的
??? context.s = context.run_info.base_book_id
??? #記錄上次開倉價
??? context.enterprice = 0


# 你選擇的品種的數(shù)據(jù)更新將會觸發(fā)此段邏輯,例如日或分鐘歷史數(shù)據(jù)切片或者是實時數(shù)據(jù)切片更新。--(必須實現(xiàn))
def handle_bar(context):
??? close = history_bars(context.s,context.X+2,\'self\',\'close\',include_now=True)
??? high = history_bars(context.s,context.X+2,\'self\',\'high\',include_now=True)?
??? low = history_bars(context.s,context.X+2,\'self\',\'low\',include_now=True)??
??? if len(close) == context.X+2:
??????? #atr的計算參考這個帖子http://www.weistock.com/bbs/dispbbs.asp?boardid=10&Id=173300
??????? tr = talib.TRANGE(high,low,close)
??????? atr = talib.SMA(tr[1:],context.X)
??????? unit = int((get_account(6)*0.01) / (atr[-2] * get_dynainf(context.s,209)))
??????? #X天的高低點(不包含當天)
??????? X周期高點 = high[:-1].max()
??????? X周期低點 = low[:-1].min()
???????
??????? #建立頭寸,根據(jù)唐奇安通道創(chuàng)新高入場,關(guān)鍵點就是利用波動atr計算倉位數(shù)量,portfolio用來進行倉位的控制
??????? portfolio=get_portfolio (context.s, 2)
??????? if high[-1]>=X周期高點 and portfolio.buy_quantity==0 and portfolio.sell_quantity==0:
??????????? buy_open(context.s, "Market",0 ,unit,serial_id = 1)
??????????? context.entry = atr[-2]
??????????? context.num = 1
??????????? context.enterprice = close[-1]
??????? if low[-1]<=X周期低點 and portfolio.sell_quantity==0 and portfolio.buy_quantity==0:
??????????? sell_open(context.s, "Market",0 ,unit,serial_id = 2)
??????????? context.entry = atr[-2]
??????????? context.num = 1
??????????? context.enterprice = close[-1]
???????????
??????? #加倉,最高價比上次開倉價多0.5個atr(盈利加倉)
??????? if portfolio.sell_quantity ==0 and portfolio.buy_quantity>0 and high[-1]>context.enterprice + 0.5*context.entry and context.num<4:
??????????? buy_open(context.s, "Market",0 ,unit,serial_id = 3)
??????????? context.num+=1
??????????? context.enterprice = close[-1]
??????? if portfolio.buy_quantity==0 and portfolio.sell_quantity>0 and low[-1]<context.enterprice - 0.5*context.entry and context.num<4:
??????????? sell_open(context.s, "Market",0 ,unit,serial_id = 4)
??????????? context.num+=1
??????????? context.enterprice = close[-1]
???????????
??????? #出場,跌破短周期低點平多
??????? Y周期高點 = high[-context.Y-1:-1].max()
??????? Y周期低點 = low[-context.Y-1:-1].min()
??????? if portfolio.buy_quantity>0 and low[-1] < Y周期低點:
??????????? sell_close(context.s,"Market",0,portfolio.buy_quantity,serial_id = 5)
??????? if portfolio.sell_quantity>0 and high[-1] > Y周期高點:
??????????? buy_close(context.s,"Market",0,portfolio.sell_quantity,serial_id = 6)
???????????
??????? #止損,虧損幅度超過開倉2個atr幅度止損
??????? if portfolio.buy_quantity>0 and low[-1] < context.enterprice - 2*context.entry:
??????????? sell_close(context.s,"Market",0,portfolio.buy_quantity,serial_id = 7)
??????? if portfolio.sell_quantity>0 and high[-1] > context.enterprice + 2*context.entry:
??????????? buy_close(context.s,"Market",0,portfolio.sell_quantity,serial_id = 8)

 

有思路,想編寫各種指標公式,交易模型,選股公式,還原公式的朋友

可聯(lián)系技術(shù)人員 QQ: 262069696  點擊在線交流或微信:cxhjy888 進行 有償收費 編寫!(注:由于人數(shù)限制,QQ或微信請選擇方便的一個聯(lián)系我們就行,加好友時請簡單備注下您的需求,否則無法通過。謝謝您!)

怎么收費,代編流程等詳情請點擊查閱!

(注:由于人數(shù)限制,QQ或微信請選擇方便的一個聯(lián)系我們就行,加好友時請簡單備注下您的需求,否則無法通過。謝謝您!)

 


【字體: 】【打印文章】【查看評論

相關(guān)文章

    沒有相關(guān)內(nèi)容
  主站蜘蛛池模板: 日本中文字幕在线观看视频 | 亚洲第一页在线播放 | 亚洲精品视频一区二区 | 国产激情在线 | 99se亚洲综合色区 | 日本8888xxxx免费视频 | 国产臀控福利视频在线 | 欧美一级午夜免费视频你懂的 | 色综久久天天综合绕视看 | 欧美韩一级片 | 91在线亚洲 | 国产亚洲欧美日韩综合综合二区 | 神马影院午夜剧场 | 天天干天天曰 | 亚洲精品一区二区伦理 | 日日摸夜夜摸无需播放器 | 成人免费毛片网站 | 亚洲第五色综合网 | 成人精品久久 | 在线观看人成午夜影片 | 四虎影视久久久 | 毛片观看网址 | 国产在线欧美精品 | 性欧美高清久久久久久久 | 国产精品乱码高清在线观看 | 大学生一一级毛片在线播放 | 天天操天天添 | 久久乱码精品区中文字幕 | 中文字幕视频一区二区 | 日韩天堂在线 | 美女一级毛片免费不卡视频 | 亚洲va在线va天堂成人 | 亚洲精品久久久 | 看免费5xxaaa| 亚洲精品国产福利在线观看 | 亚洲视频区 | 天天做夜夜做 | 99爱在线精品视频免费观看9 | 日产一一到六区麻豆 | www.欧美激情| 久久影视网|