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

您現在的位置:程序化交易>> 期貨公式>> 金字塔等>> 金字塔模型>>正文內容

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

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

?

?


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


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


# 你選擇的品種的數據更新將會觸發此段邏輯,例如日或分鐘歷史數據切片或者是實時數據切片更新。--(必須實現)
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()
???????
??????? #建立頭寸,根據唐奇安通道創新高入場,關鍵點就是利用波動atr計算倉位數量,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)

 

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

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

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

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

 


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

相關文章

    沒有相關內容
  主站蜘蛛池模板: 伊人色院成人蜜桃视频 | 四虎影院永久网站 | 黄色福利在线观看 | 天堂男人在线 | 中文字幕在线播放一区 | 日韩亚洲欧洲在线rrrr片 | 五月婷婷狠狠 | 99精品视频在线观看免费播放 | 久久精品国产精品青草 | 精品国产一区二区三区成人 | 久久精品视频播放 | 尤物视频国产 | 97在线公开视频 | 亚洲欧美高清视频 | 欧美一级亚洲一级 | 老年人一级特黄aa大片 | 成人一级免费视频 | 9191久久久久视频 | 国产精品嫩草影院奶水 | 午夜福利毛片 | 西西大胆实体啪啪色哟哟 | 欧美不卡影院 | 国产精品香蕉一区二区三区 | 99r8这里精品热视频免费看 | 五月天激情在线 | 天天草夜夜草 | 久久中文网中文字幕 | 日韩一区国产二区欧美三 | 精品国产不卡一区二区三区 | 天天看片日日夜夜 | 一级毛片看一个 | 番茄视频在线观看黄版本免费 | 久久久免费视频播放 | 色久影院 | 国产码欧美日韩高清综合一区 | 久久精品图片 | 看免费黄色一级视频 | 久久乐国产精品亚洲综合m3u8 | 欧美国产高清 | 91精品国产综合久久精品 | 成人免费国产欧美日韩你懂的 |