输入/搜索内容

均线策略(python版)

Python
复制: 360
点击次数: 6166
8
关注
1381
关注者

均线策略(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)

策略参数
策略参数
入市快线周期
入市慢线周期
入市观察期
离市快线周期
离市慢线周期
离市观察期
仓位比例
轮询周期
评论
全部评论 (4)

    iikuj

    7 年前

    iikuj

    7 年前

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

    10 年前

    这个是 《python 版数字货币交易类库》 模板的一个导出函数。 img

    10 年前
  • 1
社区
回测系统
APP 下载
iPhone 下载
© 2015 - ∞ INVENTOR PTE LTD (SG)