[英]Python: How to count the number of moving average crossovers + highest point between each crossover?
作为第一步,要计算交叉的数量以及它们发生的时间,您可以执行以下操作。 将其视为伪代码以获取想法..
# MA: list containing the values of the moving average for each time period
# High: list containing the highs of each bar
# Low: list containing the lows of each bar
MA = [...]
High = [...]
Low = [...]
count = 0 # the number of crosses
index_cross = [] # the indices where crosses occur
for i in range(len(MA)):
if Low[i] < MA[i] and High[i] > MA[i]:
index_cross.append(i)
count += 1
现在你有了交叉的数量和它们发生的时间。 这假设条形穿过 MA。 (即没有缺口,即前一根柱线的低点高于均线,而当前柱线的高点低于均线)。 然后您可以继续使用 index_cross 指数找到价格与交叉发生位置的最大偏差。 您必须考虑是否使用收盘价,或者在上升趋势高点和下降趋势低点的情况下。
作为旁注,要使用兴趣点注释图形,您可以查看 pandas(用于数据分析的库)。 此外,当市场波动时,此类注释往往会变得非常混乱。 希望这能给一些指导..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.