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