ValiMohammadiethereum macd
    Updated 2023-01-18
    WITH token_prices AS (
    select
    date_trunc('day', RECORDED_HOUR) as datee,
    avg(close) as WETH_Price


    from solana.core.fact_token_prices_hourly
    where symbol = 'WETH'
    group by 1
    order by datee
    ),

    ema AS (
    SELECT
    datee,
    WETH_Price,
    WETH_Price * (2/(12+1)) +
    LAG(WETH_Price, 1) OVER (ORDER BY datee) * (1-(2/(12+1))) as EMA_12,
    (WETH_Price * (2/(26+1)) +
    LAG(WETH_Price, 1) OVER (ORDER BY datee) * (1-(2/(26+1)))) as EMA_26
    FROM token_prices
    ),

    macd AS (
    SELECT
    datee,
    EMA_12 - EMA_26 as MACD,
    EMA_12 - EMA_26 as MACD_Signal,
    (MACD_Signal * (2/(9+1)) +
    LAG(MACD_Signal, 1) OVER (ORDER BY datee) * (1-(2/(9+1)))) as MACD_Signal_Line
    FROM ema
    )

    SELECT
    datee,
    macd - MACD_Signal_Line as "MACDHistogram"
    Run a query to Download Data