Comments (4)
Hey @Krisa,
sorry for the delayed response here. Can you provide an example?
from techan.
here:
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/adshao/go-binance"
"github.com/sdcoffey/big"
"github.com/sdcoffey/techan"
)
func main() {
series := getSeries()
closePrices := techan.NewClosePriceIndicator(series)
// Show EMAs
EMA10 := techan.NewEMAIndicator(closePrices, 10)
EMA20 := techan.NewEMAIndicator(closePrices, 20)
EMA10Price := EMA10.Calculate(series.LastIndex() - 1).Float()
EMA20Price := EMA20.Calculate(series.LastIndex() - 1).Float()
log.Printf("EMA10Price: %v", EMA10Price)
log.Printf("EMA20Price: %v", EMA20Price)
// Show RSI
rsi14 := techan.NewRelativeStrengthIndexIndicator(closePrices, 14)
rsi14Calculated := rsi14.Calculate(series.LastIndex() - 1).Float()
log.Printf("rsi14: %v", rsi14Calculated)
}
func getSeries() *techan.TimeSeries {
binanceClient := binance.NewClient("", "")
klines, err := binanceClient.
NewKlinesService().
Symbol("BTCUSDT").
Interval("1h").
Do(context.Background())
if err != nil {
fmt.Println(err)
return nil
}
series := techan.NewTimeSeries()
for _, kline := range klines {
start := time.Unix(0, 1000000*kline.OpenTime)
end := time.Unix(0, 1000000*kline.CloseTime)
period := techan.NewTimePeriod(start, end.Add(1*time.Millisecond).Sub(start))
candle := techan.NewCandle(period)
candle.OpenPrice = big.NewFromString(kline.Open)
candle.ClosePrice = big.NewFromString(kline.Close)
candle.MaxPrice = big.NewFromString(kline.High)
candle.MinPrice = big.NewFromString(kline.Low)
candle.Volume = big.NewFromString(kline.Volume)
candle.TradeCount = uint(kline.TradeNum)
series.AddCandle(candle)
}
return series
}
You can compare to the real chart here: https://www.tradingview.com/symbols/BTCUSDT/?exchange=BINANCE
EMA 10 and 20 are both perfectly calculated, RSI, at the time of writing (since it takes time.Now() - 1 hour
) is quite off (45.53 real, 51.26 calculated)
from techan.
Thanks for the snippet @Krisa, let me see if I can fix
from techan.
@Krisa sorry for taking so long to get to this. The issue should be fixed in v0.8.0, please give it a whirl and re-open if it persists.
from techan.
Related Issues (20)
- EMA calculation differ from ta4j documentation
- Integrating multiple timeframes into a single strategy
- Feature request - add support for KDJ or Stochastic Oscillator HOT 2
- Indicator should have Len() method
- TimeSeries should be able to export Indicators representing OCHLV value series
- Proposal: Use shopspring/decimal instead of bespoke decimal interface HOT 2
- MACD Signal line (EMA) seems to be broken/not working... HOT 6
- should EMA consider time window? HOT 2
- SMA and EMA get the same result
- [Feature] Support/Resistance levels indicator
- Requesting improved documentation by examples and more detailed comments
- if the price type is float then it might lose some accuracy?
- Unable to use the library
- EMA always return 0.00 HOT 2
- SMA Bug in v0.12.1 ? HOT 1
- Macd Signal HOT 1
- Cashing in indicators HOT 1
- Checkout-Java-SDK HOT 1
- What is the status of this package? HOT 2
- Is this project dead? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from techan.