Example #1
0
def compute_resistance_support_line(opening, high, low, close):
    price_data = db.get_realtime_Data(trading_symbol, frame_size)
    print "compute_resistance_support_line"

    support_lines, resistance_lines = compute_support_resistance(
        opening, high, low, close)
    support_end_points = []
    good_support = []
    support_slope = []
    for l in reversed(support_lines[-7:]):
        good_support.append(l["line"])
        support_slope.append(l["line"].slope)
        support_end_points.append(l["line"].get_y(0))
        support_end_points.append(l["line"].get_y(frame_size))
    good_resisitance = []
    resistance_slope = []

    resistance_end_points = []
    for l in reversed(resistance_lines[-7:]):
        good_resisitance.append(l["line"])
        resistance_slope.append(l["line"].slope)
        resistance_end_points.append(l["line"].get_y(0))
        resistance_end_points.append(l["line"].get_y(frame_size))

    normalize_slope_val = max(resistance_end_points) - min(support_end_points)
    resistance_slope.remove(max(resistance_slope))
    resistance_slope.remove(min(resistance_slope))
    support_slope.remove(max(support_slope))
    support_slope.remove(min(support_slope))

    good_lines = []
    for index in range(2):
        good_lines.append([good_support[index], good_resisitance[index]])

    final_support = Line(2, 2, 1, 1)
    final_support.slope = (good_lines[0][0].slope + good_lines[1][0].slope) / 2
    final_support.intercept = (good_lines[0][0].intercept +
                               good_lines[1][0].intercept) / 2

    final_resistance = Line(2, 2, 1, 1)
    final_resistance.slope = (good_lines[0][1].slope +
                              good_lines[1][1].slope) / 2
    final_resistance.intercept = (good_lines[0][1].intercept +
                                  good_lines[1][1].intercept) / 2
    return (final_support, final_resistance)
Example #2
0
    return result


raw_training_data = get_ML_data_for_resistance_support(start_time=20160213,
                                                       end_time=20160213)
training_data = []
training_result = []
for chunk in raw_training_data:
    unixtime, opening, high, low, close, good_result = chunk
    print(len(opening))
    for index in range(101, len(opening)):
        if good_result[index] != 0.0:
            print "good_result"
            support_lines, resistance_lines = compute_support_resistance(
                opening[index - 26:index - 2], high[index - 26:index - 2],
                low[index - 26:index - 2], close[index - 26:index - 2])
            support_line, resistance_line = choose_best_line(
                resistance_lines, support_lines, 25)
            resistance_line_val = resistance_line.get_y(25)
            support_line_val = support_line.get_y(25)
            print(support_line_val, resistance_line_val,
                  support_line_val < resistance_line_val)
            # time_s = []
            # for t in unixtime[index - 101:index]:
            # 	time_s.append(datetime.datetime.fromtimestamp(t))
            # Plot.plot_day_candle(time_s, opening[index - 101:index], high[index - 101:index], low[index - 101:index], close[index - 101:index], 26, "EURUSD", lines=[[support_line],[resistance_line]], save=True)
            if resistance_line_val > support_line_val:
                features_arr = []
                if resistance_line.slope > 0:
                    features_arr.append(0)
import math
from SupportResistance import compute_support_resistance, parse_historical_data
from matplotlib.dates import date2num

db = Database()
currency_data = db.get_range_currency_date("EURUSD", 20160223, 20160523)
for day_data in currency_data:
    frame_size = 30

    frame = []
    support_slope_arr = []
    resistance_slope_arr = []
    # for frame_size in range(20,30):
    frame, opening, high, low, close = parse_historical_data(
        day_data["minute_price"], frame_size=frame_size)
    resistance_lines, support_lines = compute_support_resistance(
        opening[:-1], high[:-1], low[:-1], close[:-1])

    support_end_points = []
    good_support = []
    support_slope = []
    for l in reversed(support_lines[-7:]):
        good_support.append(l["line"])
        support_slope.append(l["line"].slope)
        support_end_points.append(l["line"].get_y(0))
        support_end_points.append(l["line"].get_y(frame_size))
    good_resisitance = []
    resistance_slope = []

    resistance_end_points = []
    for l in reversed(resistance_lines[-7:]):
        good_resisitance.append(l["line"])