Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pylab import *
- import matplotlib.pyplot as plt
- from datetime import*
- import time
- from matplotlib.dates import DateFormatter, WeekdayLocator, HourLocator, \
- DayLocator, MONDAY
- from matplotlib.finance import candlestick,\
- plot_day_summary, candlestick2
- #link of 1-minute bars
- #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
- #DAILY PRICES
- #getting array of data, each of the format like ['20010103', '00:00:00', '0.9507', '0.9262', '0.9569', '0.9271']
- data=[n.split(',')[1:] for n in open("C:\Users\Public\Downloads\pinigai.csv").read().split()]
- #changing each cell of array to form like ({date converted in numeric form}, 1.123, 1.212, 1.463, 1.056)
- 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:]
- #for n in prices: print n #printig prepared list
- def show(prices,M1=False,H1=False,D1=False):
- '''takes daily prices (numeric date, low, high, min, max) and paints graph'''
- mondays = WeekdayLocator(MONDAY) # major ticks on the mondays
- alldays = DayLocator() # minor ticks on the days
- if M1: Formatter = DateFormatter('%Y %b %d %H:%M') #e.g. 2015 Jan 12 15:24
- if H1: Formatter = DateFormatter('%Y %b %d %H:%M') #e.g. 2015 Jan 12 15:24
- if D1: Formatter = DateFormatter('%Y %b %d') # e.g. 2015 Jan 12
- fig, ax = plt.subplots()
- fig.subplots_adjust(bottom=0.2) #bottom of table
- if D1: ax.xaxis.set_major_locator(WeekdayLocator(MONDAY)) #scales Ox axis highlighting Mondays
- if M1: ax.xaxis.set_major_locator(MinuteLocator(interval=10)) #scales Ox axis highlighting every ten minutes
- if H1: ax.xaxis.set_major_locator(HourLocator(interval=100)) #scales Ox axis highlighting Mondays ###############
- ax.xaxis.set_minor_locator(alldays)
- ax.xaxis.set_major_formatter(Formatter) #format of writing dates #############
- if M1: wid=0.0006
- if H1: wid=0.6
- if D1: wid=0.6
- candlestick(ax, prices, width=wid, colorup='g', colordown='r') ###########
- ax.xaxis.set_ticks_position('bottom') #direction of gradation ticks
- ax.yaxis.set_ticks_position('left')
- ax.tick_params(axis='both', direction='out', width=2, length=8,
- labelsize=12, pad=8) #highlighted gradation ticks
- ax.set_xlabel('TIME')
- ax.set_ylabel('EUR/USD')
- ax.xaxis_date() #don't know
- ax.autoscale_view() #responsible for graph position in the table - not neccessarry
- plt.setp( plt.gca().get_xticklabels(), rotation=25, horizontalalignment='right')
- plt.show()
- #prices=prices[10:240]
- #show(prices,H1=True)
- #READING 1M PRICES
- import fileinput
- prices=[]
- i=0
- for n in fileinput.input("C:\Users\Public\Downloads\EURUSD.txt"):
- prices.append(eval(n))
- i+=1
- if i==300: break
- show(prices,M1=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement