Closed thegamecat closed 4 years ago
For example if you want to plot price and SMA together in the same plot with Matplotlib. Then the price list as well the SMA list both must have the same length to plot it correctly.
The NaN value is meaning that the indicator cannot be calculated, yet. The NaN value is not showed in the plot, only the indicator calculation output is showed.
If you want only the last SMA output you can do something like this: jhta.SMA(df, 20)[-1]
That's true about plotting but I assume most are using that for automating trading. On top of this, it's probably better to push all chart data into a single list including indicator outputs.
That's a great tip re getting the last value, I thought you had to do this in 2 steps, python wins again :)
Thank you again.
I see this in nearly all tech analysis libs and I've never understood it.
If I want SMA 20 - I'm likely to already be cycling through data tick by tick and on each tick I want the latest SMA 20. I will have a generic array of ohlcv data that may have a depth of say 200 (to cover all eventualities). So I pass in my data as you specified:
jhta.SMA(df, 20)
DF has a length of 200 just because...so I would like the SMA value where the SMA length is 20, of the last tick. What I receive is 200 SMAs, why?
The return value should always be a single number....shouldn't it?
For an easier explanation of my confusion...
df length is 201 pp (jhta.SMA(df, 200)) that returns 199 NaNs and 1 number
There must be a use case I'm too stupid to get, but everyone implements such things as you have, and I don't know why !
Really really loving your lib so dont think this is negative!