technical icon indicating copy to clipboard operation
technical copied to clipboard

Vortex Indicator - written by myself

Open roko772 opened this issue 3 years ago • 1 comments

Hi! I've written Python code for Vortex Indicator. Since I'm only a newbie, could you check that code? I can't get almost any profit when backtesting.

     def vortex_indicator_plus(window = 14):

            df = dataframe.copy()
            try:
                df['tr1'] = (df['high']- df['low'])
                df['tr2'] = (df['high']- df['close'].shift(1))
                df['tr3'] = (df['low'] - df['close'].shift(1))
                df['true_range'] = df[['tr1', 'tr2', 'tr3']].values.max(1)
            except ValueError:
                return np.nan
            min_periods = window
            df['trn'] = df['true_range'].rolling(window, min_periods=min_periods).sum()
            df['vmp'] = np.abs(df['high'] - df['low'].shift(1))
            df['vmm'] = np.abs(df['low'] - df['high'].shift(1))
            vip = df['vmp'].rolling(window, min_periods=min_periods).sum() / df['trn']
            vin = df['vmm'].rolling(window, min_periods=min_periods).sum() / df['trn']

            return vip

def vortex_indicator_minus(window=14):

            df = dataframe.copy()
            try:
                df['tr1'] = (df['high'] - df['low'])
                df['tr2'] = (df['high'] - df['close'].shift(1))
                df['tr3'] = (df['low'] - df['close'].shift(1))
                df['true_range'] = df[['tr1', 'tr2', 'tr3']].values.max(1)
            except ValueError:
                return np.nan
            min_periods = window
            df['trn'] = df['true_range'].rolling(window, min_periods=min_periods).sum()
            df['vmp'] = np.abs(df['high'] - df['low'].shift(1))
            df['vmm'] = np.abs(df['low'] - df['high'].shift(1))
            vip = df['vmp'].rolling(window, min_periods=min_periods).sum() / df['trn']
            vin = df['vmm'].rolling(window, min_periods=min_periods).sum() / df['trn']
            return vin

Thank you very much!

roko772 avatar Mar 02 '21 22:03 roko772

you could combine this to one function by using return vip, vin - and then obviously also acceptiong it this way outside of the function.

apart from that, i'm not sure what you're expecting

it doesn't include any examples on how you would trade this, so it's just an indicator we'd need to do research on.

the code itself doesn't seem to have any obvious flaws - but there's for sure multiple ways to trade such an indicator.

xmatthias avatar Mar 04 '21 18:03 xmatthias

Closing this as we had no further feedback on the comment above.

If you think this should be added, please submit a pull request instead. We'd still want some more information - like a dockstring on what the recommended use in a strategy is.

Without that information, it's pretty much just a random calculation everyone can make sense of by actually reading the code, which makes it not very useful.

xmatthias avatar Aug 22 '23 05:08 xmatthias