question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help to implement RVGI indicator , NaN values

See original GitHub issue

Hello all , i have a question , i create the next code :

values = {
        'open': np.array([]),
        'high': np.array([]),
        'low': np.array([]),
        'close': np.array([]),
        'volume': np.array([]),
    }
    for x in candles:
        if 'active_id' in candles[x].keys():
            actualPrice = candles[x]['close']
        values['open'] = np.append(values['open'], candles[x]['open'])
        values['high'] = np.append(values['high'], candles[x]['max'])
        values['low'] = np.append(values['low'], candles[x]['min'])
        values['close'] = np.append(values['close'], candles[x]['close'])
        values['volume'] = np.append(values['volume'], candles[x]['volume'])

    serieOpen = pd.Series(values['open'])
    serieHigh = pd.Series(values['high'])
    serieLow = pd.Series(values['low'])
    serieClose = pd.Series(values['close'])

    resultRVI = ta.rvgi(serieOpen, serieHigh, serieLow, serieClose)

But when i print “resultRVI” i got this :

    RVGI_14_4  RVGIs_14_4
0         NaN         NaN
1         NaN         NaN
2         NaN         NaN
3         NaN         NaN
4         NaN         NaN
5         NaN         NaN
6         NaN         NaN
7         NaN         NaN
8         NaN         NaN
9         NaN         NaN
10        NaN         NaN
11        NaN         NaN
12        NaN         NaN
13        NaN         NaN
14        NaN         NaN

The question is why i recibe NaN values , i cant understand , some one can help me please 😭

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
twopirllccommented, Feb 12, 2021

@kypanz,

I can not create an IQ Option account from the US and will not be able to test their output that you get. You will have to manage the data from that unofficial iqoption api yourself.

yes but the problem here is the rvgvi returns 2 values , value A = rvgi , value B = signal of rvgi , that is the reason when you print the result of rvgi you see “RVGI_12_4” and “RVGIs_12_4” , when rvgi has “s” is the signal

I know how rvgi works. The signal B is a lagged version of A and will not start calculating till A has started.

… , and that value is not the same with the graphics values, and the next index 16 have 2 values , the rvgi and the signal values , but that values are not correct value, this not happend with the RSI , RSI works fine , but with this indicator is not the values what i see, and i dont know if i doing wrong or the operations from the functions and returns are wrong

I can not access to how IQOptions calculates rvgi nor view it’s source. So if there are differences in computation between their closed system (and graphics values) and this open source version, then that is beyond my control without insight into their source. It is not uncommon for different platforms to have slight variations in calculations. Even the de facto TA Lib in C they sometimes have different calculations by platform.

Unfortunately, I can not devote much time on a one off difference in computation without further evidence. There is clearly a lack of data to reasonably test this information both for one off differences and a test of correlation between IQOptions calculation and Pandas TA versions of rvgi. Somehow you need to be able to export both their candles and their rvgi data so that it can be more easily compared. Now it is possible that swma could be throwing the values off, but yet again you do not have data for comparison, just a “graphics value”.

When you are able to give me more actionable data to work with, I can look into it.

Kind Regards, KJ

1reaction
twopirllccommented, Feb 12, 2021

Hi @kypanz,

from iqoption api , this returns to me a dictionary with the candles information

