Skip to content

Commit

Permalink
remove rounding from scripting TA (thrasher-corp#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazbert authored Nov 9, 2020
1 parent 70e0cd1 commit f050c13
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 22 deletions.
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/atr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -87,7 +86,7 @@ func atr(args ...objects.Object) (objects.Object, error) {
r.Period = inTimePeriod
ret := indicators.ATR(ohlcvData[2], ohlcvData[3], ohlcvData[4], inTimePeriod)
for x := range ret {
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
r.Value = append(r.Value, &objects.Float{Value: ret[x]})
}

return r, nil
Expand Down
7 changes: 3 additions & 4 deletions gctscript/modules/ta/indicators/bbands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -125,12 +124,12 @@ func bbands(args ...objects.Object) (objects.Object, error) {
retUpper, retMiddle, retLower := indicators.BBANDS(ohlcvData[selector], inTimePeriod, inNbDevDn, inNbDevDn, MAType)
for x := range retMiddle {
temp := &objects.Array{}
temp.Value = append(temp.Value, &objects.Float{Value: math.Round(retMiddle[x]*100) / 100})
temp.Value = append(temp.Value, &objects.Float{Value: retMiddle[x]})
if retUpper != nil {
temp.Value = append(temp.Value, &objects.Float{Value: math.Round(retUpper[x]*100) / 100})
temp.Value = append(temp.Value, &objects.Float{Value: retUpper[x]})
}
if retLower != nil {
temp.Value = append(temp.Value, &objects.Float{Value: math.Round(retLower[x]*100) / 100})
temp.Value = append(temp.Value, &objects.Float{Value: retLower[x]})
}
r.Value = append(r.Value, temp)
}
Expand Down
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/correlation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -84,7 +83,7 @@ func correlationCoefficient(args ...objects.Object) (objects.Object, error) {

ret := indicators.CorrelationCoefficient(closures1, closures2, inTimePeriod)
for x := range ret {
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
r.Value = append(r.Value, &objects.Float{Value: ret[x]})
}

return r, nil
Expand Down
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/ema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -72,7 +71,7 @@ func ema(args ...objects.Object) (objects.Object, error) {

ret := indicators.EMA(ohlcvClose, inTimePeriod)
for x := range ret {
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
r.Value = append(r.Value, &objects.Float{Value: ret[x]})
}

return r, nil
Expand Down
7 changes: 3 additions & 4 deletions gctscript/modules/ta/indicators/macd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -85,12 +84,12 @@ func macd(args ...objects.Object) (objects.Object, error) {
macd, macdSignal, macdHist := indicators.MACD(ohlcvClose, inFastPeriod, inSlowPeriod, inTimePeriod)
for x := range macdHist {
tempMACD := &objects.Array{}
tempMACD.Value = append(tempMACD.Value, &objects.Float{Value: math.Round(macdHist[x]*100) / 100})
tempMACD.Value = append(tempMACD.Value, &objects.Float{Value: macdHist[x]})
if macd != nil {
tempMACD.Value = append(tempMACD.Value, &objects.Float{Value: math.Round(macd[x]*100) / 100})
tempMACD.Value = append(tempMACD.Value, &objects.Float{Value: macd[x]})
}
if macdSignal != nil {
tempMACD.Value = append(tempMACD.Value, &objects.Float{Value: math.Round(macdSignal[x]*100) / 100})
tempMACD.Value = append(tempMACD.Value, &objects.Float{Value: macdSignal[x]})
}
r.Value = append(r.Value, tempMACD)
}
Expand Down
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/mfi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -87,7 +86,7 @@ func mfi(args ...objects.Object) (objects.Object, error) {

ret := indicators.MFI(ohlcvData[2], ohlcvData[3], ohlcvData[4], ohlcvData[5], inTimePeriod)
for x := range ret {
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
r.Value = append(r.Value, &objects.Float{Value: ret[x]})
}

return r, nil
Expand Down
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/obv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -81,7 +80,7 @@ func obv(args ...objects.Object) (objects.Object, error) {

ret := indicators.OBV(ohlcvData[4], ohlcvData[5])
for x := range ret {
temp := &objects.Float{Value: math.Round(ret[x]*100) / 100}
temp := &objects.Float{Value: ret[x]}
r.Value = append(r.Value, temp)
}
return r, nil
Expand Down
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/rsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -71,7 +70,7 @@ func rsi(args ...objects.Object) (objects.Object, error) {
r.Period = inTimePeriod
ret := indicators.RSI(ohlcvClose, inTimePeriod)
for x := range ret {
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
r.Value = append(r.Value, &objects.Float{Value: ret[x]})
}

return r, nil
Expand Down
3 changes: 1 addition & 2 deletions gctscript/modules/ta/indicators/sma.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package indicators
import (
"errors"
"fmt"
"math"
"strings"

objects "github.com/d5/tengo/v2"
Expand Down Expand Up @@ -69,7 +68,7 @@ func sma(args ...objects.Object) (objects.Object, error) {
r.Period = inTimePeriod
ret := indicators.SMA(ohlcvClose, inTimePeriod)
for x := range ret {
r.Value = append(r.Value, &objects.Float{Value: math.Round(ret[x]*100) / 100})
r.Value = append(r.Value, &objects.Float{Value: ret[x]})
}

return r, nil
Expand Down

0 comments on commit f050c13

Please sign in to comment.