在图表中识别本地高点

发布于 2025-02-10 19:22:21 字数 2273 浏览 1 评论 0原文

S& p 500高点

以下是S& p 500的图表

。 =“ https://i.sstatic.net/b402f.png” alt =“在此处输入图像描述”>

人们通常在谈论历史价格数据时通常指“所有时间高”或“本地高点”。因此,例如,人们可以指的是上面用蓝色箭头注释的高点。

程序以自动找到高点

而不是手动注释图表,我想拥有一个可以识别高点的程序。

这是一个C#函数,似乎可以使用:

List<Candle> identify_highs(List<Candle> rows, TimeSpan threshold)
{
    var ls = new List<Candle>();

    var candidate = rows.First();
                    
    foreach (var row in rows)
    {
        if (row.High > candidate.High)
        {
            var duration = (row.DateTime - candidate.DateTime).Duration();

            if ((row.DateTime - candidate.DateTime).Duration() > threshold)
            {
                ls.Add(candidate);

                candidate = row;
            }
            else
            {
                candidate = row;
            }
        }
    }

    ls.Add(candidate);

    return ls;
}

这是对算法的粗略描述:

Given a list of candles, let the first one be the `candidate`.

For each candle
    If the next candle is higher than the candidate
        If the next candle is far away from the candidate
            The candidate is a high.
            The candle is a new candidate
        Else
            The candle is a new candidate

如果我运行了一个程序,该程序使用此函数绘制数据并使用此函数,则使用threshold175>几天,它输出以下内容:

”在此处输入图像说明“

它也显示了控制台上的高点:

“在此处输入图像说明”

问题

siende_highs上面使用的功能只是一个快速的广告 - HOC功能为此程序组合在一起。

是否有一种流行或已建立的算法来识别图表高点?

项目

在这里生成上述绘图的整个程序:

https> https:// github.com/dharmatech/IndentifyHighscs/blob/master/IndistifyHighscs/program.cs

S&P 500 highs

Here's a chart of the S&P 500 going back before the year 2000.

enter image description here

People commonly refer to "all time highs" or "local highs" when talking about historical price data. So for example, the highs that folks might refer to are annotated above with the blue arrows.

Program to find highs automatically

Instead of manually annotating a chart, I'd like to have a program which identifies the highs.

Here's a C# function which appears to work:

List<Candle> identify_highs(List<Candle> rows, TimeSpan threshold)
{
    var ls = new List<Candle>();

    var candidate = rows.First();
                    
    foreach (var row in rows)
    {
        if (row.High > candidate.High)
        {
            var duration = (row.DateTime - candidate.DateTime).Duration();

            if ((row.DateTime - candidate.DateTime).Duration() > threshold)
            {
                ls.Add(candidate);

                candidate = row;
            }
            else
            {
                candidate = row;
            }
        }
    }

    ls.Add(candidate);

    return ls;
}

Here's a rough description of the algorithm:

Given a list of candles, let the first one be the `candidate`.

For each candle
    If the next candle is higher than the candidate
        If the next candle is far away from the candidate
            The candidate is a high.
            The candle is a new candidate
        Else
            The candle is a new candidate

If I run a program which plots the data and highs using this function with a threshold of 175 days, it outputs the following:

enter image description here

It also displays the highs on the console:

enter image description here

Question

The identify_highs function used above is just a quick ad-hoc function put together for this program.

Is there a popular or established algorithm for identifying chart highs?

Project

The entire program which generates the plot above is here:

https://github.com/dharmatech/IdentifyHighsCs/blob/master/IdentifyHighsCs/Program.cs

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心舞飞扬 2025-02-17 19:22:21

这很容易弄清楚。最后的高(灰色)和未来的低(橙色)

“

图1

。最大值(上方灰线)。在任何时期,灰线的值表示先前的高。

现在,将数据从最新到最旧的扫描,并跟踪最小值(上面的橙色线)。在任何时期,橙色线的值表示下一个低点。

为了找到最后一个高和未来低点的日期,只需找到与计算值匹配的数据中的日期。

This is pretty easy to figure out. The last high (gray), and future low (orange)

fig1

Figure 1. Reverse time SP500 chart (oldest to the right)

Scan the data from oldest to newest and keep track of the maximum value (gray line above). For any period, the value of the gray line indicates the previous high.

Now scan the data from newest to oldest and keep track the minimum value (orange line above). For any period, the value of the orange line indicates the next low.

To find the dates where the last high and future low occurred, just find the date in the data that matches the values calculated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文