-- Debug script for stop-loss integration test

-- Check if regime state exists
SELECT 'Regime State:' as step;
SELECT symbol, regime, confidence FROM regime_states WHERE symbol = 'NQ.FUT' ORDER BY event_timestamp DESC LIMIT 1;

-- Check if market data exists
SELECT 'Market Data Count:' as step;
SELECT COUNT(*) as bar_count FROM prices WHERE symbol = 'NQ.FUT';

-- Check market data values
SELECT 'Market Data Sample:' as step;
SELECT
    high::FLOAT8 / 100.0 as high,
    low::FLOAT8 / 100.0 as low,
    close::FLOAT8 / 100.0 as close
FROM prices
WHERE symbol = 'NQ.FUT'
ORDER BY timestamp DESC
LIMIT 5;

-- Test ATR calculation manually
SELECT 'Manual ATR Check:' as step;
WITH bars AS (
    SELECT
        high::FLOAT8 / 100.0 as high,
        low::FLOAT8 / 100.0 as low,
        close::FLOAT8 / 100.0 as close,
        timestamp
    FROM prices
    WHERE symbol = 'NQ.FUT'
    ORDER BY timestamp DESC
    LIMIT 20
)
SELECT
    AVG(high - low) as avg_range,
    MAX(high - low) as max_range,
    MIN(high - low) as min_range
FROM bars;
