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

MACD Signal line (EMA) seems to be broken/not working... #39

Open
amlwwalker opened this issue Mar 19, 2021 · 6 comments
Open

MACD Signal line (EMA) seems to be broken/not working... #39

amlwwalker opened this issue Mar 19, 2021 · 6 comments
Labels

Comments

@amlwwalker
Copy link

Based on a series of data, to plot the MACD and signal lines, I am doing:

	macD := analytics.MACD(closePriceIndicator, 12, 26)
	macDSignal := analytics.MACDSignalLine(macD, 9)

Where the above two functions are defined as:

func MACD(indicator techan.Indicator, shortWindow, longWindow int) techan.Indicator {
	return techan.NewMACDIndicator(indicator, shortWindow, longWindow)
}
func MACDSignalLine(indicator techan.Indicator, window int) techan.Indicator {
	return techan.NewEMAIndicator(indicator, window)
}

However when I plot this, I get two very different lines

image

To check I wasn't going completely mad, I changed the signal line to use an SMA instead, so my MACDSignalLine function becomes

func MACDSignalLine(indicator techan.Indicator, window int) techan.Indicator {
	return techan.NewSimpleMovingAverage(indicator, window) // Create an exponential moving average with a window of 10
}

which plots like

image

Which suggests that the EMA isn't working correctly for some reason here. Any suggestions as to where Im going wrong would be great, thanks!

@GeorgeGkinis
Copy link

@amlwwalker
Did you plot this in Excell or something else?

@amlwwalker
Copy link
Author

amlwwalker commented Mar 21, 2021

@amlwwalker
Copy link
Author

@sdcoffey - was trying to add a bug label to this, as for the v1 milestone be good to know if this is a EMA bug here?

@sdcoffey sdcoffey added the bug label Mar 29, 2021
@sdcoffey
Copy link
Owner

@amlwwalker I'll check this out! Will you let me know what version of the library you're using? Also if you can drop in your test data that would be super helpful as I debug. Thanks!

@amlwwalker
Copy link
Author

amlwwalker commented Mar 30, 2021

hey, apologies @sdcoffey I actually now think it was an issue with scaling in Excel - i re plotted the graph in react-vis and it seemed to be good. I wonder if excel was getting caught by not quite adjusting the y scale correctly or something.

I am however having divide by 0 crashes uses the trend_line:

techan.NewTrendlineIndicator(closeIndicator, 14)

Im using AAPL stock data (last ~thousand points) that I downloaded the CSV for from yahoo. I get:

panic: division of zero by zero or infinity by infinity [recovered]
	panic: interface conversion: interface {} is big.ErrNaN, not string
math/big.(*Float).Quo(0xc000ca3890, 0xc000ca3680, 0xc000ca3860, 0xc000ca3860)
	/usr/local/go/src/math/big/float.go:1651 +0x11f
github.com/sdcoffey/big.Decimal.Div.func1(0xc000486fd0)
	/Users/alex.walker/go/pkg/mod/github.com/sdcoffey/[email protected]/decimal.go:133 +0x79
github.com/sdcoffey/big.nanGuard(0xc000486fe0, 0xc000486fd0, 0x2, 0x2, 0xc000ca3860)
	/Users/alex.walker/go/pkg/mod/github.com/sdcoffey/[email protected]/decimal.go:359 +0x66
github.com/sdcoffey/big.Decimal.Div(0xc000ca3680, 0xc000ca3860, 0xc000ca3860)
	/Users/alex.walker/go/pkg/mod/github.com/sdcoffey/[email protected]/decimal.go:132 +0x8b
github.com/sdcoffey/techan.trendLineIndicator.Calculate(0x4953160, 0xc000bdd180, 0xe, 0x0, 0xc0000a2300)
	/Users/alex.walker/go/pkg/mod/github.com/sdcoffey/[email protected]/indicator_trend.go:32 +0x265

My guess is for a few days there isn't a value, but I didn't think that would cause a run time error. I was wondering if it needs something on line 32 of indicator_trend.go:

	if cd.LTE(big.NewDecimal(0)) {
		return big.NewDecimal(0)
	}

versions:

	github.com/sdcoffey/big v0.7.0
	github.com/sdcoffey/techan v0.12.0

While here, I was wondering if there was any seasonality/ARIMA/Prophet esq work, in the works, of if not do you know of any good library and I might try and implement it myself....?

@sdcoffey
Copy link
Owner

Hey @amlwwalker, good to know. I'll check out the divide by zero error.

I definitely do not have any forecasting plans in the works, I think it might be out of scope for this project. I don't know of any library in go that does forecasting/seasonality, although you might look in awesome-go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants