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

EMA always return 0.00 #49

Open
Chipsterjulien opened this issue Nov 29, 2021 · 2 comments
Open

EMA always return 0.00 #49

Chipsterjulien opened this issue Nov 29, 2021 · 2 comments

Comments

@Chipsterjulien
Copy link

Hello, i used your code with data and ... nothing works. For example EMA always gives 0

Volume:	870.19 Time:	2021-11-28T07:00:00 -> 2021-11-28T08:00:00
Open:	54377.42
Close:	54475.96
High:	54590.48
Low:	54173.81
Volume:	787.07 Time:	2021-11-28T08:00:00 -> 2021-11-28T09:00:00
Open:	54475.97
Close:	54515.61
High:	54636.65
Low:	54396.33
Volume:	985.20 Time:	2021-11-28T09:00:00 -> 2021-11-28T10:00:00
Open:	54515.60
Close:	54396.20
High:	54682.90
Low:	54231.92
Volume:	823.84 Time:	2021-11-28T10:00:00 -> 2021-11-28T11:00:00
Open:	54393.87
Close:	54335.80
High:	54475.00
Low:	54130.72
Volume:	765.69 Time:	2021-11-28T11:00:00 -> 2021-11-28T12:00:00
Open:	54335.80
Close:	54718.15
High:	54933.80
Low:	54184.60
Volume:	1028.53 Time:	2021-11-28T12:00:00 -> 2021-11-28T13:00:00
Open:	54718.15
Close:	54493.09
High:	54875.00
Low:	54425.27
Volume:	1030.39 Time:	2021-11-28T13:00:00 -> 2021-11-28T14:00:00
Open:	54493.10
Close:	54356.62
High:	54635.52
Low:	54263.16
Volume:	909.93 Time:	2021-11-28T14:00:00 -> 2021-11-28T15:00:00
Open:	54356.62
Close:	54274.20
High:	54396.33
Low:	54203.13
Volume:	777.66 Time:	2021-11-28T15:00:00 -> 2021-11-28T16:00:00
Open:	54274.20
Close:	54365.00
High:	54555.00
Low:	54029.99
Volume:	1130.34 Time:	2021-11-28T16:00:00 -> 2021-11-28T17:00:00
Open:	54365.00
Close:	54296.14
High:	54450.00
Low:	54169.84
Volume:	753.77 Time:	2021-11-28T17:00:00 -> 2021-11-28T18:00:00
Open:	54296.14
Close:	54188.43
High:	54373.00
Low:	53942.01
Volume:	1277.10 Time:	2021-11-28T18:00:00 -> 2021-11-28T19:00:00
Open:	54188.43
Close:	53896.37
High:	54287.25
Low:	53800.00
Volume:	1358.34 Time:	2021-11-28T19:00:00 -> 2021-11-28T20:00:00
Open:	53896.36
Close:	54108.99
High:	54186.17
Low:	53256.64
Volume:	2958.13 Time:	2021-11-28T20:00:00 -> 2021-11-28T21:00:00
Open:	54108.99
Close:	54617.85
High:	54967.50
Low:	54044.98
Volume:	2249.23 Time:	2021-11-28T21:00:00 -> 2021-11-28T22:00:00
Open:	54617.85
Close:	54918.51
High:	55149.99
Low:	54617.84
Volume:	1304.77 Time:	2021-11-28T22:00:00 -> 2021-11-28T23:00:00
Open:	54918.51
Close:	56273.23
High:	56390.00
Low:	54863.01
Volume:	3117.97 Time:	2021-11-28T23:00:00 -> 2021-11-29T00:00:00
Open:	56273.23
Close:	56029.82
High:	56729.72
Low:	56023.01
Volume:	2427.77 Time:	2021-11-29T00:00:00 -> 2021-11-29T01:00:00
Open:	56029.81
Close:	57274.88
High:	57445.05
Low:	56000.00
Volume:	3468.79 Time:	2021-11-29T01:00:00 -> 2021-11-29T02:00:00
Open:	57274.89
Close:	57765.73
High:	58000.15
Low:	57136.56
Volume:	3073.53 Time:	2021-11-29T02:00:00 -> 2021-11-29T03:00:00
Open:	57765.73
Close:	57639.76
High:	58242.09
Low:	57501.99
Volume:	2729.83 Time:	2021-11-29T03:00:00 -> 2021-11-29T04:00:00
Open:	57643.14
Close:	57309.25
High:	57715.42
Low:	57269.72
Volume:	1769.15 Time:	2021-11-29T04:00:00 -> 2021-11-29T05:00:00
Open:	57309.26
Close:	57359.02
High:	57426.95
Low:	57176.00
Volume:	1648.18 Time:	2021-11-29T05:00:00 -> 2021-11-29T06:00:00
Open:	57359.02
Close:	57249.58
High:	57642.93
Low:	57232.00
Volume:	1358.98 Time:	2021-11-29T06:00:00 -> 2021-11-29T07:00:00
Open:	57249.58
Close:	57325.75
High:	57384.99
Low:	57200.00
Volume:	801.75 Time:	2021-11-29T07:00:00 -> 2021-11-29T08:00:00
Open:	57325.76
Close:	57426.91
High:	57500.63
Low:	57309.65
Volume:	1002.85 Time:	2021-11-29T08:00:00 -> 2021-11-29T09:00:00
Open:	57426.92
Close:	57515.13
High:	57688.00
Low:	57390.00
Volume:	1047.27 Time:	2021-11-29T09:00:00 -> 2021-11-29T10:00:00
Open:	57512.17
Close:	57514.33
High:	57642.85
Low:	57455.08
Volume:	174.91]}

EMA output: 0.00

The code :

df := techan.NewTimeSeries()

	for _, k := range *klines {
		// opentime, open, high, low, close, volume
		period := techan.NewTimePeriod(time.Unix(k.OpenTime/1000, 0), *duration)

		candle := techan.NewCandle(period)
		candle.OpenPrice = big.NewFromString(k.Open)
		candle.ClosePrice = big.NewFromString(k.Close)
		candle.MaxPrice = big.NewFromString(k.High)
		candle.MinPrice = big.NewFromString(k.Low)
		candle.Volume = big.NewFromString(k.Volume)

		df.AddCandle(candle)
	}

	fmt.Println(df)
        closePrices := techan.NewClosePriceIndicator(df)
	movingAverage := techan.NewEMAIndicator(closePrices, 10) // Create an exponential moving average with a window of 10

	fmt.Println("EMA output :" + movingAverage.Calculate(0).FormattedString(2))
@d2bit
Copy link

d2bit commented Feb 6, 2022

@Chipsterjulien Hi!
I think the problem is in el Calculate call, as the window size is 10, the Calculate will return 0 from index 0 up to 9, as it has not enough data to fill the window.
Try this:

movingAverage.Calculate(9).FormattedString(2)

If it does not work, take a look if you are adding the candles right. Seems they have to be added time-ordered.

@gespi1
Copy link

gespi1 commented Sep 13, 2022

@Chipsterjulien did you ever get this working?

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

No branches or pull requests

3 participants