新增cross_macd_order.py
# -*- coding: utf-8 -*-import talib
import cross_order as order
import time
def main():
print("任务开始时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
for symbol in order.symbol_pool:
# 设置杠杆倍数
order.set_leverage(symbol=symbol, leverage='25')
# 获取标的的最新价
data = order.get_candlesticks(symbol=symbol, interval='15m', limit=str(30))
close = data['close'].values
# MACD: 平滑异同移动平均线
# macd, macdsignal, macdhist = MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
# 参数说明:high:最高价;low:最低价;close:收盘价;fastperiod:快周期; slowperiod:慢周期
macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
# macd 是长短均线的差值,signal是macd的均线,如果短均线从下往上突破长均线,为入场信号,进行买入开仓操作
if (macd.values[-1] - signal.values[-1] > 0) and (macd.values[-2] - signal.values[-2] < 0):
order.up_cross_order(symbol, 'macd入场信号,以市价做多')
# 为出场信号,以市价做空
elif (macd.values[-1] - signal.values[-1] < 0) and (macd.values[-2] - signal.values[-2] > 0):
order.down_cross_order(symbol, 'macd出场信号,以市价做空')
time.sleep(5)
print("任务结束时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
if __name__ == '__main__':
main()
标签:signal,symbol,macd,values,time,量化,区块,order,MACD From: https://www.cnblogs.com/nbjjy/p/17489197.html