-
-
Save praveenbm5/bdeb65c39f4771540ca25bf994d8c393 to your computer and use it in GitHub Desktop.
GodMode Indicator in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a non-multiexchange version of GODMODE indicator | |
# If you want the multi exchange version of GODMODE indicator, you need to implement willy and csi calculations too | |
# Original source of god mode indicator: | |
# https://www.tradingview.com/script/oA3U7pok-GODMODE-OSCILLATOR-FRESH-BREAD-GENERATOR-FREE-TO-USE/ | |
import pandas as pd | |
import talib | |
channel_length = 9 | |
average_length = 26 | |
short_length = 13 | |
def tci(src, base_column='hlc3'): | |
ema = talib.EMA(src[base_column], timeperiod=channel_length) | |
ema_offset = src[base_column] - ema | |
ema_offset_abs = abs(ema_offset) | |
ema_offset_smooth = talib.EMA(ema_offset_abs, timeperiod=channel_length) | |
res = talib.EMA((ema_offset_abs / ema_offset_smooth) / 40, | |
timeperiod=average_length) + 50 | |
return res | |
def mf(src, base_column='hlc3', volume_column='volume'): | |
diff = src[base_column].diff() | |
upwards = pd.Series([0 if cur <= 0 else cur for cur in diff]) | |
volume_n_upwards = src[volume_column] * upwards | |
upwards_cum_sum = volume_n_upwards.rolling(min_periods=1, window=short_length).sum() | |
downwards = pd.Series([0 if cur >= 0 else cur for cur in diff]) | |
volume_n_downwards = src[volume_column] * downwards | |
downwards_cum_sum = volume_n_downwards.rolling(min_periods=1, window=short_length).sum() | |
res = 100 - 100 / (1 + (upwards_cum_sum / abs(downwards_cum_sum))) | |
return res | |
def tradition(src, base_column='hlc3'): | |
rsi = talib.RSI(src[base_column], timeperiod=short_length) | |
return (tci(src, base_column=base_column) + mf(src, base_column=base_column) + rsi) / 3 | |
# todo Retrieve candles from source | |
candles = pd.DataFrame() | |
base_column = 'hlc3' | |
candles[base_column] = (candles['high'] + candles['close'] + candles['low']) / 3 | |
candles['wt1'] = tradition(candles, base_column=base_column) | |
candles['wt2'] = talib.SMA(candles['wt1'], timeperiod=6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment