Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TestHeikinashiCandles and TestCrossover #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions talib.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,13 +2010,23 @@ func Macd(inReal []float64, inFastPeriod int, inSlowPeriod int, inSignalPeriod i
fastEMABuffer[i] = fastEMABuffer[i] - slowEMABuffer[i]
}

outMACD := make([]float64, len(inReal))
for i := lookbackTotal - 1; i < len(fastEMABuffer); i++ {
outMACD[i] = fastEMABuffer[i]
/*
for i := lookbackTotal - 1; i < len(fastEMABuffer); i++ {
outMACD[i] = fastEMABuffer[i]
}
*/
outMACD := fastEMABuffer
for i := 0; i < lookbackTotal-1; i++ {
outMACD[i] = 0
}

outMACDSignal := ema(outMACD, inSignalPeriod, (2.0 / float64(inSignalPeriod+1)))

outMACDHist := make([]float64, len(inReal))
//outMACDHist := make([]float64, len(inReal))
outMACDHist := slowEMABuffer
for i := 0; i < lookbackTotal; i++ {
outMACDHist[i] = 0
}
for i := lookbackTotal; i < len(outMACDHist); i++ {
outMACDHist[i] = outMACD[i] - outMACDSignal[i]
}
Expand Down
23 changes: 19 additions & 4 deletions talib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func ok(t *testing.T, err error) {
Expand Down Expand Up @@ -53,7 +52,7 @@ var (
testNothingCrossed1 = []float64{1, 2, 3, 4, 8, 6, 7}
testNothingCrossed2 = []float64{1, 4, 5, 9, 5, 3, 7}

testCrossover1 = []float64{1, 3, 2, 4, 8, 6, 7}
testCrossover1 = []float64{1, 3, 2, 4, 8, 3, 8}
testCrossover2 = []float64{1, 5, 1, 4, 5, 6, 7}
)

Expand Down Expand Up @@ -674,24 +673,40 @@ func TestHeikinashiCandles(t *testing.T) {

resultHigh, resultOpen, resultClose, resultLow := HeikinashiCandles(testHigh, testOpen, testClose, testLow)
for i, expected := range expectedHighs {
i++
if i == len(expectedHighs) {
continue
}
if resultHigh[i] != expected {
t.Errorf("Highs error: Expected %f at cell %d got %f ", expected, i, resultHigh[i])
}
}

for i, expected := range expectedOpens {
i++
if i == len(expectedOpens) {
continue
}
if resultOpen[i] != expected {
t.Errorf("Opens error: Expected %f at cell %d got %f ", expected, i, resultOpen[i])
}
}

for i, expected := range expectedCloses {
i++
if i == len(expectedCloses) {
continue
}
if resultClose[i] != expected {
t.Errorf("Closes error: Expected %f at cell %d got %f ", expected, i, resultClose[i])
}
}

for i, expected := range expectedLows {
i++
if i == len(expectedLows) {
continue
}
if resultLow[i] != expected {
t.Errorf("Lows error: Expected %f at cell %d got %f ", expected, i, resultLow[i])
}
Expand Down Expand Up @@ -735,7 +750,7 @@ func TestCrossunder(t *testing.T) {
series1 = []float64{1, 2, 3, 4, 8, 6, 7}
series2 = []float64{1, 4, 5, 9, 5, 3, 7}

if Crossunder(series1, series2) == true {
if Crossover(series1, series2) == true {
t.Error("Crossunder: Not expected and found")
}

Expand Down