Profile Picture

Bars between Highest and Lowest

Posted By ywlee 3 Years Ago
Message
Posted Thursday April 03 2014
Hi

What is the best way to get the number of days between the highest and lowest bars within say 20 days/bars?

phg
Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)Supreme Being (44,517 reputation)
Whistling Posted Friday April 04 2014
That's a tougher question than it seems at first glance. On each new bar one old bar ages out of consideration while the new one replaces it. Identifying the oldest one is easy since the bar series is in date order. But lowest and highest are less apparent. 'Caching' them could pay off for a 'long' interval. But for 20 my guess is the brute force approach should be tried. Not a very clever suggestion I know, but . . .

Caching becomes a bit complicated: keep the date of the highest and lowest. On each new bar, mark departing bar as not highest if highest is replaced by new bar. Similarly for lowest. If departing bar is marked both not highest and not lowest you are done (probably no need to actually make this test since this result is fall-out from the next two tests). Otherwise (if not marked) if departing matches highest use brute force to look for new highest. Same for lowest. (Order of tests may not be optimal. I did not test this so the logic may actually be screwed up. Whistling )

I don't know whether I am helping or not?

-Pete

See also Yahoo group about applying RE.

Posted Saturday April 05 2014
Try the following with Linq. I have not tested it but it should give you enough to get the answer by adjusting as required. The code below compiles so it should work straight away.

// outside of NewBar
var barData = new List();

// in NewBar
barData.Add(Bars.Current);
var lowBar = (from b in barData
where b.Low == BarUtils.LowestLow(barData, barData.Count - 21, 20)
select b).First();
var highBar = (from b in barData
where b.High == BarUtils.HighestHigh(barData, barData.Count - 21, 20)
select b).First();
var days = Math.Abs((int)lowBar.BarStartTime.Subtract(highBar.BarStartTime).TotalDays);

Duane
Posted Tuesday April 08 2014
Thanks! Will try it out.


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems