Skip to content

Commit

Permalink
增加ATR
Browse files Browse the repository at this point in the history
  • Loading branch information
idoall committed Mar 6, 2023
1 parent 3cd32be commit f6d4173
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nuxt.isNuxtApp": false
}
57 changes: 57 additions & 0 deletions commonstock/ATR.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package commonstock

import (
"math"
"time"

"github.com/idoall/TokenExchangeCommon/commonmodels"
)

// ATR struct
type ATR struct {
Period int //默认计算几天的MA,KDJ一般是9,OBV是10、20、30
data []ATRPoint
kline []*commonmodels.Kline
}

type ATRPoint struct {
Time time.Time
TR float64
ATR float64
}

// NewATR new Func
func NewATR(list []*commonmodels.Kline, period int) *ATR {
m := &ATR{kline: list, Period: period}
return m
}

// Calculation Func
func (e *ATR) Calculation() *ATR {

for i := 0; i < len(e.kline); i++ {
klineItem := e.kline[i]
var ATRPointStruct ATRPoint
ATRPointStruct.TR = math.Max(klineItem.High-klineItem.Low, math.Max(klineItem.High-klineItem.Close, klineItem.Close-klineItem.Low))
ATRPointStruct.Time = e.kline[i].KlineTime
e.data = append(e.data, ATRPointStruct)
}

var tempKline []*commonmodels.Kline
for _, v := range e.data {
tempKline = append(tempKline, &commonmodels.Kline{
Close: v.TR,
})
}

var atr = NewEMA(tempKline, e.Period).Calculation().GetPoints()
for i := 0; i < len(atr); i++ {
e.data[i].ATR = atr[i].Value
}
return e
}

// GetPoints Func
func (e *ATR) GetPoints() []ATRPoint {
return e.data
}
1 change: 1 addition & 0 deletions commonstock/MACD.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type MACDPoint struct {
DIF float64
DEA float64
MACD float64
Hist float64
}

// NewMACD new Func
Expand Down
4 changes: 2 additions & 2 deletions commonutils/checkmail/checkmail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestValidateHost(t *testing.T) {
continue
}

err := checkmail.ValidateHost(s.mail)
err := ValidateHost(s.mail)
if err != nil && s.account == true {
t.Errorf(`"%s" => unexpected error: "%v"`, s.mail, err)
}
Expand All @@ -45,7 +45,7 @@ func TestValidateHost(t *testing.T) {

func TestValidateFormat(t *testing.T) {
for _, s := range samples {
err := checkmail.ValidateFormat(s.mail)
err := ValidateFormat(s.mail)
if err != nil && s.format == true {
t.Errorf(`"%s" => unexpected error: "%v"`, s.mail, err)
}
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module github.com/idoall/TokenExchangeCommon

go 1.17

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/json-iterator/go v1.1.5
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
github.com/stretchr/testify v1.2.2 // indirect
)

go 1.13
require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/stretchr/testify v1.8.2 // indirect
)
14 changes: 12 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
Expand All @@ -10,5 +11,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit f6d4173

Please sign in to comment.