Skip to content

Instantly share code, notes, and snippets.

@SajidLhessani
Created September 5, 2021 01:18
Show Gist options
  • Select an option

  • Save SajidLhessani/853e5298c6b8fbd460395e4ea4025856 to your computer and use it in GitHub Desktop.

Select an option

Save SajidLhessani/853e5298c6b8fbd460395e4ea4025856 to your computer and use it in GitHub Desktop.
# Create a column by name, SMA and assign the SMA calculation to it
df['SMA'] = df['Close'].shift(1).rolling(window=n).mean()
# Create a column by name, Corr and assign the calculation of correlation to it
df['Corr'] = df['Close'].shift(1).rolling(window=n).corr(df['SMA'].shift(1))
# Create a column by name, SAR and assign the SAR calculation to it
df['SAR'] = ta.SAR(np.array(df['High'].shift(1)), np.array(df['Low'].shift(1)),
0.2, 0.2)
# Create a column by name, ADX and assign the ADX calculation to it
df['ADX'] = ta.ADX(np.array(df['High'].shift(1)), np.array(df['Low'].shift(1)),
np.array(df['Open']), timeperiod=n)
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment