tradingAI / supertrend_agent.py
yougandar's picture
Create supertrend_agent.py
267432a verified
raw
history blame contribute delete
631 Bytes
import pandas as pd
import numpy as np
class SupertrendAgent:
def run(self, df, period=7, multiplier=3):
df = df.copy()
hl2 = (df['High'] + df['Low']) / 2
atr = df['High'].rolling(period).max() - df['Low'].rolling(period).min()
upper_band = hl2 + multiplier * atr
lower_band = hl2 - multiplier * atr
current_close = df['Close'].iloc[-1]
if current_close > upper_band.iloc[-1]:
signal = "Bullish"
elif current_close < lower_band.iloc[-1]:
signal = "Bearish"
else:
signal = "Neutral"
return {"signal": signal}