在图表中识别本地高点
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
如果我运行了一个程序,该程序使用此函数绘制数据并使用此函数,则使用threshold
的175
>几天,它输出以下内容:
它也显示了控制台上的高点:
问题
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.
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:
It also displays the highs on the console:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很容易弄清楚。最后的高(灰色)和未来的低(橙色)
图1
。最大值(上方灰线)。在任何时期,灰线的值表示先前的高。
现在,将数据从最新到最旧的扫描,并跟踪最小值(上面的橙色线)。在任何时期,橙色线的值表示下一个低点。
为了找到最后一个高和未来低点的日期,只需找到与计算值匹配的数据中的日期。
This is pretty easy to figure out. The last high (gray), and future low (orange)
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.