Giter Site home page Giter Site logo

rogue-trader's Introduction

Build Status Go Report Card

Trading indicators

The set of trading indicators

Installation

$ go get github.com/evsamsonov/trading-indicators/indicator  

Usage

All indicators requires trading data in timeseries structure

dataset := []struct {
    Time   time.Time
    High   float64
    Low    float64
    Open   float64
    Close  float64
    Volume int64
}{
    {Time: time.Unix(1121979600, 0), High: 23, Low: 21.27, Open: 21.3125, Close: 22.1044, Volume: 4604900},
    {Time: time.Unix(1122238800, 0), High: 23.31999, Low: 22.15, Open: 22.15, Close: 23.21608, Volume: 4132600},
}

series := timeseries.New()
for _, item := range dataset {
    candle := timeseries.NewCandle(item.Time)
    candle.Open = item.Open
    candle.Close = item.Close
    candle.High = item.High
    candle.Low = item.Low
    candle.Volume = item.Volume

    err := series.AddCandle(candle)
    if err != nil {
        log.Printf("Failed to add candle: %v\n", err)
    }
}

Average True Range

Indicator calculates Average True Range (ATR)

period := 2
atrIndicator := indicator.NewAverageTrueRange(series, period)
fmt.Println(atrIndicator.Calculate(1))   // 1.4727950000000014

Average Volume

Indicator calculates Average Volume

period := 2
atrIndicator := indicator.NewAverageVolume(series, period)
fmt.Println(atrIndicator.Calculate(1))  // 4368750

Exponential Moving Average

Indicator calculates Exponential Moving Average

smoothInterval := 2
atrIndicator := indicator.NewExponentialMovingAverage(series, smoothInterval)
fmt.Println(atrIndicator.Calculate(1))  // 22.84552

Trend

The indicator returns a trend direction. It bases on fast (with shorter period) and slow EMA. The third parameter of NewTrend allows setting max difference between fast and slow EMA when Calculate returns the flat.

fastEMAIndicator, err := indicator.NewExponentialMovingAverage(series, 14)
if err != nil {
    log.Fatalln(err)
}
slowEMAIndicator, err := indicator.NewExponentialMovingAverage(series, 50)
if err != nil {
    log.Fatalln(err)
}

trendIndicator := indicator.NewTrend(fastEMAIndicator, slowEMAIndicator, 0.6)
trend := trendIndicator.Calculate(1)
switch trend {
case indicator.UpTrend:
    fmt.Println("Up trend")
case indicator.DownTrend:
    fmt.Println("Down trend")
case indicator.FlatTrend:
    fmt.Println("Flat trend")
}

rogue-trader's People

Contributors

candfan avatar

Watchers

 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.