Loading ...

MA21

Author: 悟空-如来-泰达打印机-量化, Date: 2021-03-18 17:03:28
Tags:


'''
MA21策略
站上买,跌破卖
'''
import datetime

def onTick():
    '''轮训函数'''
    account = _C(exchange.GetAccount)
    Log(account)
    kline_data = _C(exchange.GetRecords, PERIOD_M15)
    # 前一个周期的MA21值,排除当前周期
    ma21_list = TA.MA(kline_data, 21)
    if len(ma21_list) >= 2:
        ma21 = ma21_list[-2]
    
        if ma21:
            # 如果有值,回测时间段内开始的几个周期,没有ma21
        
            # 取上个周期的开盘价、收盘价
            open_price = kline_data[-2].Open
            close_price = kline_data[-2].Close
            Log('当前:open_price=', open_price, ',close_price=', close_price, ',ma21=', ma21)
        
            if open_price < ma21 < close_price:
                 Log('买')
                 #发送邮箱
                 Mail('ssl://smtp.163.com:465','wxslzmb@163.com','OTFGVFUKWMECXJVP','63196979@qq.com','21均线买入','15分钟k线上穿21均线 可参考买入 ,切记:如果不断上下穿插不操作')
                 #和平 
                 Mail('ssl://smtp.163.com:465','wxslzmb@163.com','OTFGVFUKWMECXJVP','723737930@qq.com','21均线买入','15分钟k线上穿21均线 可参考买入, 切记:如果不断上下穿插不操作') 
                 #exchange.Buy(-1, account.Balance)
             
            elif close_price < ma21 < open_price:
                #and account.Stocks > 0.1
                Log('卖')
                #exchange.Sell(-1, account.Stocks)
                Mail('ssl://smtp.163.com:465','wxslzmb@163.com','OTFGVFUKWMECXJVP','63196979@qq.com','21均线卖出','15分钟k线击穿21均线参考卖出,切记:如果不断上下穿插不操作')
                #和平
                Mail('ssl://smtp.163.com:465','wxslzmb@163.com','OTFGVFUKWMECXJVP','723737930@qq.com','21均线卖出','15分钟k线击穿21均线参考卖出,切记:如果不断上下穿插不操作')
            else:
                Log('无行情')
        else:
            Log('当前时间无ma21供参考')

def wait_to_time():
    '''等待15分钟'''
   
   
    # Log(s)
    Sleep(13* 60 * 1000)

def main():
    # 设置重试延迟
    _CDelay(RETRY_INTERVAL * 1000)
    while True:
        onTick()
        wait_to_time()
        # Sleep(LOOP_INTERVAL * 1000)

More