GithubHelp home page GithubHelp logo

go-pine's Introduction

go-pine

Pinescript to Golang

Build Status docs godocs codecov Go Report Card HitCount Maintainability

Example

PineScript

study("Pine test")

lengthshort = 5
lengthlong = 20
span = 10

source = close
basis = sma(source, lengthshort)
basis2 = sma(source, lengthlong)
multi = basis * basis2
upperBB = basis + span
lowerBB = basis - span

Golang

// initiate
initialData := make([]pine.OHLCV)
opts := pine.SeriesOpts{
  Interval: 300,
  Max: 30,
  EmptyInst: pine.EmptyInstUseLastClose,
}
s, _ := pine.NewSeries(initialData, opts)

// load indicators
short := 5
long := 20
span := 10
source := pine.NewOHLCProp(pine.OHLCPropClose)
basis := pine.NewSMA(source, short)
basis2 := pine.NewSMA(source, long)
multi := pine.NewArithmetic(pine.ArithmeticMultiplication, basis, basis2)
upperBB := pine.NewArithmetic(pine.ArithmeticAddition, basis, span)
lowerBB := pine.NewArithmetic(pine.ArithmeticSubtraction, basis, span)

s.AddIndicator("upperBB", upperBB)
s.AddIndicator("lowerBB", lowerBB)
s.AddIndicator("multi", multi)

// then add OHLCV or exec and play
t := time.Now()
s.AddOHLCV(pine.OHLCV{O: 14, L: 10, H: 19, C: 14, V: 432, S: t })
s.AddOHLCV(pine.OHLCV{O: 15, L: 8, H: 18, C: 15, V: 192, S: t.Add(time.Minute * 5) })
s.AddOHLCV(pine.OHLCV{O: 16, L: 9, H: 16, C: 13, V: 325, S: t.Add(time.Minute * 10) })
s.AddOHLCV(pine.OHLCV{O: 17, L: 10, H: 19, C: 11, V: 82, S: t.Add(time.Minute * 15) })
...

// or, if you're relying on exec information
s.AddExec(pine.TPQ{Qty: 13, Px: 12.3, Timestamp: t.Add(time.Second * 4) })
s.AddExec(pine.TPQ{Qty: 18, Px: 12.5, Timestamp: t.Add(time.Second * 8) })
s.AddExec(pine.TPQ{Qty: 12, Px: 12.6, Timestamp: t.Add(time.Second * 8) })


v := s.GetValueForInterval(t)

log.Printf("OHLCV: %+v", v.OHLCV)
log.Printf("Indicator values: %+v", v.Indicators)

Limitations

  • Assumes initial data is sequential in time ascending order

Features

TBD

go-pine's People

Contributors

tsuz avatar

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.