Supertrend depends on ATR, and ATR needs historical candles.
So, you have to pass both the historical and live data.
Aggregate the data first and then pass in Supertrend function you will get the accurate value.
Eg code below:
def get_supertrend_input(symbol, live_candles):
# Fetch historical
query = "GET HISTORICAL DATA"
values = [symbol, "minute"]
historical_candles = fetch_historical_data(query, values)
# Merge
all_candles = historical_candles + live_candles
# Safety check
if len(all_candles) < 15: # minimum for ATR(10)
return []
return all_candles
def run_supertrend(symbol, live_candles):
candles = get_supertrend_input(symbol, live_candles)
if not candles:
return None
result = compute_supertrend(candles, period=10, multiplier=3)
if not result:
return None
return result[-1] # latest signal