평선 전략 (python 버전)

저자:작은 꿈, 날짜: 2016-09-08 18:43:58
태그:파이썬MA

유평선 전략 (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)



관련

더 많은

가오프05210이쿠

가오프05210이쿠

my1000w5번 줄, 왜 ext를 사용합니까?

작은 꿈이 문서는 파이썬 버전의 디지털 화폐 거래 도서관 템플릿의 출력 함수입니다. https://dn-filebox.qbox.me/8ddb571bdcf96f99fbb13f3277874850ddd9cc59.png