Advertisement
miklis

prekyba

Sep 23rd, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. from pylab import *
  2. import matplotlib.pyplot as plt
  3. from datetime import*
  4. import time
  5. from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \
  6. DayLocator, MONDAY
  7. from matplotlib.finance import candlestick,\
  8. plot_day_summary, candlestick2
  9.  
  10. #link of 1-minute bars
  11. #http://www.forextester.com/data/datasourcesb?utm_expid=10288340-134.TonnJTxKS9-kS6ERm9mvXg.1&utm_referrer=http%3A%2F%2Fwww.forexfactory.com%2Fshowthread.php%3Ft%3D277091
  12.  
  13. #DAILY PRICES
  14.  
  15. #getting array of data, each of the format like ['20010103', '00:00:00', '0.9507', '0.9262', '0.9569', '0.9271']
  16. data=[n.split(',')[1:] for n in open("C:\Users\Public\Downloads\pinigai.csv").read().split()]
  17. #changing each cell of array to form like ({date converted in numeric form}, 1.123, 1.212, 1.463, 1.056)
  18. prices=map(lambda x: (date2num(datetime.strptime(x[0]+x[1], "%Y%m%d%H:%M:%S")), float(x[2]), float(x[5]), float(x[3]), float(x[4])), data)[-200:]
  19. #for n in prices: print n #printig prepared list
  20.  
  21. def show(prices,M1=False,H1=False,D1=False):
  22. '''takes daily prices (numeric date, low, high, min, max) and paints graph'''
  23. mondays = WeekdayLocator(MONDAY) # major ticks on the mondays
  24. alldays = DayLocator() # minor ticks on the days
  25. if M1: Formatter = DateFormatter('%Y %b %d %H:%M') #e.g. 2015 Jan 12 15:24
  26. if H1: Formatter = DateFormatter('%Y %b %d %H:%M') #e.g. 2015 Jan 12 15:24
  27. if D1: Formatter = DateFormatter('%Y %b %d') # e.g. 2015 Jan 12
  28.  
  29. fig, ax = plt.subplots()
  30. fig.subplots_adjust(bottom=0.2) #bottom of table
  31. if D1: ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) #scales Ox axis highlighting Mondays
  32. if M1: ax.xaxis.set_major_locator(MinuteLocator(interval=10)) #scales Ox axis highlighting every ten minutes
  33. if H1: ax.xaxis.set_major_locator(HourLocator(interval=100)) #scales Ox axis highlighting Mondays ###############
  34. ax.xaxis.set_minor_locator(alldays)
  35. ax.xaxis.set_major_formatter(Formatter) #format of writing dates #############
  36. if M1: wid=0.0006
  37. if H1: wid=0.6
  38. if D1: wid=0.6
  39. candlestick(ax, prices, width=wid, colorup='g', colordown='r') ###########
  40.  
  41. ax.xaxis.set_ticks_position('bottom') #direction of gradation ticks
  42. ax.yaxis.set_ticks_position('left')
  43. ax.tick_params(axis='both', direction='out', width=2, length=8,
  44. labelsize=12, pad=8) #highlighted gradation ticks
  45.  
  46. ax.set_xlabel('TIME')
  47. ax.set_ylabel('EUR/USD')
  48. ax.xaxis_date() #don't know
  49. ax.autoscale_view() #responsible for graph position in the table - not neccessarry
  50. plt.setp( plt.gca().get_xticklabels(), rotation=25, horizontalalignment='right')
  51. plt.show()
  52.  
  53. #prices=prices[10:240]
  54. #show(prices,H1=True)
  55.  
  56. #READING 1M PRICES
  57. import fileinput
  58. prices=[]
  59. i=0
  60. for n in fileinput.input("C:\Users\Public\Downloads\EURUSD.txt"):
  61. prices.append(eval(n))
  62. i+=1
  63. if i==300: break
  64.  
  65. show(prices,M1=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement