Code Monkey home page Code Monkey logo

go-talib's Introduction

go-talib

GoDoc

A pure Go port of TA-Lib

Install

Install the package with:

go get github.com/markcheno/go-talib

Import it with:

import "github.com/markcheno/go-talib"

and use talib as the package name inside the code.

Example

package main

import (
	"fmt"
	"github.com/markcheno/go-quote"
	"github.com/markcheno/go-talib"
)

func main() {
	spy, _ := quote.NewQuoteFromYahoo("spy", "2016-01-01", "2016-04-01", quote.Daily, true)
	fmt.Print(spy.CSV())
	rsi2 := talib.Rsi(spy.Close, 2)
	fmt.Println(rsi2)
}

License

MIT License - see LICENSE for more details

Contributors

go-talib's People

Contributors

johnsome avatar markcheno avatar saniales avatar sanyalington avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-talib's Issues

Natr index out of range

data =[]float64 {1,2,3}
Natr(data,data,data,3)
func Natr(....).. {
...
prevATRTemp := Sma(tr, inTimePeriod)
prevATR := prevATRTemp[inTimePeriod]   // will panic 
...
}

Trix Index out of range

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

Index out of range with Stoch()

Steps to reproduce
In your talib_test.go file, change inFastKPeriod to a higher value, e.g. 12.

slowk, slowd := Stoch(testHigh, testLow, testClose, 12, 3, SMA, 3, SMA)

Index out of range error occurs on the following line:
outSlowK[j] = tempBuffer1[i]

RSI indicator not accurite if candles not so enough

e.g.
if it is feed with 11 candles to calculate rsi for 10 days, the result deviation is very heavily ;
if it is feed with 20 candles to calculate rsi for 10 days, the result deviation is small.
if it is feed with 30 candles, the result is nearly same with other libraries.

TestHeikinashiCandles fail

heikinHighs/Opens/Closes/Lows returned from HeikinashiCandles are indexes since 1 not 0
quick fix in talib_test.go:678 under kjx98/master
talib_test.go:729 Crossover to be fixed

HtTrendline Gives index out of range

panic: runtime error: index out of range
goroutine 7 [running]:
github.com/markcheno/go-talib.HtTrendline(0xc42025ea00, 0x1a, 0x20, 0x6, 0xc8, 0xc420268274)
/home/codevarun/go/src/github.com/markcheno/go-talib/talib.go:185 +0x10b5

Discuss a possible implementation upgrade to better match tradingview's pinescript way of code

This would allow to easily import pinescript strategies into go talib based programs

as far as I've seen, the more problematic feature is the security function by tradingview, which allows to switch context and have new candles and manipulate them

from function signature (https://it.tradingview.com/study-script-reference/#fun_security) in its simplest form:

security(symbol, resolution, expression)

where

  • symbol is used to get the candles from the tradingview chart (so it can be substituted with the input of high/low/open/close four []float64 values we can get from any exchange or broker api.
  • resolution is usually a timeframe related, so it can be merged with the 4 float64 arrays as symbol
  • expression is the manipulation we need to perform on data

an example of call would be

security("BTCUSD", "1d", close) // gets the close values from btcusd 1 day chart
security(heikinashi("BTCUSD"), "30m", hlc3) // gets the heikinashi candles of btcusd 30m chart, then performs HLC3 [(high+low+close) / 3] to the gotten series and returns it

To translate this in go-talib way I have an idea:
let's create the following function

func security(inHigh, inOpen, inClose, inLow []float64, expression Manipulator) []float64

the in-arrays represent the symbol + resolution parameters results while the manipulator function will defined as follow:

type Manipulator func(inHigh, inOpen, inClose, inLow []float64) []float64

In this way we would be able to use it like this:

// we do not really care about how candles are extracted, let's assume to use the following function
inHigh, inOpen, inClose, inLow := extractFromSomeCandles(symbol, resolution) // we can extract it from cryptocurrency exchanges as well as from forex brokers
manipulator := talib.Hlc3 // we need to change the signature of the function to follow manipulator signature
// then we use it
result := talib.Security(inHigh, inOpen, inClose, inLow, manipulator)

We can also wrap manipulators one inside another, like the following:

manipulator1 := talib.Hlc3
manipulator2 := func(inHigh, inOpen, inClose, inLow []float64) []float64 {
    manipulatedHigh, manipulatedOpen, manipulatedClose, manipulatedLow := manipulateInSomeWay(inHigh, inOpen, inClose, inLow)
    // pass manipulated array to the second function
    return manipulator1(manipulatedHigh, manipulatedOpen, manipulatedClose, manipulatedLow)
}

A better way should be found though, maybe through the use of a Wrap function in some way

Another idea would be to create a ContextSwitcher function which is like the following

func(inHigh, inOpen, inClose, inLow []float64) ([]float64, []float64, []float64, []float64)

@markcheno what do you think? is it possible in your opinion. In case it's not I can create a separate repo, detaching from talib

Query on plus_di (and similar functions)

go-talib/talib.go

Line 2500 in cd53a92

for i > 0 {

Hello,

I wanted to check the maths on the DI implementation -- I think there might be an off-by-one error in how it's set up. I would expect the first values of prevTR and prevPlusDM to be the sum of the first (period) readings rather than the first (period - 1) -- otherwise these values are systematically under-weighted and (I believe) the ratio converges to the correct value more slowly.

It's more than possible that I've made an error or misunderstood, but thought I ought to flag it up.

Many thanks.

Confused about RSI

go-talib/talib.go

Lines 2819 to 2840 in cd53a92

today := 0
prevValue := inReal[today]
prevGain := 0.0
prevLoss := 0.0
today++
for i := inTimePeriod; i > 0; i-- {
tempValue1 = inReal[today]
today++
tempValue2 = tempValue1 - prevValue
prevValue = tempValue1
if tempValue2 < 0 {
prevLoss -= tempValue2
} else {
prevGain += tempValue2
}
}
prevLoss /= float64(inTimePeriod)
prevGain /= float64(inTimePeriod)
if today > 0 {

Hi Mark, just start reading this source codes, and got a little confused about the today variable in func Rsi, it seems that at L2840 the today will be 3 at least because there's an auto-increament operation at L2823 and min value of inTimePeriod is 2, so the else part at L2850 would never be reached. Is that right?

Macd calculation isn't correct

Hey, i get a different result if i use your macd func with the example data from here

data:

[]float64{
				81.59,
				81.06,
				82.87,
				83.00,
				83.61,
				83.15,
				82.84,
				83.99,
				84.55,
				84.36,
				85.53,
				86.54,
				86.89,
				87.77,
                                87.29,
			},

result:

[0 0 0 0 0 0 0 0 0 0 0 0.9434874256972989 0.9025802469135868 0.9862497078697317 0.6256763196667094]

[0 0 0 0 0 0 0 0 0 0 0 0.1886974851394598 0.3314740374942852 0.46242917156937446 0.49507860118884145]

[0 0 0 0 0 0 0 0 0 0 0 0 0.5711062094193016 0.5238205363003572 0.130597718477868]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.