sdcoffey / techan

Technical Analysis Library for Golang
https://godoc.org/github.com/sdcoffey/techan
MIT License
840 stars 143 forks source link

Question: What do you guys mean by window? #24

Closed Gauthamastro closed 4 years ago

Gauthamastro commented 4 years ago
    ema := NewEMAIndicator(NewClosePriceIndicator(ts), 10)

    decimalEquals(t, 63.6948, ema.Calculate(9))
    decimalEquals(t, 63.2649, ema.Calculate(10))
    decimalEquals(t, 62.9458, ema.Calculate(11))

ts variable has a time-period set for candles already. So what is this window parameter passed to NewEMAIndicator? Also, what is the purpose of that parameter index given to Calculate?

I couldn't find any documentation for it. Can someone please explain it to me?

sdcoffey commented 4 years ago

Hey @Gauthamastro, good questions.

Window

window, for a moving average indicator like this one, allows you to specify the number of periods used in the moving average calculation. For example, a moving average using 10 periods would be more spiky than one with 200 periods. Check out the investopedia page on exponential moving average for more detail.

Index

index just lets you request the moving average at any point in the timeseries. If you want to know the lastest value in the moving average curve, you'd use the last index value. If you want to know the moving average value as of 10 periods ago, you might use len(ts.Candles) -10 as the index.

Gauthamastro commented 4 years ago

Hi @sdcoffey, Thanks for your reply.

Now it makes sense. I was confused about the index parameter.