资源加载中... loading...

五线向上&&突破前高

Author: 围龙小子, Date: 2018-02-26 23:17:03
Tags: 趋势Python突破

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


import types
import peakutils
import os
import time
import numpy
def main():
	MA_LINES = ['5_8','5_13','5_21','5_34','8_13','8_21','8_34','13_21','13_34','21_34']
	initAccount = ext.GetAccount()
	reported_price_list = []
	while True:
		lines_up = True
		for lines in MA_LINES:
			data = lines.split('_')
			FastPeriod,SlowPeriod = int(data[0]),int(data[1])
			n = ext.Cross(FastPeriod,SlowPeriod)
			if n <= 0:
				lines_up = False
				break

		if lines_up == True:
			records = exchange.GetRecords(PERIOD_M15)
			current_price = records[-1].get("Close", 0)
			times = [record.get("Time", 0) for record in records]
			y = [record.get("High", 0) for record in records]
			x = [i for i in xrange(1,len(y)+1)]
			x, y = numpy.array(x),numpy.array(y)
			n_peaks = 2
			prepared = y - peakutils.baseline(y, 3)
			idx = peakutils.indexes(prepared, thres=0.03, min_dist=10)
			previous_high = y[sorted(idx.tolist()[:10])[-1]]
			previous_time = int(str(times[idx.tolist()[-1]])[:-3])
			previous_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(previous_time))
			if current_price >= previous_high:
				if previous_high not in reported_price_list:
					Log("五线向上,突破前期:",previous_time,"的高点:",previous_high, "当前价格:",current_price)
					reported_price_list.append(previous_high)

		Sleep(1000)
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6