大伊人青草狠狠久久-大伊香蕉精品视频在线-大伊香蕉精品一区视频在线-大伊香蕉在线精品不卡视频-大伊香蕉在线精品视频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)容
  主站蜘蛛池模板: 免费视频爱爱太爽了 | 狠狠操福利视频 | 奶交性视频欧美 | 欧美日韩亚洲一区二区 | 久久狠狠婷婷丁香香蕉 | 亚洲欧美精品日韩欧美 | 99久久国产亚洲综合精品 | 亚洲一区二区三区在线播放 | 欧美一区二区三区久久久人妖 | 亚洲久草 | 看全色黄大色黄大片 视 | 欧美日韩亚洲综合在线一区二区 | 亚洲在线一区二区 | 国产精品免费一区二区三区四区 | 操一操干一干 | 国产五月色婷婷六月丁香视频 | 免费超爽大片黄网站 | 四虎黄色影院 | 乡下女色又黄一级毛片 | 国产精品99在线观看 | 久久亚洲这里只有精品18 | 极品精品国产超清自在线观看 | 久青草国产手机在线观 | 麻豆久久婷婷综合五月国产 | 男人猛桶女人下面视频国产 | 日韩欧美综合视频 | 日日插天天操 | 久草午夜| 一本久道综合久久精品 | 2022色婷婷综合久久久 | 西西做人爱免费视频 | 久久精品国产屋 | 欧美午夜精品一区二区三区 | 久久国产精品永久免费网站 | 国产美女激情视频 | 国产成人精品免费午夜 | 亚洲成片观看四虎永久 | 久久久久久久91精品免费观看 | 色综合久久88色综合天天小说 | 天天爽夜夜爽天天做夜夜做 | 五月亭亭免费高清在线 |