-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"nuxt.isNuxtApp": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ type MACDPoint struct { | |
DIF float64 | ||
DEA float64 | ||
MACD float64 | ||
Hist float64 | ||
} | ||
|
||
// NewMACD new Func | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters