Advertisement
ImDerekD

ISPYTESTALLFINISHED_02_06

Feb 6th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.26 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. import sys
  8. from termcolor import colored, cprint
  9. from colorama import init
  10. import numbers
  11. import time
  12. import itertools
  13. from itertools import zip_longest
  14. from time import sleep
  15. import pathlib
  16. import os
  17. import os.path
  18. from pathlib import Path
  19. import glob
  20. from progress.bar import Bar
  21. import hashlib
  22.  
  23. #File Entry / Open / Confirm
  24. # filename_input = input('Filename: ')
  25. dir = '/Users/King/iFiles/'
  26.  
  27. # confirmFile = Path(dir+filename_input+'.csv')
  28. # FileExists = Path.is_file(confirmFile)
  29.  
  30. #Data in File
  31.  
  32.  
  33.  
  34.  
  35.  
  36. for file in glob.glob(dir+'*2.csv'):
  37. filename = file[19:-4]
  38. ticker = filename[:-1]
  39. candleDur = filename[-1:]
  40. ref_Num = int(0)
  41. Liquidity = float()
  42.  
  43. #HashAll
  44.  
  45. CurrentInfo = []
  46.  
  47. regDate = []
  48. regTime = []
  49. hashDateTime1 = []
  50. hashDateTime2 = []
  51. hashData1 = []
  52.  
  53. #MIV
  54. MIVList = []
  55. prevPrice = float(1)
  56. prevFlow = float(1)
  57. prevVol = int(1)
  58. counter = int()
  59.  
  60. xLiq = float()
  61. xVol = int()
  62. xLFP = float()
  63. xVLiq = float()
  64. xMIV = float()
  65.  
  66. #Ranges
  67. tHigh = bool
  68. tLow = bool
  69. Filled = bool
  70.  
  71. lows_Found = int()
  72. lows_Filled = int()
  73.  
  74. highs_Found = int()
  75. highs_Filled = int()
  76.  
  77. Found = int()
  78. last = float()
  79. #TimeTakenForRangesToGetFilled
  80. timeTaken = []
  81. count = int()
  82. x = int(0)
  83. n = int(0)
  84. with open(file, 'r') as csv_file:
  85. reader = csv.reader(csv_file)
  86. header = next(reader)
  87. for row in reader:
  88. ref_Num += 1
  89. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  90. Time = dTime[-14:]
  91. Open_Price = float(row[1])
  92. Close_Price = float(row[2])
  93. High_Price = float(row[3])
  94. Low_Price = float(row[4])
  95. Money_Flow = float(row[6])
  96. last = Close_Price
  97. Vol = row[5]
  98. f_Vol = float(Vol[:-1])
  99. m_Vol = str(Vol[-1:])
  100. if m_Vol == "K":
  101. f_Vol = f_Vol * 1000
  102. if m_Vol == "M":
  103. f_Vol = f_Vol * 1000000
  104. if m_Vol != "K" and m_Vol != "M":
  105. f_Vol = float(row[5])
  106. if f_Vol < 1:
  107. M_Price = HLCC
  108. else:
  109. M_Price = round(float(Money_Flow) / f_Vol, 2)
  110. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price)/4
  111. Diff = round(HLCC - M_Price, 2)
  112. MMM = float(f_Vol * HLCC)
  113. Liq_change = float(Money_Flow - MMM)
  114. Liquidity += Liq_change
  115. Date = str(Time[:5])
  116. military_time = str(Time[-8:])
  117. criteria = abs(.0035*HLCC)
  118.  
  119.  
  120. if abs(Liq_change) > 0:
  121. LiqFlowPrice = round(Money_Flow / abs(Liq_change), 2)
  122. VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
  123. LiqFlowPriceClone = round(1000*(abs(Liq_change) / Money_Flow), 4)
  124.  
  125.  
  126. if Money_Flow > 0:
  127. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 2)
  128. prevPrice = Close_Price
  129. prevFlow = Money_Flow
  130. prevVol = f_Vol
  131.  
  132. if abs(MIV_Index) > 3:
  133. Volume = '{:20,.2f}'.format(f_Vol)
  134. AbsLiqChange = '{:20,.2f}'.format(Liq_change)
  135. LFP = '{:20,.2f}'.format(LiqFlowPrice)
  136. VolumeLiqPrice = '{:20,.2f}'.format(VolLiqPrice)
  137. ExtremeMIVList = [Date,military_time,MIV_Index,AbsLiqChange,Volume,LFP,VolumeLiqPrice,LiqFlowPriceClone]
  138. MIVList.append(ExtremeMIVList)
  139.  
  140.  
  141. if abs(M_Price-HLCC) >= criteria:
  142. diff = M_Price - HLCC
  143. Range_Clause = True
  144. Found += 1
  145. FoundPrice = Close_Price
  146. Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
  147. High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
  148. Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
  149. High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
  150.  
  151. r_Price = M_Price
  152. t_Price = M_Price + diff
  153. opp_Range = round(float(HLCC + (diff*-1)), 2)
  154. opp_Target = round(float(opp_Range + (diff*-1)), 2)
  155. if r_Price == Low_Range:
  156. tLow = True
  157. tHigh = False
  158. Filled = False
  159. lows_Found += 1
  160. RangeString = str(r_Price)
  161. FoundPriceString = str(FoundPrice)
  162. range_ref_String = Fore.RED+"[LOW TARGET]"
  163. foundDate = Fore.RED+Date+' '+military_time
  164. TargetString = str(t_Price)
  165. '''print(Fore.RED+"LOW TARGET",RangeString, TargetString, Style.RESET_ALL)
  166. time.sleep(1.5)'''
  167. if r_Price == High_Range and MIV_Index < 0:
  168. foundDate = Fore.CYAN+Date+' '+military_time
  169. range_ref_String = Fore.CYAN+"[HIGH TARGET]"
  170. tLow = False
  171. tHigh = True
  172. Filled = False
  173. highs_Found += 1
  174. RangeString = str(r_Price)
  175. TargetString = str(t_Price)
  176. '''print(Fore.CYAN+"HIGH TARGET",RangeString, TargetString, Style.RESET_ALL)
  177. time.sleep(1.5)'''
  178. if Filled == False and tHigh == True:
  179. count += 1
  180. if High_Price >= High_Range:
  181. timeTaken.append(count)
  182. Filled = True
  183. highs_Filled += 1
  184. '''print(Fore.CYAN+"HIGH RANGE FILLED", Style.RESET_ALL)
  185. time.sleep(1)'''
  186. count = count*0
  187.  
  188. if Filled == False and tLow == True:
  189. count += 1
  190. if Low_Price <= Low_Range:
  191. timeTaken.append(count)
  192. Filled = True
  193. lows_Filled += 1
  194. '''print(Fore.RED+"LOW RANGE FILLED", Style.RESET_ALL)
  195. time.sleep(1)'''
  196. count = count*0
  197.  
  198. '''print(Date, military_time, Close_Price)'''
  199.  
  200.  
  201.  
  202. if highs_Found > 0 and lows_Found > 0:
  203. if highs_Filled and lows_Filled > 0:
  204. lowAccuracy = 100*round(lows_Filled / lows_Found, 2)
  205. highAccuracy = 100*round(highs_Filled / highs_Found, 2)
  206. print('$%s' % ticker, '%s Min File' % candleDur)
  207. if lowAccuracy > 70:
  208. print(Fore.RED+'Lows Found: '+Fore.CYAN,lows_Found, ' | ', lows_Filled, '[',lowAccuracy,'%]'+Style.RESET_ALL)
  209. else:
  210. print(Fore.RED+'Lows Found: '+Fore.YELLOW,lows_Found, ' | ', lows_Filled, '[',lowAccuracy,'%]'+Style.RESET_ALL)
  211. if highAccuracy > 70:
  212. print(Fore.CYAN+'Highs Found: ',highs_Found, ' | ', highs_Filled, '[',highAccuracy,'%]'+Style.RESET_ALL)
  213. else:
  214. print(Fore.CYAN+'Highs Found: '+Fore.YELLOW,highs_Found, ' | ', highs_Filled, '[',highAccuracy,'%]'+Style.RESET_ALL)
  215. AbsolutePriceRange = abs(Close_Price - t_Price) + abs(Close_Price - opp_Target)
  216. percent_in_range = 100-(100*round(abs(Close_Price - t_Price) / AbsolutePriceRange, 2))
  217. print('Direction: %s' % range_ref_String+Style.RESET_ALL)
  218. print('Last Price: [$',Close_Price,']','Found Price: [$',FoundPrice,']')
  219. print('Range Price: [$',r_Price,']', 'Opposite Range: [$',opp_Range,']')
  220. print('Percent in Range: [',percent_in_range,'%]')
  221. LN = round(100*(Close_Price - FoundPrice) / Close_Price, 2)
  222. print(Fore.WHITE+'Found: '+foundDate)
  223. if LN > 0:
  224. LNString = Fore.CYAN+str(LN)
  225. print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
  226. if LN < 0:
  227. LNString = Fore.RED+str(LN)
  228. print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
  229.  
  230. for i in timeTaken[-5:]:
  231. i = int(i)
  232. x += i
  233. n += 1
  234. Minute = 1
  235. AvgTimeTakenFilled = round(x / n, 2)
  236. if x > 60:
  237. Hour = AvgTimeTakenFilled // 60
  238. Minute = round(AvgTimeTakenFilled - (Hour*60), 2)
  239.  
  240. print('\nAvg Time Taken until Filled, Hours: [',Hour,'] Minutes: [',Minute,']\n')
  241. else:
  242. if highs_Found > 0 or lows_Found >0:
  243. print(Fore.WHITE+'$%s' % ticker, '%s Min File' % candleDur, '[Insufficient Accuracy Data]'+Style.RESET_ALL)
  244. print(Fore.RED+'Lows Found: ',lows_Found)
  245. print(Fore.CYAN+'Highs Found: ',highs_Found)
  246. AbsolutePriceRange = abs(Close_Price - t_Price) + abs(Close_Price - opp_Target)
  247. percent_in_range = 100-(100*round(abs(Close_Price - t_Price) / AbsolutePriceRange, 3))
  248. print('Direction: %s' % range_ref_String+Style.RESET_ALL)
  249. print('Last Price: [$',Close_Price,']','Found Price: [$',FoundPrice,']')
  250. print('Range Price: [$',r_Price,']', 'Opposite Range: [$',opp_Range,']')
  251. print('Percent in Range: [',percent_in_range,'%]')
  252. LN = round(100*(Close_Price - FoundPrice) / Close_Price, 2)
  253. print(Fore.WHITE+'Found: '+foundDate)
  254. if LN > 0:
  255. LNString = Fore.CYAN+str(LN)
  256. print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
  257. if LN < 0:
  258. LNString = Fore.RED+str(LN)
  259. print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
  260. print('\n')
  261.  
  262. #
  263. # '''Title = 'DATE Time MIV Liq Change Volume LiqFlowPrice VolLiqPrice | Liq/$Flow '
  264. # print(Title)
  265. #
  266. #
  267. #
  268. #
  269. #
  270. #
  271. # for i in MIVList[1:]:
  272. # counter += 1
  273. # Date = i[0]
  274. # military_time = i[1]
  275. # MIV = i[2]
  276. # Liq_Change = i[3]
  277. # Volume = i[4]
  278. # LiqFlowPrice = i[5]
  279. # VolLiqPrice = i[6]
  280. # LiqFlow = i[7]
  281. #
  282. # if MIV < 0:
  283. # print(Fore.CYAN,i,Style.RESET_ALL)
  284. # if MIV > 0:
  285. # print(Fore.RED,i,Style.RESET_ALL)'''
  286. # xMIV += abs(MIV)
  287. # xLiq += abs(Liq_Change)
  288. # xVol += Volume
  289. # xLFP += LiqFlow
  290. # xVolLiq += VolLiqPrice
  291. #
  292. # avgMIV = xMIV / counter
  293. # avgLiqChange = xLiq / counter
  294. # avgVol = xVol / counter
  295. # avgLFP = xLFP / counter
  296. # avgVolLiq = xVolLiq / counter
  297. # if abs(MIV) > avgMIV:
  298. # MIV_String = str(Fore.YELLOW+MIV+Style.RESET_ALL)
  299. # if abs(Liq_change) > avgLiqChange:
  300. # Liq_changeString = str(Fore.YELLOW+Liq_changeString+Style.RESET_ALL)
  301. # if Volume > avgVol:
  302. # VolumeString = str(Fore.YELLOW+Volume+Style.RESET_ALL)
  303. # if LiqFlowPrice > avgLFP:
  304. # LiqFlowPriceString = str(Fore.YELLOW+LiqFlowPrice+Style.RESET_ALL)
  305. # if VolLiqPrice > avgVolLiq:
  306. # VolLiqPriceString = str(Fore.YELLOW+VolLiqPriceString+Style.RESET_ALL)
  307. # if LFP > avgLFP:
  308. # LFPString = str(Fore.YELLOW+LFP+Style.RESET_ALL)
  309. # else:
  310. # print(Fore.WHITE,i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement