Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My first thought is, why try to use LINQ on this? It seems like a better situation for making a new <code>Enumerable</code> using the <code>yield</code> keyword to partially process and then spit out an answer.</p> <p>Something along the lines of this:</p> <pre><code>public struct PricePoint { ulong price; ulong volume; } public struct RangePoint { ulong open; ulong close; ulong volume; } public static IEnumerable&lt;RangePoint&gt; calculateRanges(IEnumerable&lt;PricePoint&gt; pricePoints) { if (pricePoints.Count() &gt; 0) { ulong open = pricePoints.First().price; ulong volume = pricePoints.First().volume; foreach(PricePoint pricePoint in pricePoints.Skip(1)) { volume += pricePoint.volume; if (pricePoint.price &gt; open) { if ((pricePoint.price - open) &gt;= STEP) { // We have established a up-trend. RangePoint rangePoint; rangePoint.open = open; rangePoint.close = close; rangePoint.volume = volume; open = pricePoint.price; volume = 0; yield return rangePoint; } } else { if ((open - pricePoint.price) &gt;= REVERSAL_STEP) { // We have established a reversal. RangePoint rangePoint; rangePoint.open = open; rangePoint.close = pricePoint.price; rangePoint.volume = volume; open = pricePoint.price; volume = 0; yield return rangePoint; } } } RangePoint lastPoint; lastPoint.open = open; lastPoint.close = pricePoints.Last().price; lastPoint.volume = volume; yield return lastPoint; } } </code></pre> <p>This isn't yet complete. For instance, it doesn't handle gapping, and there is an unhandled edge case where the last data point might be consumed, but it will still process a "lastPoint". But it should be enough to get started.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload