Advertisement
ImDerekD

analyze.py

May 28th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.29 KB | None | 0 0
  1. #!/usr/bin/bash python
  2.  
  3. import csv
  4. import datetime
  5. from datetime import datetime
  6. import sys
  7. import time
  8. import hashlib
  9.  
  10. ########## NEED ##########
  11. ref_Num = int()
  12. Liquidity = float()
  13. gap_up = int()
  14. gap_down = int()
  15. Last = float()
  16. prevVol = float(1)
  17. prevFlow = float(1)
  18. prevPrice = float(1)
  19. Strength = float()
  20. MIV_Spike = float()
  21. MIV_Spike_Count = int()
  22. TradingAbove_Count = int()
  23. TradingBelow_Count = int()
  24. TradingAbove_Diff = float()
  25. TradingBelow_Diff = float()
  26. RegRangeCount = int()
  27. CurRegRangeCount = int()
  28. High_Range_Count = int()
  29. Low_Range_Count = int()
  30. test = []
  31. CashOpenHash = '00491302948265c47e651fcff99fd9fb'
  32. CashOpen = float()
  33. chg_Open = float()
  34. MM_Range_Count = int()
  35. range_ref_Str = str()
  36. gap_Ratio = float()
  37. range_ref_Str = ''
  38. cps = []
  39. datalist2 = []
  40. test2 = []
  41. Master = []
  42. test3 = []
  43. raw_liq_list = []
  44. ns_list = []
  45. pvs_list = []
  46. Liq_list = []
  47. PotentialMatches = []
  48. EODHashStr = '7263a069030520f9333799b957c155bf'
  49. PivotPrice = float()
  50. findDiff = float()
  51. TotalDiff = float()
  52. z_gain = float(1)
  53. chg_Close = float()
  54. curr_chg_Close = float()
  55. prev_Day_Close = float()
  56. DayCount = int()
  57. curr_Price = float()
  58. z_gain_count = int()
  59. sum_z_gain = float()
  60. avg_z_gain = float()
  61. y_price = float(1)
  62.  
  63. o_CHG = []
  64. c_CHG = []
  65. GR = []
  66. NS = []
  67. LIQ1 = []
  68. LIQ2 = []
  69. PVS_i = []
  70. PVS_c = []
  71. RR = []
  72. TATBR = []
  73. MMR = []
  74. PM1 = []
  75. PM2 = []
  76. MASTER = []
  77. lcount = int()
  78. chg_c_cps = float(1)
  79. PT_MIS = []
  80.  
  81. Has_Range = bool
  82. all_RR_Data = []
  83. RR_Data = []
  84. RR_Dict = {}
  85. Range_Info = []
  86. all_Range_Info = []
  87. M1_Range_Info = []
  88. p_diff = float()
  89. p_diff1 = float()
  90. MIV_Ratio = float()
  91. oppRange = float()
  92. oppTarget = float()
  93. Range_Targets = []
  94. oppRange_Targets = []
  95. lfpc_diff_spread = float()
  96. lfpc_cps_diff_spread = float()
  97. ta_tbr_cps = float()
  98. ta_tbr = float()
  99. avg_ND_gain = float()
  100. avg_3D_gain = float()
  101. count = int()
  102. sum_ND_gain = float()
  103. sum_3D_gain = float()
  104. ################# TA.PY
  105. full_ref = int()
  106. cp1_list = []
  107. chg_390 = float(1)
  108. chg_1170 = float(1)
  109. cp2_list = []
  110. neg_ND_return = int()
  111. ND_drawdown = float()
  112. pos_ND_return = int()
  113. ND_gain = float()
  114. neg_ND_return = int()
  115. neg_N3D_return = int()
  116. N3D_drawdown = float()
  117. pos_N3D_return = float()
  118. N3D_gain = int()
  119. Accuracy = float()
  120. ################## TA.PY
  121.  
  122.  
  123.  
  124. cps_file = '/Users/King/Desktop/iSpy.csv'
  125. curfile = '/Users/King/data.csv'
  126.  
  127. with open(curfile, 'r') as curfile:
  128. cur_reader = csv.reader(curfile)
  129. cur_header = next(cur_reader)
  130. for row in cur_reader:
  131. ref_Num += 1
  132. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  133. Time = dTime[-14:]
  134. Open_Price = float(row[1])
  135. Close_Price = float(row[2])
  136. High_Price = float(row[3])
  137. Low_Price = float(row[4])
  138. Money_Flow = float(row[6])
  139. last = Close_Price
  140. Vol = row[5]
  141. f_Vol = float(Vol[:-1])
  142. m_Vol = str(Vol[-1:])
  143. if m_Vol == "K":
  144. f_Vol = f_Vol * 1000
  145. if m_Vol == "M":
  146. f_Vol = f_Vol * 1000000
  147. if m_Vol != "K" and m_Vol != "M":
  148. f_Vol = float(row[5])
  149. if f_Vol < 1:
  150. M_Price = HLCC
  151. else:
  152. M_Price = round(float(Money_Flow) / f_Vol, 2)
  153. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price) / 4
  154. Diff = round(HLCC - M_Price, 2)
  155. MMM = float(f_Vol * HLCC)
  156. Liq_change = float(Money_Flow - MMM)
  157. Liquidity += Liq_change
  158. Date = str(Time[:5])
  159. military_time = str(Time[-8:])
  160. criteria1 = abs(.0035 * HLCC)
  161. criteria2 = abs(.003 * HLCC)
  162. findDiff = round(M_Price - Close_Price, 2)
  163. TotalDiff += findDiff
  164. PivotPrice = round(Close_Price + TotalDiff, 2)
  165. PivotSpread = round(PivotPrice - Close_Price, 2)
  166.  
  167. hashTime = hashlib.md5(str.encode(military_time))
  168.  
  169.  
  170. if ref_Num == 1:
  171. CashOpen = Open_Price
  172.  
  173. if ref_Num >= 1:
  174. CashOpen = CashOpen
  175.  
  176.  
  177. if ref_Num >= 2:
  178. prevPrice1 = Close_Price
  179.  
  180. if ref_Num % 2 != 0:
  181. Price1 = Close_Price
  182.  
  183. if ref_Num % 2 == 0:
  184. Price2 = Close_Price
  185.  
  186. if ref_Num % 2 != 0 and ref_Num > 2:
  187. Last = Price2
  188. Chg = 100 * round((Close_Price - Last) / Last, 4)
  189.  
  190. if ref_Num % 2 == 0 and ref_Num >= 2:
  191. Last = Price1
  192. Chg = 100 * round((Close_Price - Last) / Last, 4)
  193.  
  194. if Open_Price > Last and ref_Num > 1:
  195. gap_up += 1
  196.  
  197. if Open_Price < Last and ref_Num > 1:
  198. gap_down += 1
  199.  
  200. if M_Price > High_Price:
  201. TradingAbove_Count += 1
  202. TradingAbove_Diff += M_Price - Close_Price
  203.  
  204. if M_Price < Low_Price:
  205. TradingBelow_Count += 1
  206. TradingBelow_Diff += M_Price - Close_Price
  207.  
  208.  
  209. if Money_Flow > 0:
  210. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
  211. prevPrice = Close_Price
  212. prevFlow = Money_Flow
  213. prevVol = f_Vol
  214. MIV_Index_String = str(MIV_Index)
  215.  
  216. if MIV_Index >= .25:
  217. MIV_Spike += abs(MIV_Index)
  218. MIV_Spike_Count += 1
  219. Avg_MIV_Spike = round(MIV_Spike / MIV_Spike_Count, 3)
  220.  
  221. if abs(Liq_change) > 0:
  222. LFP = round(Money_Flow / abs(Liq_change) * .01, 3)
  223. VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
  224. LFPC = round(1000 * (abs(Liq_change) / Money_Flow) * .01, 4)
  225.  
  226. if Close_Price >= Open_Price and Liq_change > 0:
  227. Price_Tick = 1
  228. Liq_Tick = 1
  229.  
  230. elif Close_Price >= Open_Price and Liq_change < 0:
  231. Price_Tick = 0
  232. Liq_Tick = -1
  233.  
  234. elif Close_Price <= Open_Price and Liq_change > 0:
  235. Price_Tick = -1
  236. Liq_Tick = 0
  237.  
  238. elif Close_Price <= Open_Price and Liq_change < 0:
  239. Price_Tick = -1
  240. Liq_Tick = -1
  241.  
  242. Tick = Liq_Tick + Price_Tick
  243. Strength += Tick
  244. percent_Strength = round(Strength / ref_Num, 4)
  245. new_Strength = round(100 - (100 * abs(percent_Strength - -.3153) / .8794), 2)
  246. MIV_Str = str(MIV_Index)+'%'
  247.  
  248. Liquidity = round(Liquidity, 2)
  249. chg_Open = round(100*(Close_Price - CashOpen) / CashOpen, 2)
  250. curr_Price = Close_Price
  251.  
  252.  
  253.  
  254. if gap_up >= 1 and gap_down >= 1:
  255. gap_Ratio = round(gap_up / gap_down, 2)
  256.  
  257.  
  258. if abs(M_Price - HLCC) >= criteria1:
  259. RegRangeCount += 1
  260. p_diff = round(100*(M_Price - HLCC) / HLCC, 3)
  261. p_diff1 = round(100*(M_Price - Close_Price) / Close_Price, 3)
  262. Range = M_Price
  263. spread_from_target = round((M_Price - Close_Price) * 2, 2)
  264. Target = round(spread_from_target + Close_Price, 2)
  265. oppRange = round((-1 * spread_from_target) / 2 + Close_Price, 2)
  266. oppTarget = round((-1 * spread_from_target) + Close_Price, 2)
  267.  
  268. if M_Price > Close_Price:
  269. High_Range_Count += 1
  270. range_ref_Str = 'HIGH'
  271.  
  272. if M_Price < Close_Price:
  273. Low_Range_Count += 1
  274. range_ref_Str = 'LOW'
  275.  
  276.  
  277. ############
  278.  
  279. Range_Targets = [Range, Target]
  280. oppRange_Targets = [oppRange, oppTarget]
  281.  
  282. MF_Str = '{:8,.2f}'.format(Money_Flow)
  283. liqchgstr = '{:8,.2f}'.format(Liq_change)
  284. MIV_Ratio = round(MIV_Index / Avg_MIV_Spike, 3)
  285. p_diffstr = str(p_diff1)+'%'
  286. R_Type = [LFP, LFPC]
  287. MIV_Type = [MIV_Index, MIV_Ratio]
  288. MF_LQ = [MF_Str, liqchgstr]
  289. LFPC = round(LFPC * 10, 3)
  290. lfpc_cps_diff_spread = round(LFPC - abs(p_diff1), 3)
  291. RR_Data = [range_ref_Str, p_diffstr, p_diff, Date, military_time, Close_Price, Range, Target, MIV_Index, MIV_Ratio, LFP, LFPC, oppRange, oppTarget, Liq_change, Money_Flow, lfpc_cps_diff_spread]
  292. ##########
  293.  
  294.  
  295. if abs(M_Price - HLCC) < criteria1 and abs(M_Price - HLCC) >= criteria2:
  296. MM_Range_Count += 1
  297.  
  298.  
  299. if RegRangeCount >= 1:
  300.  
  301. Has_Range = True
  302. RR_Dict = {'Range Type:':RR_Data[0], 'Implied Move:':RR_Data[1], 'LFP:':R_Type[0], 'LFPC:':R_Type[1], 'MIV Index:':MIV_Type[0], 'MIV Ratio:':MIV_Type[1], 'MoneyFlow:':MF_LQ[0], 'Liq Change:':MF_LQ[1]}
  303. CurRegRangeCount = RegRangeCount
  304. curdata = [Date, military_time, Close_Price, new_Strength, chg_Open, Liquidity, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, range_ref_Str, MM_Range_Count, PivotSpread]
  305.  
  306. else:
  307. datalist = [ref_Num, new_Strength, chg_Open, Liquidity, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, Low_Range_Count, High_Range_Count, MM_Range_Count]
  308.  
  309. curdata = [Date, military_time, Close_Price, new_Strength, chg_Open, Liquidity, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, range_ref_Str, MM_Range_Count, PivotSpread]
  310.  
  311. test.append(curdata)
  312.  
  313.  
  314. def compare():
  315. PotentialMatch = []
  316.  
  317. tt_compare = str(curdata[1])
  318. tt_cps_hash = hashlib.md5(str.encode(tt_compare))
  319. tt_cps_str = tt_cps_hash.hexdigest()
  320. ns_cps = float(curdata[3])
  321. chg_o_cps = float(curdata[4])
  322. Liq_cps = float(curdata[5])
  323. gu_cps = float(curdata[6])
  324. gd_cps = float(curdata[7])
  325. gr_cps = float(curdata[8])
  326. tac_cps = float(curdata[9])
  327. tbc_cps = float(curdata[10])
  328. rrc_cps = float(curdata[11])
  329. rrs_cps = str(curdata[12])
  330. mmc_cps = int(curdata[13])
  331. pvs_cps = float(curdata[14])
  332.  
  333.  
  334. with open(cps_file, 'r') as cps_file:
  335. cps_reader = csv.reader(cps_file)
  336. cps_header = next(cps_reader)
  337. for row in cps_reader:
  338. full_ref += 1
  339. ref_Num += 1
  340. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  341. Time = dTime[-14:]
  342. Open_Price = float(row[1])
  343. Close_Price = float(row[2])
  344. High_Price = float(row[3])
  345. Low_Price = float(row[4])
  346. Money_Flow = float(row[6])
  347. last = Close_Price
  348. Vol = row[5]
  349. f_Vol = float(Vol[:-1])
  350. m_Vol = str(Vol[-1:])
  351. if m_Vol == "K":
  352. f_Vol = f_Vol * 1000
  353. if m_Vol == "M":
  354. f_Vol = f_Vol * 1000000
  355. if m_Vol != "K" and m_Vol != "M":
  356. f_Vol = float(row[5])
  357. if f_Vol < 1:
  358. M_Price = HLCC
  359. else:
  360. M_Price = round(float(Money_Flow) / f_Vol, 2)
  361. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price) / 4
  362. Diff = round(HLCC - M_Price, 2)
  363. MMM = float(f_Vol * HLCC)
  364. Liq_change = float(Money_Flow - MMM)
  365. Liquidity += Liq_change
  366. Date = str(Time[:5])
  367. military_time = str(Time[-8:])
  368. criteria1 = abs(.0035 * HLCC)
  369. criteria2 = abs(.003 * HLCC)
  370. findDiff = round(M_Price - Close_Price, 2)
  371. TotalDiff += findDiff
  372. PivotPrice = round(Close_Price + TotalDiff, 2)
  373. PivotSpread = round(PivotPrice - Close_Price, 2)
  374.  
  375. hashTime = hashlib.md5(str.encode(military_time))
  376. cp1_list.append(Close_Price)
  377. cp2_list.append(Close_Price)
  378.  
  379. if full_ref >= 390:
  380. chg_390 = round(100*(cp1_list[0] - cp1_list[-1]) / cp1_list[0], 2)
  381. cp1_list.pop(0)
  382.  
  383. if full_ref >= 1170:
  384. chg_1170 = round(100*(cp2_list[0] - cp2_list[-1]) / cp2_list[0], 2)
  385. cp2_list.pop(0)
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395. if hashTime.hexdigest() == CashOpenHash:
  396. CashOpen = Open_Price
  397.  
  398. if ref_Num >= 2:
  399. prevPrice1 = Close_Price
  400.  
  401. if ref_Num % 2 != 0:
  402. Price1 = Close_Price
  403.  
  404. if ref_Num % 2 == 0:
  405. Price2 = Close_Price
  406.  
  407. if ref_Num % 2 != 0 and ref_Num > 2:
  408. Last = Price2
  409. Chg = 100 * round((Close_Price - Last) / Last, 4)
  410.  
  411. if ref_Num % 2 == 0 and ref_Num >= 2:
  412. Last = Price1
  413. Chg = 100 * round((Close_Price - Last) / Last, 4)
  414.  
  415. if Open_Price > Last and ref_Num > 1:
  416. gap_up += 1
  417.  
  418. if Open_Price < Last and ref_Num > 1:
  419. gap_down += 1
  420.  
  421. if M_Price > High_Price:
  422. TradingAbove_Count += 1
  423. TradingAbove_Diff += M_Price - Close_Price
  424.  
  425. if M_Price < Low_Price:
  426. TradingBelow_Count += 1
  427. TradingBelow_Diff += M_Price - Close_Price
  428.  
  429. if Money_Flow > 0:
  430. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
  431. prevPrice = Close_Price
  432. prevFlow = Money_Flow
  433. prevVol = f_Vol
  434. MIV_Index_String = str(MIV_Index)
  435.  
  436. if MIV_Index >= .25:
  437. MIV_Spike += abs(MIV_Index)
  438. MIV_Spike_Count += 1
  439. Avg_MIV_Spike = round(MIV_Spike / MIV_Spike_Count, 3)
  440.  
  441. if abs(Liq_change) > 0:
  442. LFP = round(Money_Flow / abs(Liq_change) * .01, 3)
  443. VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
  444. LFPC = round(1000 * (abs(Liq_change) / Money_Flow) * .01, 4)
  445.  
  446. if Close_Price >= Open_Price and Liq_change > 0:
  447. Price_Tick = 1
  448. Liq_Tick = 1
  449.  
  450. elif Close_Price >= Open_Price and Liq_change < 0:
  451. Price_Tick = 0
  452. Liq_Tick = -1
  453.  
  454. elif Close_Price <= Open_Price and Liq_change > 0:
  455. Price_Tick = -1
  456. Liq_Tick = 0
  457.  
  458. elif Close_Price <= Open_Price and Liq_change < 0:
  459. Price_Tick = -1
  460. Liq_Tick = -1
  461.  
  462. Tick = Liq_Tick + Price_Tick
  463. Strength += Tick
  464. percent_Strength = round(Strength / ref_Num, 4)
  465. new_Strength = round(100 - (100 * abs(percent_Strength - -.3153) / .8794), 2)
  466. if MIV_Spike_Count >= 1:
  467. MIV_Ratio = round(MIV_Index / Avg_MIV_Spike, 3)
  468. Liq_change = int(Liq_change)
  469.  
  470. if abs(M_Price - HLCC) >= criteria1:
  471. RegRangeCount += 1
  472. if M_Price > Close_Price:
  473. High_Range_Count += 1
  474. range_ref_Str = 'HIGH'
  475.  
  476. if M_Price < Close_Price:
  477. Low_Range_Count += 1
  478. range_ref_Str = 'LOW'
  479.  
  480. LFPC = round(LFPC * 10, 3)
  481. p_diff1 = round(100*(M_Price - Close_Price) / Close_Price, 3)
  482. p_diff = round(100*(M_Price - HLCC) / HLCC, 3)
  483. lfpc_diff_spread = round(LFPC - abs(p_diff1), 3)
  484.  
  485. all_RR_Data = [Date, military_time, range_ref_Str, p_diff1, LFPC, LFP, MIV_Index, MIV_Ratio, Liq_change, Money_Flow, chg_390, chg_1170, lfpc_diff_spread]
  486.  
  487. if Has_Range == True and range_ref_Str == RR_Data[0]:
  488. if lfpc_cps_diff_spread * lfpc_diff_spread > 0:
  489. if (MIV_Ratio - 1) * (RR_Data[9] - 1) > 0:
  490. all_Range_Info.append(all_RR_Data)
  491.  
  492.  
  493.  
  494.  
  495. if abs(M_Price - HLCC) < criteria1 and abs(M_Price - HLCC) >= criteria2:
  496. MM_Range_Count += 1
  497.  
  498. Liquidity = round(Liquidity, 2)
  499. chg_Open = round(100 * (Close_Price - CashOpen) / Close_Price, 2)
  500. liqstr = '{:8,.2f}'.format(Liquidity)
  501.  
  502.  
  503. if gap_up >= 1 and gap_down >= 1:
  504. gap_Ratio = round(gap_up / gap_down, 2)
  505.  
  506. if RegRangeCount >= 1 or MM_Range_Count >= 1:
  507. datalist2 = [ref_Num, new_Strength, chg_Close, chg_Open, Liquidity, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, Low_Range_Count, High_Range_Count, MM_Range_Count, PivotSpread, z_gain, chg_390, chg_1170]
  508.  
  509. cps = [Date, military_time, Close_Price, new_Strength, chg_Close, chg_Open, liqstr, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, range_ref_Str, MM_Range_Count, PivotSpread, z_gain, chg_390, chg_1170]
  510. RR.append(cps)
  511. else:
  512. datalist2 = [ref_Num, new_Strength, chg_Close, chg_Open, Liquidity, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, Low_Range_Count, High_Range_Count, MM_Range_Count, PivotSpread, z_gain, chg_390, chg_1170]
  513.  
  514. cps = [Date, military_time, Close_Price, new_Strength, chg_Close, chg_Open, liqstr, gap_up, gap_down, gap_Ratio, TradingAbove_Count, TradingBelow_Count, RegRangeCount, range_ref_Str, MM_Range_Count, PivotSpread, z_gain, chg_390, chg_1170]
  515.  
  516. ####################################### FINDING THE CLOSE OF 390 CANDLES PREVIOUS ############
  517.  
  518.  
  519. #################################### IF COMPARE FILE == CURRENT FILE TIME ######################
  520. if hashTime.hexdigest() == tt_cps_str:
  521. x_price = Close_Price
  522. ns_diff = round(abs(ns_cps - new_Strength), 2)
  523. co_diff = round(abs(chg_o_cps - chg_Open), 2)
  524. pvs_diff = round(abs(pvs_cps - PivotSpread), 2)
  525. gr_diff = round(abs(gr_cps - gap_Ratio), 2)
  526. gr_above_below = round((gr_cps - 1) * (gap_Ratio - 1), 2)
  527. LIQ_pct_spread = (Liq_cps + Liquidity)*.3
  528. LIQ_abs_diff = abs(Liq_cps - Liquidity)
  529. if tac_cps > 0 or tbc_cps > 0:
  530. ta_tbr_cps = tac_cps - tbc_cps
  531. if TradingAbove_Count > 0 or TradingBelow_Diff > 0:
  532. ta_tbr = TradingAbove_Count - TradingBelow_Count
  533.  
  534. if (ta_tbr_cps - 1) * (ta_tbr - 1) > 0:
  535. if abs(ta_tbr_cps) > 0 and abs(ta_tbr) > 0:
  536. TATBR.append(cps)
  537. sum_ND_gain += chg_390
  538. sum_3D_gain += chg_1170
  539. count += 1
  540.  
  541. if chg_1170 < 0:
  542. neg_N3D_return += 1
  543.  
  544. if chg_1170 > 0:
  545. pos_N3D_return += 1
  546.  
  547. if chg_390 < 0:
  548. neg_ND_return += 1
  549.  
  550. if chg_390 > 0:
  551. pos_ND_return += 1
  552.  
  553.  
  554.  
  555.  
  556.  
  557. if gr_above_below > 0:
  558. GR.append(cps)
  559.  
  560. if chg_o_cps * chg_Open > 0:
  561.  
  562. o_CHG.append(cps)
  563. if Liq_cps * Liquidity >= 0 and ns_diff < 5:
  564. sum_z_gain += z_gain
  565. z_gain_count += 1
  566.  
  567.  
  568.  
  569. if chg_c_cps * chg_Close >= 0:
  570. c_CHG.append(cps)
  571.  
  572.  
  573. if pvs_cps * PivotSpread > 0 and pvs_diff < .5 * abs(pvs_cps + PivotSpread):
  574. PVS_i.append(cps)
  575. if pvs_diff < .3 * abs(pvs_cps + PivotSpread):
  576. PVS_c.append(cps)
  577. sum_ND_gain += chg_390
  578. sum_3D_gain += chg_1170
  579. count += 1
  580. if chg_1170 < 0:
  581. neg_N3D_return += 1
  582.  
  583. if chg_1170 > 0:
  584. pos_N3D_return += 1
  585.  
  586. if chg_390 < 0:
  587. neg_ND_return += 1
  588.  
  589. if chg_390 > 0:
  590. pos_ND_return += 1
  591.  
  592.  
  593. if Liq_cps * Liquidity > 0:
  594. LIQ1.append(cps)
  595. if LIQ_abs_diff <= LIQ_pct_spread:
  596. LIQ2.append(cps)
  597.  
  598. if ns_diff < 7:
  599. NS.append(cps)
  600.  
  601.  
  602. if MM_Range_Count >= 1:
  603. MMR.append(cps)
  604.  
  605. if RegRangeCount >= 1:
  606. RR.append(cps)
  607.  
  608.  
  609.  
  610.  
  611. if hashTime.hexdigest() == EODHashStr:
  612. if DayCount >= 1:
  613. chg_Close = round(100*(Close_Price - prev_Day_Close) / prev_Day_Close, 2)
  614. prev_Day_Close = Close_Price
  615. else:
  616. DayCount += 1
  617. prev_Day_Close = Close_Price
  618.  
  619. z_gain = round(100*(y_price - x_price) / y_price, 2)
  620. y_price = Close_Price
  621.  
  622.  
  623.  
  624.  
  625. ############################### RESETING ALL STATISTICS ###################
  626. Tick = Tick * 0
  627. Strength = Strength * 0
  628. new_Strength = new_Strength * 0
  629. ref_Num = 0
  630. Liquidity = Liquidity * 0
  631. if tt_cps_str == '15:59:00':
  632. prevClose = prevClose
  633. prevClose = Close_Price
  634. RegRangeCount = RegRangeCount * 0
  635. TradingBelow_Count = TradingBelow_Count * 0
  636. TradingAbove_Count = TradingAbove_Count * 0
  637. gap_Ratio = gap_Ratio * 0
  638. gap_down = gap_down * 0
  639. gap_up = gap_up * 0
  640. High_Range_Count = High_Range_Count * 0
  641. Low_Range_Count = Low_Range_Count * 0
  642. MM_Range_Count = MM_Range_Count * 0
  643. range_ref_Str = str()
  644. findDiff = findDiff * 0
  645. TotalDiff = TotalDiff * 0
  646. PivotPrice = PivotPrice * 0
  647. PivotSpread = PivotSpread * 0
  648.  
  649. curr_chg_Close = round(100*(curr_Price - prev_Day_Close) / curr_Price, 2)
  650. curdata.insert(4, curr_chg_Close)
  651. chg_c_cps = float(curdata[4])
  652. chg_o_cps = float(curdata[5])
  653.  
  654.  
  655.  
  656.  
  657.  
  658. print('\n\n')
  659. help_comment = """BP%: Bullish percentile. % of upticks (+ liquidity & + price changes) / total count of upticks/neutral/downticks in given time frame.
  660. @bid: # of times gapping UP after each minute candle. These are typically market orders filled on the ASK, but are found during times when orders are large enough to take out BID orders
  661. @ask: # of times gapping DOWN after each minute candle. These are typically market orders filled on the BID, but are found during times when orders are large enough to take out ASK orders
  662. Gap|R: # of gap UPS / # of gap DOWNS. Higher ratios tend to become overly bearish after a typical show of extreme sentiment on the bullish side.
  663. TA: # of times trading ABOVE. This is where a $ price (distribution price for algos) is ABOVE the high price of a minute candle in a given minute
  664. TB: # of times trading BELOW. This is where a $ price (accumulation price for algos) is BELOW the low price of a minute candle in a given minute
  665. #R/Type: # of REGULAR (.35% or more) ranges seen in a given day; represented w/ high or low $ prices (a "High/Low Range")
  666. PivotSpread: The $ difference in ATR terms between current day's pivot price from where price is currently trading. Typically divergences > $1.00 are best for entries of a majority of tickers/trades
  667. %byEOD: % chg using current days closing price as % change from day's cash open price"""
  668. print(help_comment)
  669. print('\n')
  670. indent = ' '
  671. print(indent + ' Date Time Price BP% %ChgClose/Open Liquidity @bid/@ask Gap|R TA TB #R/Type PivotSpread')
  672. print('Current: ', curdata)
  673. if CurRegRangeCount >= 1:
  674. Range_Info.append(RR_Data)
  675.  
  676. for i in Range_Info:
  677. cps_Range_ref = str(i[0])
  678. cps_IV = float(i[2])
  679. cps_MIV = float(i[8])
  680. cps_MIV_Ratio = float(i[9])
  681. cps_LFP = float(i[10])
  682. cps_LFPC = float(i[11])
  683. cps_MF = float(i[14])
  684.  
  685.  
  686. for k,v in dict.items(RR_Dict):
  687. print(k,v)
  688.  
  689.  
  690. print('\n')
  691. print('\n POSSIBLE SCENARIOS (MISCELLANIOUS) \n')
  692. desc = ' Date Time Price BP% %ChgClose/Open Liquidity @bid @ask Gap|R TA TB #Ranges/Type #MMRanges PivotSpread %EOD %ND %3D'
  693. print(desc)
  694.  
  695.  
  696. if CurRegRangeCount >= 1:
  697. print('RANGES OF TYPE')
  698. print(Range_Info)
  699. print('\n')
  700. print(' Date Time Type %Move LFPC LFP MIV MIV|R Liq_Change Money Flow %Chg_ND | %3D LFPC Spread')
  701. for i in all_Range_Info:
  702. print(i)
  703. lcount += 1
  704.  
  705. print('Total items: %s' % lcount)
  706. else:
  707.  
  708. print('\nLIQ, % CHG CLOSE MATCHES\n')
  709. print(desc)
  710. for i in c_CHG:
  711. if i in LIQ1 and i in o_CHG:
  712. if i in GR and i in NS:
  713. print(i)
  714. PM2.append(i)
  715. # print(i)
  716.  
  717.  
  718. # print('RELIABLE SIMILARITIES')
  719. for i in c_CHG:
  720. if i in LIQ1 and i in LIQ2:
  721. if i not in PM2:
  722. PM2.append(i)
  723.  
  724.  
  725. # print('CREDIBLE SIMILARITIES')
  726. for i in LIQ1:
  727. if i in NS and i in GR:
  728.  
  729. PM1.append(i)
  730. if i in LIQ2:
  731. print(i)
  732. # print('CERTIFIED MATCHES\n')
  733. for i in GR:
  734. if i in LIQ2 and i not in PM1:
  735. PM1.append(i)
  736. print(i)
  737.  
  738. print('\n TATBR')
  739. print(desc)
  740. for i in TATBR:
  741. if i in PVS_c:
  742. print(i)
  743.  
  744. for i in PM1:
  745. if i in PM2:
  746. MASTER.append(i)
  747. else:
  748. pass
  749.  
  750. for i in MASTER:
  751. print(i)
  752. if i not in PVS_i or i in PVS_c:
  753. PT_MIS.append(i)
  754.  
  755.  
  756. print('\n')
  757. print('HIGH POTENTIAL SCENARIOS')
  758. desc1 = ' Date Time Price BP% %ChgClose|Open Liquidity @bid @ask Gap|R %EOD %ND %3D'
  759. print(desc1)
  760. for i in PT_MIS:
  761. if i not in RR:
  762. sum_3D_gain += i[-1]
  763. sum_ND_gain += i[-1]
  764. x = i[:-9]
  765. y = i[-3:]
  766. z = [x, y]
  767. dict = {'':x, '% Chgs':y}
  768.  
  769. print(z)
  770.  
  771. avg_ND_gain = round(sum_ND_gain / count, 2)
  772. avg_3D_gain = round(sum_3D_gain / count, 2)
  773.  
  774. if avg_3D_gain < 0:
  775. Accuracy = round(100*(neg_N3D_return / count), 3)
  776.  
  777. if avg_3D_gain > 0:
  778. Accuracy = round(100*(pos_N3D_return / count), 3)
  779.  
  780. print('\n')
  781. print('AVG ND % GAIN:', avg_ND_gain)
  782. print('AVG 3D % GAIN:', avg_3D_gain)
  783. print('TREND ACCURACY:', Accuracy)
  784.  
  785. avg_z_gain = round(sum_z_gain / z_gain_count, 2)
  786. print('AVG Z GAIN:', avg_z_gain,'%')
  787.  
  788. print('\n')
  789.  
  790.  
  791.  
  792. ### [range_ref_Str, p_diffstr, p_diff, Date, military_time, Close_Price, Range, Target, MIV_Index, MIV_Ratio, LFP, LFPC, oppRange, oppTarget, Money_Flow]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement