def calculate_risk(ta): entry = ta["price"] support = ta["support"] resistance = ta["resistance"] risk = round(entry - support, 2) reward = round(resistance - entry, 2) rr = round( reward / risk, 2 ) if risk > 0 else 0 stop_loss = round( support * 0.995, 2 ) take_profit = round( resistance * 1.005, 2 ) position_size = "SMALL" if rr >= 3: position_size = "LARGE" elif rr >= 2: position_size = "MEDIUM" return { "entry": entry, "stop_loss": stop_loss, "take_profit": take_profit, "rr": rr, "position_size": position_size }