ImDerekD

Criteria > .3% Close

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