Hopefully finish Ichimoku()

This commit is contained in:
Luke I. Wilson
2023-05-22 09:49:55 -05:00
parent 30b6482fbf
commit c0de28664e
4 changed files with 102 additions and 15 deletions

View File

@@ -14,10 +14,18 @@ const float64Tolerance = float64(1e-6)
var ErrNotASignedNumber = errors.New("not a signed number")
// Crossover returns true if the latest a value crosses above the latest b value, but only if it just happened. For example, if a series is [1, 2, 3, 4, 5] and b series is [1, 2, 3, 4, 3], then Crossover(a, b) returns false because the latest a value is 5 and the latest b value is 3. However, if a series is [1, 2, 3, 4, 5] and b series is [1, 2, 3, 4, 6], then Crossover(a, b) returns true because the latest a value is 5 and the latest b value is 6
func Crossover(a, b Series) bool {
func Crossover(a, b *Series) bool {
return a.Float(-1) > b.Float(-1) && a.Float(-2) <= b.Float(-2)
}
func CrossoverIndex[I comparable](index I, a, b *IndexedSeries[I]) bool {
aRow, bRow := a.Row(index), b.Row(index)
if aRow < 1 || bRow < 1 {
return false
}
return a.Float(aRow) > b.Float(bRow) && a.Float(aRow-1) <= b.Float(bRow-1)
}
// EasyIndex returns an index to the `n` -length object that allows for negative indexing. For example, EasyIndex(-1, 5) returns 4. This is similar to Python's negative indexing. The return value may be less than zero if (-i) > n.
func EasyIndex(i, n int) int {
if i < 0 {