Advertisement
ImDerekD

TESTING22.py (12/26 9:47)

Dec 26th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.60 KB | None | 0 0
  1. #!/usr/bin/bash python
  2.  
  3. import csv
  4. import datetime
  5. from datetime import datetime
  6. from colorama import Back, Fore, Style
  7. from colorama import init
  8. import time
  9. import itertools
  10. from itertools import zip_longest
  11. from time import sleep
  12. with open('/Users/King/Desktop/iSpy.csv', 'r') as csv_file:
  13. csv_reader = csv.reader(csv_file)
  14. header = next(csv_reader)
  15.  
  16.  
  17. ref = [] # Start off w/ empty list
  18. ref_Num = int(0) # First to go in list = ref # (390 cells in 1 day)(using ref+=1 for each row)
  19. data = [] # Not sure but I could rearrange for liquidity?
  20. Liquidity = float()
  21. found = int(0)
  22. Range = []
  23. Target = []
  24. Range_List = {}
  25. Low_Range_Found = {}
  26. High_Range_Found = {}
  27. Range_Found = {}
  28. range_ref_String = ('')
  29. dTime = []
  30. printRanges = str()
  31. range_identifier_low = 'Low'
  32. range_identifier_high = 'High'
  33. range_identifier_all = 'All'
  34. All_Range_References = []
  35. All_Referenced_Prices = []
  36. menu_ans = input('What would you like to do? \n [1] Print Liquidity Data | [2] See previous ranges | [3] Test\n')
  37. if menu_ans == '1':
  38. Liquidity_Data = input('Would you like to print liquidity data? [y/n]: ')
  39. if menu_ans == '2':
  40. printRanges = input('Which ranges would you like to see?: [High/Low/All]\n')
  41. range_identifier = ''
  42. new_range = bool
  43. t = bool
  44. tLow = bool
  45. tHigh = bool
  46. Target = float()
  47. Range_Dict = {}
  48. TickString = str()
  49. TickSum = int()
  50. Tick = int(0)
  51. Tick_String = ''
  52. StartTraceback = {}
  53. day_Count = int()
  54. tList = []
  55. last = float()
  56. LT = float()
  57. HT = float()
  58. last = float()
  59. Strength = int()
  60. TrendStrength = ''
  61. Price_Tick = int()
  62. Previous = []
  63. for row in csv_reader:
  64. # row = [Time, Open, Close, High, Low, realVol, Money_Flow]
  65. ref_Num += 1 # Starting at 0
  66. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  67. Time = dTime[-14:]
  68. Open_Price = float(row[1]) # Price Data Dictionary
  69. Close_Price = float(row[2]) # Price Data Dictionary
  70. High_Price = float(row[3]) # Price Data Dictionary
  71. Low_Price = float(row[4]) # Price Data Dictionary
  72. Money_Flow = float(row[6]) # Price Data Dictionary
  73. Vol = row[5] # Price Data Dictionary
  74. f_Vol = float(Vol[:-1]) # Price Data Dictionary
  75. m_Vol = str(Vol[-1:]) # Price Data Dictionary
  76. if m_Vol == "K": # Price Data Dictionary
  77. f_Vol = f_Vol * 1000 # Price Data Dictionary
  78. if m_Vol == "M": # Price Data Dictionary
  79. f_Vol = f_Vol * 1000000
  80. if m_Vol != "K" and m_Vol != "M":
  81. f_Vol = float(row[5]) # Price Data Dictionary
  82. HLCC = round(float(High_Price + Low_Price + Close_Price + Close_Price)/4, 2) # Price Data Dictionary & RangeReference Dictionary
  83. M_Price = round(float(Money_Flow) / f_Vol, 2) # Price Data Dictionary & RangeReference Dictionary
  84. Diff = round(HLCC - M_Price, 2) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  85. MMM = float(f_Vol * HLCC) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  86. Liq_change = float(Money_Flow - MMM) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  87. Liquidity += Liq_change # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  88. Date = str(Time[:5]) # Important
  89. military_time = str(Time[-8:])
  90. criteria = abs(1) # Important
  91. allData = [ref_Num,Date, military_time, High_Price,Low_Price,Close_Price, HLCC, M_Price, f_Vol, Money_Flow,MMM, Liquidity,Liq_change]
  92. Data_Dict = {'REF#':[ref_Num],'Date':[Date],'Time':[military_time], 'Close_Price':[Close_Price], 'M_Price':[M_Price], 'Volume':[f_Vol]}
  93. '''USING THIS DATA
  94. [0]REFERENCE NUMBER
  95. [1]DATE
  96. [2]MILITARY_TIME
  97. [3]HIGH_PRICE
  98. [4]LOW_PRICE
  99. [5]CLOSE_PRICE
  100. [6]HLCC
  101. [7]M_Price
  102. [8]F_VOL
  103. [9]MONEY_FLOW
  104. [10]MARKETMAKERMOVE 'MMM'
  105. [11]LIQUIDITY
  106. [12]LIQ_CHANGE
  107. '''
  108. if abs(allData[7]-allData[6]) > criteria:
  109. found +=1
  110. diff = abs(M_Price - Close_Price)
  111. Range_Clause = True
  112. range_identifier_all = 'All'
  113. if Range_Clause == True:
  114. t_price = M_Price
  115. found_Price = HLCC
  116. Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
  117. High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
  118. Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
  119. High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
  120. if M_Price >= found_Price+diff:
  121. range_ref_String = "HIGH TARGET"
  122. tHigh = True
  123. Target = M_Price
  124. range_identifier = 'High'
  125. found_Price = HLCC
  126. tList = ['High', High_Target]
  127. elif M_Price<= found_Price-diff:
  128. range_ref_String = "LOW TARGET"
  129. tLow = True
  130. Target = M_Price
  131. range_identifier = 'Low'
  132. found_Price = HLCC
  133. tList = ['Low', Low_Target]
  134. RT_Reference1 = [Low_Range, High_Range, Low_Target, High_Target]
  135. LRS = '$'+str(Low_Range)
  136. LRT = '$'+str(Low_Target)
  137. HRS = '$'+str(High_Range)
  138. HRT = '$'+str(High_Target)
  139. found_Price_String = '$'+str(found_Price)
  140. RT_Reference = [LRS, LRT, HRS, HRT]
  141. Target = round(Target, 2)
  142. Target_String = '$'+str(Target)
  143. lows = [LRS, LRT]
  144. highs = [HRS, HRT]
  145. target_String = range_ref_String+': $'
  146. end_String = 'Price while found: $'+str(Close_Price)
  147. if printRanges == range_identifier and range_identifier == range_identifier_low:
  148. Low_Range_Reference = [Date, military_time, range_ref_String, Target_String, end_String]
  149. Low_Range_Found = {'\nData Found':Low_Range_Reference, 'Watch for: $':lows, 'Potential Resistance: ':highs}
  150. Low_Range = Low_Range_Found
  151. for k, v in dict.items(Low_Range):
  152. print(Fore.RED, k, v)
  153. if printRanges == range_identifier and range_identifier == range_identifier_high:
  154. High_Range_Reference = [Date, military_time, range_ref_String, Target_String, end_String]
  155. High_Range_Found = {'\nData Found': High_Range_Reference, 'Watch for: $':highs, 'Potential Support: ':lows}
  156. High_Range = High_Range_Found
  157. for k, v in dict.items(High_Range):
  158. print(Fore.CYAN, k, v)
  159. if printRanges == range_identifier_all and range_identifier_all == range_identifier_all:
  160. Range_Reference = [Date, military_time, Close_Price, range_ref_String]
  161. TRange_Reference = [LRS, HRS, LRT, HRT]
  162. Range_Found = {'<-- Reference': Range_Reference, 'TRange Reference': TRange_Reference}
  163. Range_List[ref_Num] = Range_Found
  164. print(Back.BLUE+Fore.WHITE+str(found), str(Range_Found)+Style.RESET_ALL)
  165. else:
  166. Range_Clause = False
  167. tHigh = False
  168. tLow = False
  169. if menu_ans == '1' and Liquidity_Data =='y':
  170. if Close_Price > Open_Price:
  171. Price_Tick = 1
  172. if Close_Price < Open_Price:
  173. Price_Tick = -1
  174. if Liq_change > 0:
  175. Liq_Tick = 1
  176. if Liq_change < 0:
  177. Liq_Tick = -1
  178. Tick = Liq_Tick + Price_Tick
  179. Strength += Tick
  180. if Tick > 0:
  181. Tick_String = Fore.BLUE+Back.GREEN+'STRONG BUYERS'
  182. if Tick < 0:
  183. Tick_String = Fore.RED+Back.YELLOW+'STRONG SELLERS'
  184. if Tick == 0 and Price_Tick > 0:
  185. Tick_String = Fore.WHITE+'WEAK BUYERS'
  186. if Tick == 0 and Liq_Tick > 0:
  187. Tick_String = Fore.RED+'SHORT COVERING'
  188. Range_List[ref_Num] = Range_Found
  189. t = False
  190. tHigh = tHigh
  191. tLow = tLow
  192.  
  193. Close_Price = Close_Price
  194. if tHigh == True:
  195. t = True
  196. HRS = str(High_Range)
  197. HRT = str(High_Target)
  198. LRS = str(Low_Range)
  199. LRT = str(Low_Target)
  200. print(Fore.YELLOW+'['+Date+']',military_time,Style.RESET_ALL+Fore.BLUE+Back.YELLOW+Style.BRIGHT+'Current Liquidity:'+'{:20,.2f}'.format(Liquidity)+Style.RESET_ALL+Fore.BLUE+Back.YELLOW+Style.BRIGHT+' Liq Change: '+'{:20,.2f}'.format(Liq_change)+Style.RESET_ALL, Fore.YELLOW+Back.BLUE+Style.BRIGHT,'Last Price: [$'+str(Close_Price)+'] '+Style.RESET_ALL+Tick_String+Style.RESET_ALL+Fore.GREEN+Back.BLUE+Style.BRIGHT+' NEW HIGH RANGE FOUND:[$'+HRS+']'+' NEW HIGH TARGET FOUND: [$'+HRT+']'+Style.RESET_ALL)
  201. time.sleep(2)
  202. add_Range_Target = input('Would you like to add this range to file?: [y/n]:')
  203. if add_Range_Target == 'y':
  204. with open('/Users/King/Desktop/RangeTargets.csv', 'a') as csv_file:
  205. file_PriceList = [Date, military_time, range_ref_String, Close_Price, M_Price, HRT, Money_Flow, f_Vol, LRS, LRT]
  206. wr = csv.writer(csv_file)
  207. wr.writerow(file_PriceList)
  208. else:
  209. t = False
  210. Close_Price = Close_Price
  211. if tLow == True:
  212. t = True
  213. HRS = str(High_Range)
  214. HRT = str(High_Target)
  215. LRS = str(Low_Range)
  216. LRT = str(Low_Target)
  217. Low_Prices = {'LOW RANGE: $': Low_Range, 'LOW TARGET: $': Low_Target} ##### May not need this line
  218. print(Fore.YELLOW+'['+Date+']',military_time,Style.RESET_ALL+Fore.CYAN+Back.RED+Style.BRIGHT+'Current Liquidity:'+'{:20,.2f}'.format(Liquidity)+Style.RESET_ALL+Fore.CYAN+Back.RED+Style.BRIGHT+' Liq Change: '+'{:20,.2f}'.format(Liq_change)+Style.RESET_ALL, Fore.YELLOW+Back.BLUE+Style.BRIGHT,'Last Price: [$'+str(Close_Price)+'] '+Style.RESET_ALL+Tick_String+Style.RESET_ALL+Fore.CYAN+Back.RED+Style.BRIGHT+' NEW LOW RANGE FOUND:[$'+LRS+']'+' NEW LOW TARGET FOUND: [$'+LRT+']'+Style.RESET_ALL)
  219. time.sleep(2)
  220. add_Range_Target = input('Would you like to add this range to file?: [y/n]:')
  221. if add_Range_Target == 'y':
  222. with open('/Users/King/Desktop/RangeTargets.csv', 'a') as csv_file:
  223. file_PriceList = [Date, military_time, range_ref_String, Close_Price, M_Price, LRT, Money_Flow, f_Vol, HRS, HRT]
  224. wr = csv.writer(csv_file)
  225. wr.writerow(file_PriceList)
  226. else:
  227. t = False
  228. if Liquidity > 0:
  229. if Liq_change > 0:
  230. time.sleep(.005)
  231. print(Fore.YELLOW+'['+Date+']', military_time,Fore.GREEN+'Current Liquidity:'+'{:20,.2f}'.format(Liquidity)+Fore.GREEN+' Liq Change: ' + '{:20,.2f}'.format(Liq_change)+' '+Fore.YELLOW+Back.BLUE, 'Last Price [$'+str(Close_Price)+'] '+Tick_String+Style.RESET_ALL)
  232. if Liq_change < 0:
  233. time.sleep(.005)
  234. print(Fore.YELLOW+'['+Date+']', military_time,Fore.GREEN+'Current Liquidity:'+'{:20,.2f}'.format(Liquidity)+Style.RESET_ALL+Fore.RED+' Liq Change: '+'{:20,.2f}'.format(Liq_change)+Style.RESET_ALL+' '+Fore.YELLOW+Back.BLUE, 'Last Price [$'+str(Close_Price)+'] '+Tick_String+Style.RESET_ALL)
  235. if Liq_change > 0:
  236. if Liquidity < 0:
  237. time.sleep(.005)
  238. print(Fore.YELLOW+'['+Date+']', military_time,Fore.BLUE+'Current Liquidity:'+'{:20,.2f}'.format(Liquidity)+Style.RESET_ALL+Fore.CYAN,' Liq Change: '+'{:20,.2f}'.format(Liq_change)+' '+Fore.YELLOW+Back.BLUE, 'Last Price [$'+str(Close_Price)+'] '+Tick_String+Style.RESET_ALL)
  239. if abs(Liq_change) > 500000:
  240. time.sleep(.005)
  241. print(Fore.CYAN+'['+Date+']',military_time,Fore.CYAN+'Current Liquidity:'+'{:20,.2f}'.format(Liquidity)+Style.RESET_ALL+Fore.YELLOW+Back.BLUE+Style.BRIGHT+' Liq Change: '+'{:20,.2f}'.format(Liq_change)+' '+Fore.YELLOW+Back.BLUE, 'Last Price [$'+str(Close_Price)+'] '+Tick_String+Style.RESET_ALL)
  242.  
  243. if menu_ans == '3':
  244. Days = ref_Num // 390
  245. Hours = float(ref_Num / 60)
  246. HoursLeft = float(ref_Num / 390 - Days) / 60
  247. Minutes = ref_Num
  248. MinutesLeft = HoursLeft * 100
  249. print('Total Minutes recorded: ',ref_Num)
  250. print('Total Days recorded ', Days,'Days', str(round(HoursLeft, 2)), 'Hours', str(round(MinutesLeft, 2)), 'Minutes')
  251. input = input('Would you like to see other found ranges?: [y/n]')
  252. if input == 'y':
  253. with open('/Users/King/Desktop/RangeTargets.csv', 'r') as csv_file:
  254. csv_reader = csv.reader(csv_file)
  255. for row in csv_reader:
  256. Date = row[0]
  257. Time = row[1]
  258. range_ref_String = row[2]
  259. Close_Price = float(row[3])
  260. M_Price = float(row[4])
  261. TargetPrice = row[5]
  262. Money_Flow = float(row[6])
  263. f_Vol = float(row[7])
  264. OppRange = row[8]
  265. OppTarget = row[9]
  266. list = [Date, Time, range_ref_String]
  267. Targets = [M_Price, TargetPrice]
  268. oppositePrices = [OppRange, OppTarget]
  269. listlist = [TargetPrice, OppRange, OppTarget]
  270. dict = {'Info':list, 'Targets: ':Targets, 'Found price: ':Close_Price, 'Opposite Ranges/Targets':oppositePrices}
  271. print(dict)
  272.  
  273.  
  274.  
  275. '''print(Fore.CYAN+'REF#:', ref_Num)
  276. time.sleep(.25)
  277. print(Fore.WHITE+Time)
  278. time.sleep(.25)
  279. print("Last:", "$" + str(Close_Price))
  280. time.sleep(.25)
  281. print("HLCC:", "$" + str(HLCC))
  282. time.sleep(.25)
  283. print("Money Price: ", "$" + str(round(M_Price, 2)))
  284. time.sleep(.25)
  285. print('Price Diff: '+'$'+str(Diff))
  286. time.sleep(.25)
  287. if f_Vol > 1000000:
  288. print(Fore.YELLOW+'Volume:' + '{:20,.2f}'.format(f_Vol))
  289. else:
  290. print(Fore.WHITE+'Volume:' + '{:20,.2f}'.format(f_Vol))
  291. time.sleep(.25)
  292. if Money_Flow > 350000000:
  293. print(Fore.YELLOW+'$Flow:' + '{:20,.2f}'.format(Money_Flow))
  294. else:
  295. print(Fore.WHITE+'$Flow:' + '{:20,.2f}'.format(Money_Flow))
  296. time.sleep(.25)
  297. if Liq_change < 0:
  298. print(Fore.RED+'Liq Change:', '{:20,.2f}'.format(Liq_change), Style.RESET_ALL)
  299. else:
  300. print(Fore.CYAN+'Liq Change:', '{:20,.2f}'.format(Liq_change))
  301. time.sleep(.25)
  302. if Liquidity < 0:
  303. print(Fore.RED+'Current Liquidity:' + '{:20,.2f}'.format(Liquidity),Style.RESET_ALL)
  304. else:
  305. print(Fore.CYAN+'Current Liquidity:' + '{:20,.2f}'.format(Liquidity),Style.RESET_ALL)
  306. time.sleep(.25)
  307. if abs(Strength) > 2 and Strength > 2:
  308. print(Fore.CYAN+'Current Strength: '+ str(Strength))
  309. if Strength < -2:
  310. print(Fore.RED+'Current Strength: ' +str(Strength))'''
  311.  
  312.  
  313. '''if found >0:
  314. tList = tList
  315. if tList[1] == 'High':
  316. print(Fore.GREEN+'LAST RANGE FOUND: [$' + str(Low_Range)+']','[$' + str(High_Range)+']', ' [' + range_ref_String + ': $' + str(Target)+']'+Style.RESET_ALL)
  317. print(Fore.GREEN+'POTENTIAL TARGETS: [$' + str(Low_Target)+']', '[$' + str(High_Target)+']'+Style.RESET_ALL)
  318. print(Fore.GREEN+'Found price: [$' + found_price + ']', 'Target implies a move of [' + implied_move + '%]'+'from current price ['+str(Close_Price)+']'+Style.RESET_ALL)
  319. else:
  320. tList = tList
  321. if tList[1] == 'Low':
  322. print(Fore.RED+'LAST RANGE FOUND: [$' + str(Low_Range)+']','$' + str(High_Range) + ' [' + range_ref_String + ': $' + str(Target)+Style.RESET_ALL)
  323. print(Fore.RED+'POTENTIAL TARGETS: [$' + str(Low_Target)+']', '$' + str(High_Target)+Style.RESET_ALL)
  324. print(Fore.RED+'Found price: [$' + (found_price) + ']', 'Target implies a move of [' + implied_move + '%]' + 'from current price [' + str(Close_Price) + ']'+Style.RESET_ALL)
  325.  
  326. input = input('Would you like to see other found ranges?: [y/n]')
  327. with open('/Users/King/Desktop/RangeTargets.csv' 'r') as csv_file:
  328. csv_reader = csv.reader(csv_file)
  329. for row in csv_file:
  330. row[0] = Date
  331. row[1] = Time
  332. row[2] = range_ref_String
  333. row[3] = Close_Price
  334. row[4] = M_Price
  335. row[5] = TargetPrice
  336. row[6] = Money_Flow
  337. row[7] = f_Vol
  338. row[8] = OppRange
  339. row[9] = OppTarget'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement