def f_ema(close_prices, window):
    """Calculates exponential moving average (EMA).

    This function takes historical data, and a moving window to calculate EMA.
    EMA differs from standard moving average with EMA placing a higher weight on more recent prices.
    As the moving average takes previous closing prices into account, its length will be len(candles) - window

    Args:
        close_prices (list of float): A list of close prices for each period.
        window (int): The moving window to take averages over.

    Returns:
        list of float: A list of EMAs
    """

    ema = []

    # calculate EMA
    # Smoothing factor
    smooth = 2.0/(window + 1.0)

    # Calculate first EMA from simple average
    ema.append(sum(close_prices[:window])/window)

    # Calculate remaining EMA values
    i = 0
    for close_price in close_prices[window:]:
        new_ema = close_price*smooth + ema[-1]*(1.0-smooth)
        ema.append(new_ema)
        i += 1

    return ema