markcheno / go-talib

A pure Go port of TA-Lib (http://ta-lib.org)
MIT License
763 stars 213 forks source link

Trix Index out of range #18

Closed GeorgeGkinis closed 3 years ago

GeorgeGkinis commented 3 years ago

Trix seems to have an index out of bounds issue :

package main

import (
    "fmt"
    "github.com/markcheno/go-talib"
)
func main() {
    v:=[]float64{0,1,2,3,4,5,6,7,8,9}
    t:=talib.Trix(v,5)
    fmt.Print(t)
}

panic: runtime error: index out of range [2] with length 2

goroutine 1 [running]:
github.com/markcheno/go-talib.ema(0xc00000c350, 0x2, 0x2, 0x5, 0x3fd5555555555555, 0xc00000c330, 0x6, 0x6)
    C:/Users/USER/go/src/github.com/markcheno/go-talib/talib.go:114 +0x13b
github.com/markcheno/go-talib.Ema(...)
    C:/Users/USER/go/src/github.com/markcheno/go-talib/talib.go:141
github.com/markcheno/go-talib.Trix(0xc00010ff18, 0xa, 0xa, 0x5, 0x60, 0x1940e000108, 0x60)
    C:/Users/USER/go/src/github.com/markcheno/go-talib/talib.go:3077 +0x165
main.main()
    C:/TrixBug/tb.go:9 +0x105
markcheno commented 3 years ago

You are not supplying enough data for the calculation. If you increase v to length 13 or more, it works fine. I agree it should probably have some bounds checking, but since this is a direct port of TaLib, so that lib has the same issue. I would rather not see them diverge.