Advertisement
ImDerekD

tcopy.py_March5th

Mar 5th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.37 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import csv
  4. from datetime import datetime
  5. import time
  6. from colorama import Back, Fore, Style
  7. import statistics
  8.  
  9.  
  10.  
  11. Liquidity = float()
  12. ref_Num = int()
  13. prevVol = float(1)
  14. prevPrice = float(1)
  15. prevFlow = float(1)
  16. ValuePrice = float()
  17.  
  18. SumFlow = float()
  19. SumVol = float()
  20. Bearish = bool
  21. Bullish = bool
  22.  
  23. Price1 = float()
  24. Price2 = float()
  25. prevPrice1 = float()
  26.  
  27. Last = float()
  28. PL = float()
  29. PLString = str()
  30. Chg = float()
  31. SignalList = []
  32.  
  33. MIV_Spike = float()
  34. MIV_Spike_Count = int()
  35.  
  36. SpreadList = []
  37. TotalSpread = float()
  38. ThreeHourSpreadAvg = float()
  39. OneHourSpreadAvg = float()
  40.  
  41. SpreadRatio = float()
  42.  
  43.  
  44. Mark = int()
  45.  
  46. with open('/Users/King/data.csv', 'r') as csv_file:
  47. reader = csv.reader(csv_file)
  48. header = next(reader)
  49. for row in reader:
  50. ref_Num += 1
  51. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  52. Time = dTime[-14:]
  53. Open_Price = float(row[1])
  54. Close_Price = float(row[2])
  55. High_Price = float(row[3])
  56. Low_Price = float(row[4])
  57. Money_Flow = float(row[6])
  58. last = Close_Price
  59. Vol = row[5]
  60. f_Vol = float(Vol[:-1])
  61. m_Vol = str(Vol[-1:])
  62. if m_Vol == "K":
  63. f_Vol = f_Vol * 1000
  64. if m_Vol == "M":
  65. f_Vol = f_Vol * 1000000
  66. if m_Vol != "K" and m_Vol != "M":
  67. f_Vol = float(row[5])
  68. if f_Vol < 1:
  69. M_Price = HLCC
  70. else:
  71. M_Price = round(float(Money_Flow) / f_Vol, 2)
  72. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price) / 4
  73. Diff = round(HLCC - M_Price, 2)
  74. MMM = float(f_Vol * HLCC)
  75. Liq_change = float(Money_Flow - MMM)
  76. Liquidity += Liq_change
  77. Date = str(Time[:5])
  78. military_time = str(Time[-8:])
  79. criteria = abs(.0035 * HLCC)
  80. HLC3 = float(High_Price+ Low_Price + Close_Price + Close_Price + Close_Price) / 5
  81. Mid = High_Price - abs(High_Price - Low_Price)
  82. Paway = round(100*((M_Price - Close_Price) / Close_Price), 3)
  83.  
  84.  
  85. SumVol += f_Vol
  86. SumFlow += Money_Flow
  87. ValuePrice1 = round(SumFlow / SumVol, 2)
  88. MidValPrice = [ValuePrice1,Close_Price]
  89. ValuePrice = round(statistics.median(MidValPrice), 2)
  90.  
  91. Spread = round(abs(Close_Price - ValuePrice), 2)
  92. SpreadList.append(Spread)
  93.  
  94. criteria2 = abs(.003 * HLCC)
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. if ref_Num >=2:
  104. prevPrice1 = Close_Price
  105.  
  106. if HLCC <= ValuePrice:
  107. Bearish = True
  108. Bullish = False
  109. Signal = 'SELL'
  110. SignalStr = Fore.RED+Signal+Style.RESET_ALL
  111. SignalList.append(Signal)
  112.  
  113.  
  114.  
  115.  
  116.  
  117. if HLCC >= ValuePrice:
  118. Bearish = False
  119. Bullish = True
  120. Signal = 'BUY'
  121. SignalStr = Fore.CYAN+Signal+Style.RESET_ALL
  122. SignalList.append(Signal)
  123.  
  124.  
  125.  
  126.  
  127.  
  128. if Liq_change > 0:
  129. liqchgstr = '{:20,.2f}'.format(Liq_change)+Style.RESET_ALL
  130. LiqChangeStr = Fore.CYAN+liqchgstr+Style.RESET_ALL
  131.  
  132. if Liq_change < 0:
  133. liqchgstr = '{:20,.2f}'.format(Liq_change)+Style.RESET_ALL
  134. LiqChangeStr = Fore.RED+liqchgstr+Style.RESET_ALL
  135.  
  136. DateStr = Fore.YELLOW+str(Date)+Style.RESET_ALL
  137. TimeStr = Fore.YELLOW+str(military_time)+Style.RESET_ALL
  138.  
  139. if Liquidity > 0:
  140. Liqstr = '{:20,.2f}'.format(Liquidity)
  141. LiqStr = Fore.CYAN+Liqstr+Style.RESET_ALL
  142.  
  143. if Liquidity < 0:
  144. Liqstr = '{:20,.2f}'.format(Liquidity)
  145. LiqStr = Fore.WHITE+Liqstr+Style.RESET_ALL
  146.  
  147.  
  148.  
  149.  
  150. if Money_Flow > 0:
  151. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
  152. prevPrice = Close_Price
  153. prevFlow = Money_Flow
  154. prevVol = f_Vol
  155. MIV_Index_String = str(MIV_Index)
  156. LiqFlowPrice = round(abs(Liq_change / Money_Flow), 4)
  157.  
  158. if MIV_Index >= .25:
  159. MIV_Spike += abs(MIV_Index)
  160. MIV_Spike_Count += 1
  161. Avg_MIV_Spike = round(MIV_Spike / MIV_Spike_Count, 3)
  162.  
  163.  
  164. if abs(Liq_change) > 0:
  165. LiqFlowPrice = .01*round(Money_Flow / abs(Liq_change), 3)
  166. VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
  167. LiqFlowPriceClone = round(1000 * (abs(Liq_change) / Money_Flow), 4) * .01
  168. ##################################################################################################################################################################
  169. if abs(M_Price - HLCC) >= criteria:
  170. Range_Clause = True
  171. diff = abs(M_Price - Close_Price)
  172. if Range_Clause == True:
  173. found_Price = Close_Price
  174. range_ref_String = str()
  175. Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
  176. High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
  177. Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
  178. High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
  179. if M_Price >= High_Range:
  180. r_Price = M_Price
  181. t_Price = High_Target
  182. oppRange = Low_Range
  183. oppTarget = Low_Target
  184. tHigh = True
  185. found_Price = Close_Price
  186. tLow = False
  187. range_ref_String = 'HIGH TARGET'
  188. if MIV_Index > 0:
  189. range_ref_String = 'FALSE HIGH TARGET (CAPPER)'
  190. elif M_Price <= Low_Range:
  191. r_Price = M_Price
  192. t_Price = Low_Target
  193. oppRange = High_Range
  194. oppTarget = High_Target
  195. tLow = True
  196. tHigh = False
  197. found_Price = Close_Price
  198. range_ref_String = 'LOW TARGET'
  199.  
  200.  
  201. if range_ref_String == 'FALSE HIGH TARGET (CAPPER)':
  202. Program = 'HIGH CONFIDENCE'
  203.  
  204. if range_ref_String == 'LOW TARGET':
  205. if LiqFlowPriceClone >= .039:
  206. if LiqFlowPrice <= 2.65 and LiqFlowPrice >= 2.5:
  207. Program = 'MODERATE CONFIDENCE'
  208. if LiqFlowPrice <= 2.5 and LiqFlowPrice >= 2.45:
  209. Program = 'HIGH CONFIDENCE'
  210. if LiqFlowPrice <= 2.45:
  211. Program = 'VOLATILE LOW (HIGH CONFIDENCE)'
  212. else:
  213. Program = 'LOW CONFIDENCE / LIQUIDITY SEARCH'
  214.  
  215.  
  216.  
  217. if LiqFlowPriceClone >=.039 and range_ref_String == 'HIGH TARGET':
  218. if LiqFlowPrice < 2.6:
  219. Program = 'VOLATILE BULL TRAP (MODERATE CONFIDENCE)'
  220. if LiqFlowPrice > 2.6 and LiqFlowPrice < 2.8:
  221. if abs(MIV_Index) >= Avg_MIV_Spike * .75:
  222. HighRangeStr = str(High_Target)
  223. Program = 'HIGH CONFIDENCE (IMMEDIATE PRESSURE: %s)' % HighRangeStr
  224. Program = 'MODERATE CONFIDENCE'
  225.  
  226. if LiqFlowPrice >= 2.81 and range_ref_String == 'HIGH TARGET':
  227. Program = 'BIG BULLISH'
  228.  
  229.  
  230. if LiqFlowPriceClone <= .037:
  231. if range_ref_String == 'HIGH TARGET':
  232. if LiqFlowPrice >= 2.75:
  233. oppTargetStr = str(oppTarget)
  234. if abs(MIV_Index) >= Avg_MIV_Spike * 3:
  235. Program = '<<LONG TERM>> BULLISH (BTMFD)'+oppTargetStr
  236. if LiqFlowPrice <= 2.75 and LiqFlowPrice >= 2.75:
  237. Program = 'VERY HIGH CONFIDENCE'
  238.  
  239.  
  240.  
  241.  
  242. if LiqFlowPriceClone <= .036 and LiqFlowPrice > 2.8:
  243. if tLow == True:
  244. if MIV_Index < 0:
  245. LowRangePT = round(Close_Price - abs(oppTarget - Low_Target), 2)
  246. LowRangePL = round(-1*(Close_Price - LowRangePT) / Close_Price, 2)
  247. Program = 'EXTREMELY HIGH CONFIDENCE (PT [%s])' % LowRangePL
  248. elif MIV_Index > 0:
  249. HighRangeStr = str(High_Range)
  250. Program = 'EXTREMELY HIGH CONFIDENCE (SELL %s)' % HighRangeStr
  251. if tHigh == True:
  252. if MIV_Index < 0 and abs(MIV_Index) > Avg_MIV_Spike:
  253. HighRangePT = round(Close_Price + (High_Target - Low_Target), 2)
  254. HighRangePL = round((HighRangePT - Close_Price) / Close_Price, 2)
  255. HighRangePTStr = str(HighRangePT)
  256. HighRangePLStr = str(HighRangePL)+'%'
  257. if HighRangePT > Close_Price:
  258. Program = 'MAXIMUM CONFIDENCE PT [$ %s]' % HighRangePT
  259. else:
  260. Program = 'SELL THE FUCKING RIP (<<IMMEDIATE TERM ONLY>>)'
  261.  
  262. if abs(MIV_Index) < Avg_MIV_Spike:
  263. HighRangeStr = str(High_Range)
  264. Program = 'BULLS FULLA SHIT [RIP] (SELL %s)' % HighRangeStr
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. if tHigh == True and MIV_Index < 0:
  272. if abs(MIV_Index) >= Avg_MIV_Spike * 3:
  273. Program = 'EXTREMELY HIGH CONFIDENCE'
  274.  
  275. if LiqFlowPriceClone >= .042 and LiqFlowPrice <= 2.40:
  276. if range_ref_String == 'LOW TARGET':
  277. HR_String = str(High_Range)
  278. HT_String = str(High_Target)
  279. Program = 'FALSE LOW (BULLISH TERRITORY %s - %s)' % (HR_String, HT_String)
  280. if range_ref_String == 'HIGH TARGET':
  281. LR_String = str(Low_Range)
  282. LT_String = str(Low_Target)
  283. Program = 'FALSE HIGH (BEARISH TERRITORY %s -%s)' % (LR_String, LT_String)
  284.  
  285.  
  286.  
  287.  
  288.  
  289. if range_ref_String == 'LOW TARGET' and tLow == True:
  290. if abs(MIV_Index) >= Avg_MIV_Spike * 3:
  291. Program = 'WALL OF CHINA OVERHEAD'
  292.  
  293. if abs(MIV_Index) >= Avg_MIV_Spike * 1.5 and LiqFlowPriceClone >= .39:
  294. Program = 'IMMEDIATE SELLOFF (HIGH CONFIDENCE)'
  295.  
  296. if LiqFlowPriceClone <= .038:
  297. if LiqFlowPrice >= 2.82:
  298. Program = 'EXTREMELY HIGH CONFIDENCE'
  299. if LiqFlowPrice >= 2.70 and LiqFlowPrice <= 2.82:
  300. Program = 'VOLATILITY COMING (HIGH CONFIDENCE <LONG TERM>)'
  301. if LiqFlowPrice <= 2.70:
  302. Program = 'POTENTIAL BOTTOM'
  303.  
  304. if LiqFlowPriceClone < .037 and LiqFlowPrice < 2.8:
  305. Program = 'BOTTOM REVERSAL TARGET [$',Low_Target,']'
  306.  
  307. if LiqFlowPrice >= 2.6 and MIV_Index >= 0:
  308. if MIV_Index < Avg_MIV_Spike and LiqFlowPriceClone <= .038:
  309. if LiqFlowPrice >= 2.7 and LiqFlowPrice < 2.81:
  310. Program = 'MMs IN CONTROL (BULLISH)'
  311. if LiqFlowPrice >= 2.81:
  312. Program = 'MMs IN CONTROL (EXTREMELY BEARISH)'
  313. if LiqFlowPrice <= 2.7 and LiqFlowPrice >= 2.6:
  314. Program = 'MMs IN CONTROL'
  315. if MIV_Index >= Avg_MIV_Spike and LiqFlowPrice <= 2.6:
  316. if LiqFlowPriceClone >= .04:
  317. Program = 'MMs IN CONTROL (BEARISH)'
  318.  
  319.  
  320.  
  321.  
  322. print(Date, military_time,' Current Liquidity:', '{:20,.2f}'.format(Liquidity), ' Liq Change:','{:20,.2f}'.format(Liq_change), ' Last Price:', Close_Price, range_ref_String+' Type: '+Program+' MIV [',MIV_Index,'%]',' LFP [',LiqFlowPrice,']',' LFP Clone [',LiqFlowPriceClone,']',' Avg MIV:',Avg_MIV_Spike)
  323. time.sleep(2.5)
  324. else:
  325. Range_Clause = False
  326. tHigh = False
  327. tLow = False
  328.  
  329. if abs(M_Price - HLCC) >= criteria2 and Range_Clause == False:
  330. Mark_The_Maker = True
  331. diff = abs(M_Price - Close_Price)
  332. if Mark_The_Maker == True:
  333.  
  334. if M_Price > Close_Price:
  335. MMLow = True
  336. MMHigh = False
  337.  
  338. elif M_Price < Close_Price:
  339. MMLow = False
  340. MMHigh = True
  341.  
  342.  
  343. if LiqFlowPriceClone <= .02 and LiqFlowPrice >= 5:
  344. Mark_Says = 'WHO NEEDS LIQUIDITY ANYWAY? (SELL)'
  345.  
  346.  
  347. if LiqFlowPriceClone >= .03 and LiqFlowPrice <= 3.4:
  348. Mark_Says = 'IMA TRAP THIS MF ~ Mark'
  349.  
  350. if LiqFlowPriceClone >= .025 and LiqFlowPrice <= 4:
  351. if MIV_Index < 0 and M_Price > Close_Price:
  352. if MMHigh == True:
  353. Mark_Says = 'IM FUCKIN SELLING ~ Mark'
  354. elif MMLow == True:
  355. Mark_Says = 'IM FUCKIN BUYING ~ Mark'
  356.  
  357.  
  358. print(Date, military_time,' Current Liquidity:', '{:20,.2f}'.format(Liquidity), ' Liq Change:','{:20,.2f}'.format(Liq_change), ' Last Price:', Close_Price, range_ref_String+' Type: '+Mark_Says+' MIV [',MIV_Index,'%]',' LFP [',LiqFlowPrice,']',' LFP Clone [',LiqFlowPriceClone,']',' Avg MIV:',Avg_MIV_Spike)
  359. time.sleep(1.5)
  360.  
  361. else:
  362. Mark_The_Maker = False
  363.  
  364.  
  365.  
  366. time.sleep(.0075)
  367.  
  368. if ref_Num % 2 != 0:
  369. Price1 = Close_Price
  370.  
  371. if ref_Num % 2 == 0:
  372. Price2 = Close_Price
  373.  
  374.  
  375. if ref_Num % 2 != 0 and ref_Num > 2:
  376. Last = Price2
  377. Chg = 100*round((Close_Price - Last) / Last, 4)
  378.  
  379. if ref_Num % 2 == 0 and ref_Num >= 2:
  380. Last = Price1
  381. Chg = 100*round((Close_Price - Last) / Last, 4)
  382.  
  383.  
  384. for i in SignalList[-2:-1]:
  385. if i == 'BUY':
  386. PL += Chg
  387. if i == 'SELL':
  388. PL += Chg*-1
  389. # if Bullish == True:
  390. # PL += Chg
  391. # if Bearish == True:
  392. # PL += Chg*-1
  393.  
  394. PLR = round(PL, 3)
  395. if PL > 0:
  396. PLString = Fore.CYAN+str(PLR)+'%'
  397. if PL < 0:
  398. PLString = Fore.RED+str(PLR)+'%'
  399.  
  400. if Range_Clause == False and Mark_The_Maker == False:
  401. '''if abs(Liq_change) >= 1000000:
  402. print(DateStr, TimeStr,' Current Liquidity:'+LiqStr,' Liq Change:'+LiqChangeStr,' Last Price:',Close_Price, SignalStr+Style.RESET_ALL+' ['+PLString+Style.RESET_ALL+']',' ',MIV_Index,' LFP: [',LiqFlowPrice,']',' LFPClone:[',LiqFlowPriceClone,']',' MIV: ',MIV_Index,' Avg MIV: ',Avg_MIV_Spike, '$Price: ',M_Price)
  403. else:'''
  404. print(DateStr, TimeStr,' Current Liquidity:'+LiqStr,' Liq Change:'+LiqChangeStr,' Last Price:',Close_Price, SignalStr+Style.RESET_ALL+' ['+PLString+Style.RESET_ALL+']',' ',ValuePrice,' Spread: [$',Spread,']', M_Price)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement