Advertisement
ImDerekD

Helpme.py

Mar 4th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.62 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. with open('/Users/King/data.csv', 'r') as csv_file:
  44. reader = csv.reader(csv_file)
  45. header = next(reader)
  46. for row in reader:
  47. ref_Num += 1
  48. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  49. Time = dTime[-14:]
  50. Open_Price = float(row[1])
  51. Close_Price = float(row[2])
  52. High_Price = float(row[3])
  53. Low_Price = float(row[4])
  54. Money_Flow = float(row[6])
  55. last = Close_Price
  56. Vol = row[5]
  57. f_Vol = float(Vol[:-1])
  58. m_Vol = str(Vol[-1:])
  59. if m_Vol == "K":
  60. f_Vol = f_Vol * 1000
  61. if m_Vol == "M":
  62. f_Vol = f_Vol * 1000000
  63. if m_Vol != "K" and m_Vol != "M":
  64. f_Vol = float(row[5])
  65. if f_Vol < 1:
  66. M_Price = HLCC
  67. else:
  68. M_Price = round(float(Money_Flow) / f_Vol, 2)
  69. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price) / 4
  70. Diff = round(HLCC - M_Price, 2)
  71. MMM = float(f_Vol * HLCC)
  72. Liq_change = float(Money_Flow - MMM)
  73. Liquidity += Liq_change
  74. Date = str(Time[:5])
  75. military_time = str(Time[-8:])
  76. criteria = abs(.0035 * HLCC)
  77. HLC3 = float(High_Price+ Low_Price + Close_Price + Close_Price + Close_Price) / 5
  78. Mid = High_Price - abs(High_Price - Low_Price)
  79. Paway = round(100*((M_Price - Close_Price) / Close_Price), 3)
  80.  
  81.  
  82. SumVol += f_Vol
  83. SumFlow += Money_Flow
  84. ValuePrice1 = round(SumFlow / SumVol, 2)
  85. MidValPrice = [ValuePrice1,Close_Price]
  86. ValuePrice = round(statistics.median(MidValPrice), 2)
  87.  
  88. Spread = round(abs(Close_Price - ValuePrice), 2)
  89. SpreadList.append(Spread)
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. if ref_Num >=2:
  99. prevPrice1 = Close_Price
  100.  
  101. if HLCC <= ValuePrice:
  102. Bearish = True
  103. Bullish = False
  104. Signal = 'SELL'
  105. SignalStr = Fore.RED+Signal+Style.RESET_ALL
  106. SignalList.append(Signal)
  107.  
  108.  
  109.  
  110.  
  111.  
  112. if HLCC >= ValuePrice:
  113. Bearish = False
  114. Bullish = True
  115. Signal = 'BUY'
  116. SignalStr = Fore.CYAN+Signal+Style.RESET_ALL
  117. SignalList.append(Signal)
  118.  
  119.  
  120.  
  121.  
  122.  
  123. if Liq_change > 0:
  124. liqchgstr = '{:20,.2f}'.format(Liq_change)+Style.RESET_ALL
  125. LiqChangeStr = Fore.CYAN+liqchgstr+Style.RESET_ALL
  126.  
  127. if Liq_change < 0:
  128. liqchgstr = '{:20,.2f}'.format(Liq_change)+Style.RESET_ALL
  129. LiqChangeStr = Fore.RED+liqchgstr+Style.RESET_ALL
  130.  
  131. DateStr = Fore.YELLOW+str(Date)+Style.RESET_ALL
  132. TimeStr = Fore.YELLOW+str(military_time)+Style.RESET_ALL
  133.  
  134. if Liquidity > 0:
  135. Liqstr = '{:20,.2f}'.format(Liquidity)
  136. LiqStr = Fore.CYAN+Liqstr+Style.RESET_ALL
  137.  
  138. if Liquidity < 0:
  139. Liqstr = '{:20,.2f}'.format(Liquidity)
  140. LiqStr = Fore.WHITE+Liqstr+Style.RESET_ALL
  141.  
  142.  
  143.  
  144.  
  145. if Money_Flow > 0:
  146. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
  147. prevPrice = Close_Price
  148. prevFlow = Money_Flow
  149. prevVol = f_Vol
  150. MIV_Index_String = str(MIV_Index)
  151. LiqFlowPrice = abs(Liq_change / Money_Flow)
  152.  
  153. if MIV_Index >= .25:
  154. MIV_Spike += MIV_Index
  155. MIV_Spike_Count += 1
  156. Avg_MIV_Spike = MIV_Spike / MIV_Spike_Count
  157.  
  158.  
  159. if abs(Liq_change) > 0:
  160. LiqFlowPrice = .01*round(Money_Flow / abs(Liq_change), 3)
  161. VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
  162. LiqFlowPriceClone = round(1000 * (abs(Liq_change) / Money_Flow), 4) * .01
  163. ##################################################################################################################################################################
  164. if abs(M_Price - HLCC) >= criteria:
  165. Range_Clause = True
  166. diff = abs(M_Price - Close_Price)
  167. if Range_Clause == True:
  168. found_Price = Close_Price
  169. range_ref_String = ''
  170. Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
  171. High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
  172. Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
  173. High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
  174. if M_Price >= High_Range:
  175. r_Price = M_Price
  176. t_Price = High_Target
  177. oppRange = Low_Range
  178. oppTarget = Low_Target
  179. tHigh = True
  180. found_Price = Close_Price
  181. tLow = False
  182. range_ref_String = 'HIGH TARGET'
  183. if MIV_Index > 0:
  184. range_ref_String = 'FALSE HIGH TARGET (CAPPER)'
  185. elif M_Price <= Low_Range:
  186. r_Price = M_Price
  187. t_Price = Low_Target
  188. oppRange = High_Range
  189. oppTarget = High_Target
  190. tLow = True
  191. tHigh = False
  192. found_Price = Close_Price
  193. range_ref_String = 'LOW TARGET'
  194.  
  195.  
  196. if range_ref_String == 'FALSE HIGH TARGET (CAPPER)':
  197. Program = 'HIGH CONFIDENCE'
  198.  
  199. if range_ref_String == 'LOW TARGET':
  200. if LiqFlowPriceClone >= .039:
  201. if LiqFlowPrice <= 2.65 and LiqFlowPrice >= 2.5:
  202. Program = 'MODERATE CONFIDENCE'
  203. if LiqFlowPrice <= 2.5 and LiqFlowPrice >= 2.45:
  204. Program = 'HIGH CONFIDENCE'
  205. if LiqFlowPrice <= 2.45:
  206. Program = 'VOLATILE LOW (HIGH CONFIDENCE)'
  207. else:
  208. Program = 'LOW CONFIDENCE / LIQUIDITY SEARCH'
  209.  
  210.  
  211.  
  212. if LiqFlowPriceClone >=.039 and range_ref_String == 'HIGH TARGET':
  213. if LiqFlowPrice < 2.6:
  214. Program = 'VOLATILE BULL TRAP (MODERATE CONFIDENCE)'
  215. if LiqFlowPrice > 2.6 and LiqFlowPrice < 2.8:
  216. Program = 'MODERATE CONFIDENCE'
  217.  
  218. if LiqFlowPrice >= 2.81 and range_ref_String == 'HIGH TARGET':
  219. Program = 'BIG BULLISH'
  220.  
  221.  
  222. if LiqFlowPriceClone <= .037:
  223. if range_ref_String == 'HIGH TARGET':
  224. if LiqFlowPrice >= 2.75:
  225. oppTargetStr = str(oppTarget)
  226. if abs(MIV_Index) >= Avg_MIV_Spike * 3:
  227. Program = '<<LONG TERM>> BULLISH (BTMFD)'+oppTargetStr
  228. if LiqFlowPrice <= 2.75 and LiqFlowPrice >= 2.75:
  229. Program = 'VERY HIGH CONFIDENCE'
  230.  
  231.  
  232.  
  233. if range_ref_String == 'LOW TARGET':
  234. if LiqFlowPrice >= 2.85:
  235. Program = 'EXTREMELY HIGH CONFIDENCE'
  236. if LiqFlowPrice >= 2.70 and LiqFlowPrice <= 2.85:
  237. Program = 'FALSE LOW RANGE (BUYERS IN CONTROL)'
  238. if LiqFlowPrice <= 2.70:
  239. Program = 'POTENTIAL BOTTOM'
  240.  
  241.  
  242.  
  243.  
  244. if LiqFlowPriceClone <= .038 and LiqFlowPrice >= 2.85:
  245. if tHigh == True:
  246. HighRangeStr = str(High_Range)
  247. Program = 'BULLS FULLA SHIT (SELL %s)' % HighRangeStr
  248.  
  249.  
  250. if tHigh == True and MIV_Index < 0:
  251. if abs(MIV_Index) >= Avg_MIV_Spike * 3:
  252. Program = 'EXTREMELY HIGH CONFIDENCE'
  253.  
  254. if LiqFlowPriceClone >= .042 and LiqFlowPrice <= 2.40:
  255. if range_ref_String == 'LOW TARGET':
  256. HR_String = str(High_Range)
  257. HT_String = str(High_Target)
  258. Program = 'FALSE LOW (BULLISH TERRITORY %s - %s)' % (HR_String, HT_String)
  259. if range_ref_String == 'HIGH TARGET':
  260. LR_String = str(Low_Range)
  261. LT_String = str(Low_Target)
  262. Program = 'FALSE HIGH (BEARISH TERRITORY %s -%s)' % (LR_String, LT_String)
  263.  
  264.  
  265.  
  266.  
  267.  
  268. if range_ref_String == 'LOW TARGET' and tLow == True:
  269. if abs(MIV_Index) >= Avg_MIV_Spike * 3:
  270. Program = 'WALL OF CHINA OVERHEAD'
  271.  
  272. if LiqFlowPrice < .037:
  273. Program = 'BOTTOM SIDE REVERSAL TARGET [$',Low_Target,']'
  274.  
  275. if LiqFlowPrice >= 2.6 and MIV_Index >= 0:
  276. if MIV_Index < Avg_MIV_Spike and LiqFlowPriceClone <= .038:
  277. if LiqFlowPrice >= 2.7 and LiqFlowPrice < 2.81:
  278. Program = 'MMs IN CONTROL (BULLISH)'
  279. if LiqFlowPrice >= 2.81:
  280. Program = 'MMs IN CONTROL (EXTREMELY BEARISH)'
  281. if LiqFlowPrice <= 2.7 and LiqFlowPrice >= 2.6:
  282. Program = 'MMs IN CONTROL'
  283. if MIV_Index >= Avg_MIV_Spike and LiqFlowPrice <= 2.6:
  284. if LiqFlowPriceClone >= .04:
  285. Program = 'MMs IN CONTROL (BEARISH)'
  286.  
  287.  
  288.  
  289.  
  290. 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,']')
  291. time.sleep(2.5)
  292. else:
  293. Range_Clause = False
  294.  
  295. time.sleep(.0075)
  296.  
  297. if ref_Num % 2 != 0:
  298. Price1 = Close_Price
  299.  
  300. if ref_Num % 2 == 0:
  301. Price2 = Close_Price
  302.  
  303.  
  304. if ref_Num % 2 != 0 and ref_Num > 2:
  305. Last = Price2
  306. Chg = 100*round((Close_Price - Last) / Last, 4)
  307.  
  308. if ref_Num % 2 == 0 and ref_Num >= 2:
  309. Last = Price1
  310. Chg = 100*round((Close_Price - Last) / Last, 4)
  311.  
  312.  
  313. for i in SignalList[-2:-1]:
  314. if i == 'BUY':
  315. PL += Chg
  316. if i == 'SELL':
  317. PL += Chg*-1
  318. # if Bullish == True:
  319. # PL += Chg
  320. # if Bearish == True:
  321. # PL += Chg*-1
  322.  
  323. PLR = round(PL, 3)
  324. if PL > 0:
  325. PLString = Fore.CYAN+str(PLR)+'%'
  326. if PL < 0:
  327. PLString = Fore.RED+str(PLR)+'%'
  328.  
  329. if Range_Clause == False:
  330. 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