import json import os MEMORY_FILE = "/tmp/memory.json" # ✅ writable path on HF def load_history(): if os.path.exists(MEMORY_FILE): with open(MEMORY_FILE, "r") as f: return json.load(f) return [] def save_history(history): with open(MEMORY_FILE, "w") as f: json.dump(history, f) def detect_trend(price): history = load_history() history.append(price) history = history[-5:] save_history(history) if len(history) < 5: return "⏳ Gathering..." if price > max(history[:-1]): return "📈 Leg Up Detected" elif price < min(history[:-1]): return "📉 Leg Down Forming" else: return "📊 Sideways"