def gentrends(dataframe, field='close', window=1 / 3.0, charts=False):
    """
    Returns a Pandas dataframe with support and resistance lines.

    :param dataframe: incomming data matrix
    :param field: for which column would you like to generate the trendline
    :param window: How long the trendlines should be. If window < 1, then it
                   will be taken as a percentage of the size of the data
    :param charts: Boolean value saying whether to print chart to screen
    """
    print(dataframe)
    x = dataframe[field]
    import numpy as np
    import pandas as pd
    x = np.array(x)
    if window < 1:
        window = int(window * len(x))
    max1 = np.where(x == max(x))[0][0]
    min1 = np.where(x == min(x))[0][0]
    if max1 + window > len(x):
        max2 = max(x[0:max1 - window])
    else:
        max2 = max(x[max1 + window:])
    if min1 - window < 0:
        min2 = min(x[min1 + window:])
    else:
        min2 = min(x[0:min1 - window])
    max2 = np.where(x == max2)[0][0]
    min2 = np.where(x == min2)[0][0]
    maxslope = (x[max1] - x[max2]) / (max1 - max2)
    minslope = (x[min1] - x[min2]) / (min1 - min2)
    a_max = x[max1] - maxslope * max1
    a_min = x[min1] - minslope * min1
    b_max = x[max1] + maxslope * (len(x) - max1)
    b_min = x[min1] + minslope * (len(x) - min1)
    maxline = np.linspace(a_max, b_max, len(x))
    minline = np.linspace(a_min, b_min, len(x))
    trends = np.transpose(np.array((x, maxline, minline)))
    trends = pd.DataFrame(trends, index=np.arange(0, len(x)), columns=[
        'Data', 'Max Line', 'Min Line'])
    if charts:
        from matplotlib.pyplot import plot, grid, savefig, close
        plot(trends)
        grid()
        if isinstance(charts, str):
            savefig('{}.png'.format(charts))
        else:
            savefig('{}_{}.png'.format(x[0], x[len(x) - 1]))
        close()
    return trends