IQOption returns exactly what you shared below, including the defaultdict(<class 'dict'>, ...? Or are you creating your candles variable as a defaultdict? What is the actual data you get? Where is link to IQOption API data? I want to see the actual source they return.

Also, rvgi requires by default a minimum of 14 candles, but 15 candles to write it’s first value. This goes for most indicators that have rolling windows. So with only 14 candles, the first 14 candles of rvgi will be NaN. In short, trying using more data or shortening the lengths of your indicators.

When I strip the defaultdict(<class 'dict'>, ...) that you have provided, convert it to a Pandas DataFrame and adjust the rvgi length to 12, I get data. Here is the code:

import pandas as pd
import pandas_ta as ta

candles = {1613131740: {'id': 2451059, 'from': 1613131740, 'at': 1613131770002146510, 'to': 1613131770, 'open': 105.027, 'close': 105.027, 'min': 105.026, 'max': 105.027, 'volume': 16}, 1613131770: {'id': 2451060, 'from': 1613131770, 'at': 1613131800018129113, 'to': 1613131800, 'open': 105.027, 'close': 105.027, 'min': 105.027, 'max': 105.028, 'volume': 11}, 1613131800: {'id': 2451061, 'from': 1613131800, 'at': 1613131830026267932, 'to': 1613131830, 'open': 105.027, 'close': 105.033, 'min': 105.027, 'max': 105.033, 'volume': 32}, 1613131830: {'id': 2451062, 'from': 1613131830, 'at': 1613131860014628690, 'to': 1613131860, 'open': 105.032, 'close': 105.033, 'min': 105.032, 'max': 105.033, 'volume': 2}, 1613131860: {'id': 2451063, 'from': 1613131860, 'at': 1613131890015790369, 'to': 1613131890, 'open': 105.033, 'close': 105.033, 'min': 105.033, 'max': 105.033, 'volume': 7}, 1613131890: {'id': 2451064, 'from': 1613131890, 'at': 1613131920026275303, 'to': 1613131920, 'open': 105.033, 'close': 105.029, 'min': 105.029, 'max': 105.033, 'volume': 19}, 1613131920: {'id': 2451065, 'from': 1613131920, 'at': 1613131950026262648, 'to': 1613131950, 'open': 105.029, 'close': 105.031, 'min': 105.028, 'max': 105.031, 'volume': 20}, 1613131950: {'id': 2451066, 'from': 1613131950, 'at': 1613131980016177934, 'to': 1613131980, 'open': 105.031, 'close': 105.03, 'min': 105.029, 'max': 105.031, 'volume': 7}, 1613131980: {'id': 2451067, 'from': 1613131980, 'at': 1613132010002298635, 'to': 1613132010, 'open': 105.03, 'close': 105.038, 'min': 105.03, 'max': 105.038, 'volume': 13}, 1613132010: {'id': 2451068, 'from': 1613132010, 'at': 1613132040000991819, 'to': 1613132040, 'open': 105.038, 'close': 105.037, 'min': 105.037, 'max': 105.038, 'volume': 2}, 1613132040: {'id': 2451069, 'from': 1613132040, 'at': 1613132070018338099, 'to': 1613132070, 'open': 105.037, 'close': 105.039, 'min': 105.037, 'max': 105.039, 'volume': 6}, 1613132070: {'id': 2451070, 'from': 1613132070, 'at': 1613132100007899342, 'to': 1613132100, 'open': 105.039, 'close': 105.033, 'min': 105.031, 'max': 105.039, 'volume': 12}, 1613132100: {'id': 2451071, 'from': 1613132100, 'at': 1613132130005581330, 'to': 1613132130, 'open': 105.033, 'close': 105.028, 'min': 105.028, 'max': 105.033, 'volume': 12}, 1613132130: {'id': 2451072, 'from': 1613132130, 'at': 1613132160002531932, 'to': 1613132160, 'open': 105.028, 'close': 105.039, 'min': 105.028, 'max': 105.039, 'volume': 27}, 1613132160: {'active_id': 6, 'size': 30, 'at': 1613132184419742234, 'from': 1613132160, 'to': 1613132190, 'id': 2451073, 'open': 105.038, 'close': 105.036, 'min': 105.036, 'max': 105.038, 'ask': 105.04, 'bid': 105.032, 'volume': 4, 'phase': 'T'}}

candlesdf = pd.DataFrame(candles).T
candlesdf.rename(columns={"max": "high", "min": "low"}, inplace=True)
candlesdf.ta.rvgi(length=12, append=True)

print(candlesdf.shape)
print(candlesdf)

Output Screen Shot 2021-02-12 at 11 06 56 AM


Also note, you will also need to convert your index into a DatetimeIndex if you want to use other indicators like vwap.

Let me know how it goes. Hope this helps!

Thanks, KJ

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative Vigor Index - 2 Top Trading Strategies You Can Use
Relative Vigor Index is a two line oscillator that helps determine trend and momentum. Learn 2 great strategies that use the RVI and...
Read more >
Implementing the Relative Vigor Index and Backtesting a ...
In this article, we will first build some basic intuitions about the indicator and the mathematics behind it. Then, we will proceed to...
Read more >
Relative Vigor Index (RVI): Definition, Formula, Uses in ...
The Relative Vigor Index (RVI) measures the strength of a trend by comparing a closing price to the daily range.
Read more >
Pandas TA: A Technical Analysis Library in Python 3 - Morioh
Use help(ta.indicator_name) for more information or make a Pull Request to ... this value to 0. df.ta.cores = 4 # Maybe you do...
Read more >
5 Trading Strategies Using the Relative Vigor Index
The relative vigor index (RVI or RVGI) is a technical indicator that ... above and below zero – producing both positive and negative...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found