简体   繁体   English

确定支撑/阻力水平和趋势线

[英]Identify Support / Resistance levels & Trend-lines

I don't need a code just the logic on how to do this.我不需要代码,只需要有关如何执行此操作的逻辑。 Example of S/R levels and a trendline S/R 水平和趋势线的示例

I know s/r levels differ from one person to another so I have attached a graph to show what criteria I use to consider a support/resistance level or a trend line.我知道 s/r 水平因人而异,所以我附上了一张图表来显示我使用什么标准来考虑支撑/阻力水平或趋势线。

  • S/R level has to have more than 2 touches if there are more than over fits this criterion then the one with most touchdowns is the valid one, same for resistance. S/R 水平必须有超过 2 次触球,如果有超过 2 次触地得分,那么触地得分最多的就是有效触地得分,阻力也一样。

  • A trend line has to have 3 touches in order to be valid.趋势线必须有 3 次接触才能有效。

All lines have a margin error since these lines can get extended.所有的线都有一个边距错误,因为这些线可以被延长。 and of course, once a support line is broken it turns into resistance.当然,一旦支撑线被突破,它就会变成阻力。

I tried taking an array of min values then see if other bars fall within a certain range of these values but it wasn't accurate enough!我尝试采用一组最小值,然后查看其他条形是否落在这些值的某个范围内,但它不够准确!

Below is something for you to start with.下面是一些让你开始的东西。 Emphasis on the 'start' because it doesn't directly answer your questions.强调“开始”,因为它不会直接回答您的问题。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

Simulate data.模拟数据。

np.random.seed(42)
mu = 0.03
ret = mu+np.random.randn(500)
price = 1+np.cumsum(ret)

Look for support by first, removing noise from signal with moving average.首先寻找support ,用移动平均从信号中去除噪声。 Offset by support value, then look for locations where offset value is at zero, which would be the locations touching the support line .support值偏移,然后查找偏移值为零的位置,这将是接触support line的位置。

def get_support_line(df,days=100):
    df['price_ma']=df['price'].rolling(5).mean()
    df = df.dropna()
    supports={}

    for x in np.arange(0,len(df)-days,10):
        price_tmp = df.iloc[x:x+days]['price_ma'].values
        # offset signal by support value, loc crossing 0 will be support.
        support_val = price_tmp[-1]
        norm = price_tmp-support_val
        lim = 0.05 # hack to find intersect with support line with tolerance
        signal = np.logical_and(norm<lim,norm>-1*lim).astype(np.int)
        inds = np.where(np.diff(signal)>0)[0]
        if np.sum(signal)>3:
            supports[x+days]={
                'x':inds+x,
                'y':support_val*np.ones(inds.shape)
            }
    return df, supports

df = pd.DataFrame()
df['price']=price
df, supports = get_support_line(df)

Plot to verify logic.绘图以验证逻辑。 You now should start tweaking the free parameters and also the logic to your "liking".您现在应该开始根据您的“喜好”调整自由参数和逻辑。

df.plot(figsize=(10,5))
for k,v in supports.items():
    print('support identified at days prior index',k,'value: {:1.2f}'.format(v['y'][0]),'touch inds:',v['x'])
    plt.plot([v['x'][0],v['x'][-1]],[v['y'][0],v['y'][-1]],color='red')
plt.grid(True)

在此处输入图片说明

I don't buy technical analysis, but I think this is an interesting problem, implementation wise!我不买技术分析,但我认为这是一个有趣的问题,实施明智! There should be lots of libraries out there.那里应该有很多图书馆。 so please be sure to do a google search, and come back and share your solutions and findings.所以请务必进行谷歌搜索,然后回来分享您的解决方案和发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM