python 程序化交易_均线策略(python版)

均线策略(python版)

均线策略(python版)

Author: 小小梦, Date: 2016-09-08 18:43:58

Tags: Python 均线

均线策略(python版)教学性质,实盘慎用。

import types

def main():

STATE_IDLE = -1

state = STATE_IDLE

initAccount = ext.GetAccount()

while True:

if state == STATE_IDLE :

n = ext.Cross(FastPeriod,SlowPeriod) # 指标交叉函数

if abs(n) >= EnterPeriod :

opAmount = _N(initAccount.Stocks * PositionRatio,3)

Dict = ext.Buy(opAmount) if n > 0 else ext.Sell(opAmount)

if Dict :

opAmount = Dict['amount']

state = PD_LONG if n > 0 else PD_SHORT

Log("开仓详情",Dict,"交叉周期",n)

else:

n = ext.Cross(ExitFastPeriod,ExitSlowPeriod) # 指标交叉函数

if abs(n) >= ExitPeriod and ((state == PD_LONG and n < 0) or (state == PD_SHORT and n > 0)) :

nowAccount = ext.GetAccount()

Dict2 = ext.Sell(nowAccount.Stocks - initAccount.Stocks) if state == PD_LONG else ext.Buy(initAccount.Stocks - nowAccount.Stocks)

state = STATE_IDLE

nowAccount = ext.GetAccount()

LogProfit(nowAccount.Balance - initAccount.Balance,'钱:',nowAccount.Balance,'币:',nowAccount.Stocks,'平仓详情:',Dict2,'交叉周期:',n)

Sleep(Interval * 1000)

相关内容

更多内容

gaof05210 iikuj

gaof05210 iikuj

期货程序化 这策略回测出场 运行部了

my1000w 第5行,为什么要用ext?这个是什么意思呢,小白求教

小小梦 哦 这个策略 教学为主 实盘慎用,具体是什么问题可以QQ 单M我。

小小梦 这个是 《python 版数字货币交易类库》 模板的一个导出函数。 https://dn-filebox.qbox.me/8ddb571bdcf96f99fbb13f3277874850ddd9cc59.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值