Advertisement
ImDerekD

Scratch014.py UPDATED Apr 6

Apr 6th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.40 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 hashlib
  16. import statistics
  17.  
  18. MIV_Spike_List = []
  19. MIV_Spike_Count = int()
  20. MIV_Spike = float()
  21. Avg_MIV_Spike = float()
  22.  
  23.  
  24.  
  25. with open('/Users/King/data.csv', 'r') as csv_file:
  26. csv_reader = csv.reader(csv_file)
  27. header = next(csv_reader)
  28.  
  29.  
  30. ref = [] # Start off w/ empty list
  31. ref_Num = int(0) # First to go in list = ref # (390 cells in 1 day)(using ref+=1 for each row)
  32. data = [] # Not sure but I could rearrange for liquidity?
  33. Liquidity = float()
  34. found = int(0)
  35. Range = []
  36. Target = []
  37. filled = bool
  38. filled_Price = float()
  39. Range_List = {}
  40. Low_Range_Found = {}
  41. High_Range_Found = {}
  42. ht_filled = bool
  43. hr_filled = bool
  44. lr_filled = bool
  45. lt_filled = bool
  46. lows_found = int()
  47. highs_found = int()
  48. Tick = int()
  49. Range_Found = {}
  50. range_ref_String = ('')
  51. dTime = []
  52. printRanges = str()
  53. range_identifier_low = 'Low'
  54. range_identifier_high = 'High'
  55. range_identifier_all = 'All'
  56. All_Range_References = []
  57. All_Referenced_Prices = []
  58. menu_ans = input('What would you like to do? \n [1] Print Liquidity Data | [2] See previous ranges | [3] RangeTargets File | [4] No-Stop-Data-Add [5] Current Info\n')
  59. if menu_ans == '1':
  60. Liquidity_Data = input('Would you like to print liquidity data? [y/n]: ')
  61. if menu_ans == '2':
  62. printRanges = input('Which ranges would you like to see?: [High/Low/All]\n')
  63. if menu_ans == '4':
  64. NoStop = True
  65. CandleDur = input('Candle Duration: ')
  66. else:
  67. NoStop = False
  68. if menu_ans == '3':
  69. option3 = True
  70. range_identifier = ''
  71. new_range = bool
  72. t = bool
  73. tLow = bool
  74. tHigh = bool
  75. Target = float()
  76. Range_Dict = {}
  77. TickString = str()
  78. Tick_String = ''
  79. Strength = int()
  80. StartTraceback = {}
  81. day_Count = int()
  82. tList = []
  83. last = float()
  84. LT = float()
  85. HT = float()
  86. last = float()
  87. ATR = float()
  88. OC_ATR = float()
  89. Avg_ATR = float()
  90. TrendStrength = ''
  91. Previous = []
  92. allfoundallfilled = {}
  93. lowfilled = float()
  94. highfilled = float()
  95. rangefilled = bool
  96. low_Ranges_Filled = int()
  97. high_Ranges_Filled = int()
  98. high_Targets_Filled = int()
  99. low_Targets_Filled = int()
  100. prevVol = float(1)
  101. prevFlow = float(1)
  102. prevIndexValue = float(1)
  103. prevPrice = float(1)
  104. Status = str('')
  105. RangeTarget = float()
  106. rFound = bool
  107. count = int(0)
  108. PCT_Range_Str = ''
  109.  
  110. sum_OC_Range = float()
  111. sum_HL_Range = float()
  112. sum_OHLC_Range = float()
  113. WarningString = ''
  114. sum_Liq = float()
  115. avg_Liq_change = float()
  116. HighRangeFlow = float()
  117. LowRangeFlow = float()
  118. LiqFlowPrice = float()
  119. LiqFlowPriceClone = float()
  120. EntryStr = str()
  121.  
  122.  
  123. liqList = []
  124. PULQ = bool
  125.  
  126. for row in csv_reader:
  127. range_ref_String = ''
  128. LRS = '$'
  129. LRT = '$'
  130. HRS = '$'
  131. HRT = '$'
  132. found_Price_String = '$'
  133. end_String = 'Price while found: $'
  134. # row = [Time, Open, Close, High, Low, realVol, Money_Flow]
  135. ref_Num += 1 # Starting at 0
  136. dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
  137. Time = dTime[-14:]
  138. Open_Price = float(row[1]) # Price Data Dictionary
  139. Close_Price = float(row[2]) # Price Data Dictionary
  140. High_Price = float(row[3]) # Price Data Dictionary
  141. Low_Price = float(row[4]) # Price Data Dictionary
  142. Money_Flow = float(row[6]) # Price Data Dictionary
  143. Vol = row[5] # Price Data Dictionary
  144. f_Vol = float(Vol[:-1]) # Price Data Dictionary
  145. m_Vol = str(Vol[-1:]) # Price Data Dictionary
  146. if m_Vol == "K": # Price Data Dictionary
  147. f_Vol = f_Vol * 1000 # Price Data Dictionary
  148. if m_Vol == "M": # Price Data Dictionary
  149. f_Vol = f_Vol * 1000000
  150. if m_Vol != "K" and m_Vol != "M":
  151. f_Vol = float(row[5]) # Price Data Dictionary
  152. if f_Vol < 1:
  153. M_Price = HLCC
  154. else:
  155. M_Price = round(float(Money_Flow) / f_Vol, 2)
  156. HLCC = float(High_Price + Low_Price + Close_Price + Close_Price)/4 # Price Data Dictionary & RangeReference Dictionary # Price Data Dictionary & RangeReference Dictionary
  157. Diff = round(HLCC - M_Price, 2) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  158. MMM = float(f_Vol * HLCC) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  159. Liq_change = float(Money_Flow - MMM) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  160. Liquidity += Liq_change # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
  161. Date = str(Time[:5]) # Important
  162. military_time = str(Time[-8:])
  163. criteria = abs(.003*HLCC)
  164. hashTime = hashlib.md5(str.encode(military_time))
  165. Liq_Tick = int()
  166. Price_Tick = int()
  167. tREF = int()
  168. rFound = False
  169.  
  170. OC_Range = abs(Close_Price - Open_Price)
  171. HL_Range = abs(High_Price - Low_Price)
  172. sum_OC_Range += OC_Range
  173. sum_HL_Range += HL_Range
  174.  
  175. sum_Liq += abs(Liq_change)
  176. liqList.append(sum_Liq)
  177. avg_HL_Range = float()
  178. avg_OC_Range = float()
  179. abs_Liq = abs(Liq_change)
  180. prevLiq = float()
  181.  
  182.  
  183.  
  184. percent_Strength = Strength / ref_Num
  185. allData = [ref_Num,Date, military_time, High_Price,Low_Price,Close_Price, HLCC, M_Price, f_Vol, Money_Flow,MMM, Liquidity,Liq_change]
  186. Data_Dict = {'REF#':[ref_Num],'Date':[Date],'Time':[military_time], 'Close_Price':[Close_Price], 'M_Price':[M_Price], 'Volume':[f_Vol]}
  187. '''USING THIS DATA
  188. [0]REFERENCE NUMBER
  189. [1]DATE
  190. [2]MILITARY_TIME
  191. [3]HIGH_PRICE
  192. [4]LOW_PRICE
  193. [5]CLOSE_PRICE
  194. [6]HLCC
  195. [7]M_Price
  196. [8]F_VOL
  197. [9]MONEY_FLOW
  198. [10]MARKETMAKERMOVE 'MMM'
  199. [11]LIQUIDITY
  200. [12]LIQ_CHANGE
  201. '''
  202.  
  203.  
  204.  
  205. if abs(allData[7]-allData[6]) >= criteria:
  206. diff = abs(M_Price - Close_Price)
  207. Range_Clause = True
  208. range_identifier_all = 'All'
  209. else:
  210. Range_Clause = False
  211. if Range_Clause == True:
  212. r_price = M_Price
  213. found_Price = HLCC
  214. Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
  215. High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
  216. Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
  217. High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
  218. RT_Reference1 = [Low_Range, High_Range, Low_Target, High_Target]
  219. LRS = '$' + str(Low_Range)
  220. LRT = '$' + str(Low_Target)
  221. HRS = '$' + str(High_Range)
  222. HRT = '$' + str(High_Target)
  223. found_Price_String = '$' + str(found_Price)
  224. RT_Reference = [LRS, LRT, HRS, HRT]
  225. lows = [LRS, LRT]
  226. highs = [HRS, HRT]
  227. range_ref_String = range_ref_String
  228. target_String = range_ref_String + ': $'
  229. end_String = 'Price while found: $' + str(Close_Price)
  230. Target_String = '$' + str(Target)
  231.  
  232. LiqFlowPrice = .01*round(Money_Flow / abs(Liq_change), 3)
  233. VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
  234. LiqFlowPriceClone = round(1000 * (abs(Liq_change) / Money_Flow), 4) * .01
  235.  
  236.  
  237. if M_Price >= High_Range:
  238. found += 1
  239. range_ref_String = "HIGH TARGET"
  240. tHigh = True
  241. RangeTarget = High_Target
  242. Target = M_Price
  243. range_identifier = 'High'
  244. found_Price = HLCC
  245. range_identifier_all = 'All'
  246. thList = ['HIGH TARGET', High_Target, highfilled]
  247. filled = False
  248. ht_filled = False
  249. hr_filled = False
  250. highs_found += 1
  251. rFound = True
  252. HighRangeFlow += Money_Flow
  253. elif M_Price<= Low_Range:
  254. found += 1
  255. range_ref_String = "LOW TARGET"
  256. tLow = True
  257. RangeTarget = Low_Target
  258. Target = M_Price
  259. range_identifier = 'Low'
  260. range_identifier_all = 'All'
  261. found_Price = HLCC
  262. tlList = ['LOW TARGET', Low_Target, lowfilled]
  263. filled = False
  264. lt_filled = False
  265. lr_filled = False
  266. lows_found += 1
  267. rFound = True
  268. LowRangeFlow += Money_Flow
  269.  
  270. if lows_found > 0:
  271. AvgLowRangeFlow = LowRangeFlow / lows_found
  272. if highs_found > 0:
  273. AvgHighRangeFlow = HighRangeFlow / highs_found
  274.  
  275.  
  276. if printRanges == range_identifier and range_identifier == range_identifier_low:
  277. Low_Range_Reference = [Date, military_time, range_ref_String, Target_String, end_String]
  278. Low_Range_Found = {'\nData Found':Low_Range_Reference, 'Watch for: $':lows, 'Potential Resistance: ':highs}
  279. Low_Range = Low_Range_Found
  280. for k, v in dict.items(Low_Range):
  281. print(Fore.RED, k, v)
  282.  
  283. if printRanges == range_identifier and range_identifier == range_identifier_high:
  284. High_Range_Reference = [Date, military_time, range_ref_String, end_String]
  285. High_Range_Found = {'\nData Found': High_Range_Reference, 'Watch for: $':highs, 'Potential Support: ':lows}
  286. High_Range = High_Range_Found
  287. for k, v in dict.items(High_Range):
  288. print(Fore.CYAN, k, v)
  289.  
  290. elif printRanges == range_identifier_all:
  291. if range_ref_String == 'LOW TARGET' or range_ref_String == 'HIGH TARGET':
  292. money_string = '$'
  293. Target_String = '$' + str(Target)
  294. Close_Price_String = money_string+str(Close_Price)
  295. Range_Reference = [Date, military_time, Close_Price_String, range_ref_String, Target_String]
  296. Low_Ranges = [LRS, LRT]
  297. High_Ranges = [HRS, HRT]
  298. Range_Found = {'<-- Reference':Range_Reference, 'Low Ranges':Low_Ranges, 'High Ranges':High_Ranges, 'REF#':ref_Num}
  299. Range_List[ref_Num] = Range_Found
  300. text = colored(str(found)+' '+str(Range_Found), 'cyan', 'on_grey', attrs=['reverse'])
  301. cprint(text)
  302.  
  303.  
  304. '''if Range_Clause == True:
  305. if range_ref_String == "HIGH TARGET" and Money_Flow < 300000000:
  306. print("MARKET MAKER HIGH TARGET")
  307. if range_ref_String == "LOW TARGET" and Money_Flow > 300000000:
  308. print("MARKET MAKER LOW TARGET")'''
  309.  
  310. else:
  311. Range_Clause = False
  312. tHigh = False
  313. tLow = False
  314. rFound = False
  315.  
  316.  
  317.  
  318.  
  319. if menu_ans == '1' and Liquidity_Data == 'y':
  320.  
  321.  
  322. avg_HL_Range = sum_HL_Range / ref_Num
  323. avg_OC_Range = sum_OC_Range / ref_Num
  324. avg_Liq_change = sum_Liq / ref_Num
  325.  
  326.  
  327.  
  328.  
  329. if Money_Flow > 0:
  330. MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
  331. runningValueIndex = round(MIV_Index + prevIndexValue, 3)
  332. prevPrice = Close_Price
  333. prevFlow = Money_Flow
  334. prevVol = f_Vol
  335. prevIndexValue = MIV_Index
  336. MIV_Index_String = str(MIV_Index)
  337.  
  338. liq_flowPrice = abs(Liq_change / Money_Flow)*1000000
  339. runningValueIndex_String = str(runningValueIndex)
  340. MIV_Index_String = str(round(MIV_Index, 2))
  341.  
  342.  
  343.  
  344.  
  345. if abs(MIV_Index) >= .25 and ref_Num > 1:
  346. MIV_Spike += abs(MIV_Index)
  347. MIV_Spike_Count += 1
  348. MIV_Spike_List.append(abs(MIV_Index))
  349. Avg_MIV_Spike = round(MIV_Spike / MIV_Spike_Count, 3)
  350. if abs(MIV_Index) >= .25 and ref_Num > 1:
  351. Avg_MIV_Spike_String = str(Avg_MIV_Spike)
  352. if MIV_Index > 0:
  353. MIV_Index_String = str(round(MIV_Index, 2))
  354. print(Fore.BLACK+Back.RED+Style.BRIGHT+'MIV_Index: '+Style.RESET_ALL+Fore.BLACK+Back.RED+'[+'+MIV_Index_String+'%]'+Style.RESET_ALL+Fore.BLACK+Back.RED+Style.BRIGHT+'Avg Spike: '+Style.RESET_ALL+Fore.BLACK+Back.RED+'[+',Avg_MIV_Spike,'%]'+Style.RESET_ALL+Fore.WHITE+'Volume:'+'{:,.2f}'.format(f_Vol)+Style.RESET_ALL)
  355.  
  356. elif MIV_Index < 0:
  357. MIV_Index_String = str(round(MIV_Index, 2))
  358. print(Fore.BLACK+Back.CYAN+Style.BRIGHT+'MIV_Index: '+Style.RESET_ALL+Fore.BLACK+Back.CYAN+'['+MIV_Index_String+'%]'+Style.RESET_ALL+Fore.BLACK+Back.CYAN+Style.BRIGHT+'Avg Spike: '+Style.RESET_ALL+Fore.BLACK+Back.CYAN+'[',Avg_MIV_Spike,'%]'+Style.RESET_ALL+Fore.WHITE+'Volume:'+'{:,.2f}'.format(f_Vol)+Style.RESET_ALL)
  359.  
  360.  
  361. if Close_Price >= Open_Price and Liq_change > 0:
  362. Price_Tick = 1
  363. Liq_Tick = 1
  364. PULQ = False
  365. elif Close_Price >= Open_Price and Liq_change < 0:
  366. Price_Tick = 0
  367. Liq_Tick = -1
  368. PULQ = True
  369. elif Close_Price <= Open_Price and Liq_change > 0:
  370. Price_Tick = -1
  371. Liq_Tick = 0
  372. PULQ = False
  373. elif Close_Price <= Open_Price and Liq_change < 0:
  374. Price_Tick = -1
  375. Liq_Tick = -1
  376. PULQ = False
  377. Tick = Liq_Tick + Price_Tick
  378. Strength += Tick
  379. percent_Strength = round(Strength / ref_Num, 4)
  380. new_Strength = round(100-(100*abs(percent_Strength- -.3153) / .8794), 2)
  381. SS = str(new_Strength)
  382. abs_Liq = abs(Liq_change)
  383.  
  384.  
  385. if OC_Range >= avg_HL_Range*.9:
  386. WarningString = '[xxx]'
  387.  
  388. if PULQ == True and OC_Range < avg_OC_Range *.3:
  389. if abs(Liq_change) < 500 and Liq_change < 0:
  390. if abs(Liq_change) < avg_Liq_change * .05:
  391. WarningString = '[*]'
  392. else:
  393. WarningString = ''
  394. else:
  395. WarningString = ''
  396.  
  397.  
  398. if Tick == 2:
  399. if abs_Liq >= avg_Liq_change*1.5:
  400. if Liquidity > 0:
  401. Tick_String = Fore.GREEN+Style.BRIGHT+'AGGRESSIVE BUYERS'+Style.RESET_ALL+WarningString+' '
  402.  
  403. else:
  404. Tick_String = Fore.GREEN+Back.RED+Style.BRIGHT+'BEARISH BUYING'+Style.RESET_ALL+WarningString+' '
  405.  
  406. elif abs_Liq >= avg_Liq_change:
  407. Tick_String = Fore.GREEN+Style.BRIGHT+'STRONG BUYERS'+Style.RESET_ALL+WarningString+' '
  408.  
  409. else:
  410. Tick_String = Fore.BLUE+Back.GREEN+'UPTICK'+Style.RESET_ALL+WarningString+' '
  411.  
  412. if Tick == -1 and Price_Tick == 0:
  413. if Liq_Tick == -1:
  414. if abs(Liq_change) < 300 and OC_Range < avg_OC_Range *.3:
  415. if WarningString == '':
  416. Tick_String = Fore.BLUE+Style.BRIGHT+Back.YELLOW+'<BUY ENTRY>'+Style.RESET_ALL+WarningString+' '
  417. else:
  418. Tick_String = Fore.RED+Style.BRIGHT+Back.YELLOW+'<SELL ENTRY>'+Style.RESET_ALL+WarningString+' '
  419.  
  420.  
  421. else:
  422. Tick_String = Fore.WHITE+'PRICE UP LIQ DOWN'+Style.RESET_ALL+WarningString+' '
  423.  
  424. if Tick == -2:
  425. if abs_Liq < avg_Liq_change:
  426. Tick_String = Fore.BLUE+'PROFIT TAKING'+Style.RESET_ALL+WarningString+' '
  427.  
  428. if abs_Liq > avg_Liq_change*.75:
  429. Tick_String = Fore.RED+Style.BRIGHT+'STRONG SELLERS'+Style.RESET_ALL+WarningString+' '
  430.  
  431. if Tick == -1 and Liq_Tick == 0:
  432. prevLiq = Liquidity - Liq_change
  433. if abs_Liq >= avg_Liq_change*.8 and prevLiq < 0:
  434. Tick_String = Fore.RED+Style.BRIGHT+'AGGRESSIVE COVERING'+Style.RESET_ALL+WarningString+' '
  435.  
  436. if OC_Range >= avg_HL_Range*.9 and abs_Liq < avg_Liq_change*.75:
  437. Tick_String = Fore.RED+Style.BRIGHT+'MM\'s BEARISH'+WarningString+' '
  438.  
  439. elif abs_Liq < avg_Liq_change*.25 and OC_Range < avg_HL_Range:
  440. Tick_String = Fore.YELLOW+'DIP BUYERS'+Style.RESET_ALL+WarningString+' '
  441.  
  442.  
  443.  
  444. Range_List[ref_Num] = Range_Found
  445. # else:
  446. # Tick_String = Fore.WHITE+'PRICE UP LIQ DOWN'+Style.RESET_ALL+WarningString+' '+Fore.WHITE+str(Strength)
  447.  
  448.  
  449. # if abs(Liq_change) <= avg_Liq_change:
  450. # Tick_String = Fore.RED+'SHORT RALLY'+Style.RESET_ALL+WarningString+' '+Fore.RED+str(Strength)
  451. # # else:
  452. # Tick_String = Fore.WHITE+'PRICE UP LIQ DOWN'+Style.RESET_ALL+WarningString+' '+Fore.WHITE+str(Strength)
  453.  
  454. # if Tick == -1 and Liq_Tick == 0:
  455. # if Liquidity < 0:
  456. # if abs(Liq_change) > avg_Liq_change*2:
  457. # Tick_String = Fore.RED+'MM\'s BEARISH'+Style.RESET_ALL+WarningString+' '+Fore.YELLOW+str(Strength)
  458. # else:
  459. # Tick_String = Fore.RED+'SHORT COVERING'+Style.RESET_ALL+WarningString+' '+Fore.YELLOW+Back.BLUE+Style.BRIGHT+str(Strength)
  460.  
  461. Range_List[ref_Num] = Range_Found
  462. else:
  463.  
  464. if Range_Clause == True:
  465. if range_ref_String == "HIGH TARGET" and Money_Flow < 300000000:
  466. if Liq_change > 1000000:
  467. print("MARKET MAKER HIGH TARGET")
  468. if range_ref_String == "LOW TARGET" and Money_Flow > 300000000:
  469. if Liq_change < 1000000:
  470. print("MARKET MAKER LOW TARGET")
  471.  
  472. if lr_filled == False:
  473. if filled == False:
  474. if range_ref_String == "LOW TARGET" and Low_Price <= Low_Range:
  475. filled_Price = Low_Price
  476. time.sleep(.5)
  477. print(Fore.WHITE + Back.RED + "LOW RANGE FILLED" + Style.RESET_ALL)
  478. time.sleep(1)
  479. lr_filled = True
  480. lt_filled = False
  481. lrf = 1
  482. low_Ranges_Filled += lrf
  483. if lt_filled == False and lr_filled == True:
  484. if Close_Price <= Low_Target:
  485. filled_target_price = Close_Price
  486. time.sleep(.5)
  487. print(Fore.RED + Back.YELLOW + 'LOW TARGET FILLED' + Style.RESET_ALL)
  488. time.sleep(1)
  489. lt_filled = True
  490. filled = True
  491. low_Targets_Filled += 1
  492. if hr_filled == False:
  493. if filled == False:
  494. if range_ref_String == "HIGH TARGET" and High_Price >= High_Range:
  495. filled_range_price = High_Price
  496. time.sleep(.5)
  497. print(Fore.CYAN + "HIGH RANGE FILLED" + Style.RESET_ALL)
  498. time.sleep(1)
  499. hr_filled = True
  500. ht_filled = False
  501. hrf = 1
  502. high_Ranges_Filled += hrf
  503. if ht_filled == False and hr_filled == True:
  504. if Close_Price >= High_Target:
  505. filled_target_price = High_Price
  506. print(Fore.CYAN + "HIGH TARGET FILLED")
  507. time.sleep(1)
  508. ht_filled = True
  509. filled = True
  510. high_Targets_Filled += 1
  511.  
  512.  
  513. if menu_ans == '4' or menu_ans == '1':
  514. if rFound == True:
  515. if tHigh == True:
  516. HRS = str(High_Range)
  517. HRT = str(High_Target)
  518. LRS = str(Low_Range)
  519. LRT = str(Low_Target)
  520. MIV_Index_String = str(MIV_Index)
  521.  
  522. 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+']'+Fore.WHITE+' '+MIV_Index_String+'%'+Style.RESET_ALL+Fore.CYAN+' Avg High Flow: $'+'{:20,.2f}'.format(AvgHighRangeFlow), 'MoneyFlow: $','{:20,.2f}'.format(Money_Flow)+Style.RESET_ALL)
  523. time.sleep(2)
  524.  
  525.  
  526. else:
  527. tHigh = False
  528. else:
  529. rFound = False
  530. Close_Price = Close_Price
  531.  
  532. if rFound == True:
  533. if tLow == True:
  534. HRS = str(High_Range)
  535. HRT = str(High_Target)
  536. LRS = str(Low_Range)
  537. LRT = str(Low_Target)
  538. lowFlow = str(AvgLowRangeFlow)
  539. flow = str(Money_Flow)
  540. MIV_Index_String = str(MIV_Index)
  541.  
  542. Low_Prices = {'LOW RANGE: $': Low_Range, 'LOW TARGET: $': Low_Target} ##### May not need this line
  543. 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+']'+Fore.WHITE+' '+MIV_Index_String+'%'+Style.RESET_ALL+Fore.RED+' Avg Low Flow: $','{:20,.2f}'.format(AvgLowRangeFlow),'MoneyFlow: $','{:20,.2f}'.format(Money_Flow)+Style.RESET_ALL)
  544. time.sleep(2)
  545.  
  546. else:
  547. tLow = False
  548. else:
  549. rFound = False
  550.  
  551.  
  552. if Liq_change < -1000000:
  553. print(Fore.YELLOW + '[' + Date + ']', military_time,PCT_Range_Str,Style.RESET_ALL + Fore.CYAN + Back.RED + Style.BRIGHT + 'Current Liquidity:' + '{:20,.2f}'.format(Liquidity) + Style.RESET_ALL + Fore.YELLOW + Back.RED + Style.BRIGHT + ' Liq Change: ' + '{:20,.2f}'.format(Liq_change) + Style.RESET_ALL, Fore.YELLOW + Back.RED + Style.BRIGHT,'Last Price: [$' + str(Close_Price) + '] ' + Style.RESET_ALL + Tick_String + Style.RESET_ALL + Fore.YELLOW + Back.RED + Style.BRIGHT + '**SELL SIGNAL**' + Style.RESET_ALL)
  554. time.sleep(1)
  555. if abs(Liq_change) > 500000:
  556. time.sleep(.005)
  557. print(Fore.CYAN + '[' + Date + ']', military_time,PCT_Range_Str,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 + ' ' + Fore.WHITE+SS+'%'+Style.RESET_ALL)
  558. elif Liquidity > 0:
  559. if Liq_change > 0:
  560. time.sleep(.005)
  561. print(Fore.YELLOW + '[' + Date + ']', military_time,PCT_Range_Str,
  562. Fore.GREEN + 'Current Liquidity:' + '{:20,.2f}'.format(
  563. Liquidity) + Fore.GREEN + ' Liq Change: ' + '{:20,.2f}'.format(Liq_change) + ' ' + Fore.YELLOW + Back.BLUE,'Last Price [$' + str(Close_Price) + '] ' + Style.RESET_ALL+ Tick_String + Style.RESET_ALL+Fore.WHITE+' '+SS+'%'+Style.RESET_ALL)
  564. if Liq_change < 0:
  565. time.sleep(.005)
  566. print(Fore.YELLOW + '[' + Date + ']', military_time,PCT_Range_Str,
  567. Fore.GREEN + 'Current Liquidity:' + '{:20,.2f}'.format(
  568. 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) + '] ' + Style.RESET_ALL+ Tick_String + Style.RESET_ALL+Fore.WHITE+' '+SS+'%'+Style.RESET_ALL)
  569. elif Liq_change > 0:
  570. time.sleep(.005)
  571. print(Fore.YELLOW + '[' + Date + ']', military_time,PCT_Range_Str,Fore.BLUE + 'Current Liquidity:' + '{:20,.2f}'.format(Liquidity) + Style.RESET_ALL + Fore.WHITE,' Liq Change: ' + '{:20,.2f}'.format(Liq_change) + ' ' + Fore.YELLOW + Back.BLUE,'Last Price [$' + str(Close_Price) + '] ' +Style.RESET_ALL + Tick_String + Style.RESET_ALL + ' ' + Fore.WHITE+SS+'%'+Style.RESET_ALL)
  572. elif Liq_change < 0:
  573. time.sleep(.005)
  574. print(Fore.YELLOW + '[' + Date + ']', military_time,PCT_Range_Str,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) + '] ' +Style.RESET_ALL + Tick_String+ Style.RESET_ALL + ' ' + Fore.WHITE+SS+'%'+Style.RESET_ALL)
  575.  
  576.  
  577.  
  578.  
  579. '''if runningValueIndex > 0 and MIV_Index > 0:
  580. print(' '+Fore.BLACK+Back.WHITE+'MIV_Index:+'+MIV_Index_String+'% '+Style.RESET_ALL+' '+Fore.BLACK+Back.GREEN+'Running Value:+'+runningValueIndex_String+'%'+Style.RESET_ALL)
  581. if MIV_Index < 0 and runningValueIndex > 0:
  582. print(' '+Fore.RED+Back.YELLOW+'MIV_Index:'+MIV_Index_String+'% '+Style.RESET_ALL+' '+Fore.BLACK+Back.GREEN+'Running Value:+'+runningValueIndex_String+'%'+Style.RESET_ALL)
  583. if MIV_Index > 0 and runningValueIndex < 0:
  584. print(' '+Fore.WHITE+'MIV_Index:+'+MIV_Index_String+'% '+Style.RESET_ALL+' '+Fore.RED+Back.YELLOW+'Running Value:'+runningValueIndex_String+'%'+Style.RESET_ALL)
  585. if MIV_Index < 0 and runningValueIndex < 0:
  586. print(' '+Fore.RED+'MIV_Index:'+MIV_Index_String+'% '+Style.RESET_ALL+' '+Fore.RED+'Running Value:'+runningValueIndex_String+'%'+Style.RESET_ALL)'''
  587.  
  588. '''else:
  589. runningValueIndex += MIV_Index
  590. runningValueIndex_String = str(round(runningValueIndex, 2))
  591. if runningValueIndex > 0:
  592. print(Fore.GREEN+'MIV_Index: '+runningValueIndex_String, '%')
  593. else:
  594. runningValueIndex_String = str(round(runningValueIndex, 2))
  595. print(Fore.RED+'MIV_Index: '+runningValueIndex_String, '%')'''
  596.  
  597.  
  598. if menu_ans == '3':
  599. printRangeFile = input('Would you like to see other found ranges?: [y/n]')
  600. if printRangeFile == 'y':
  601. file_Choose = input('Which file would you like to use? [1 = 1 min Ranges] [2 = 2 min ranges] [5 = 5 min ranges]: ')
  602. if file_Choose == '1':
  603. filename = ('/Users/King/iFiles/iRanges/SPY1.csv')
  604. if file_Choose == '2':
  605. filename = ('/Users/King/iFiles/iRanges/SPY2.csv')
  606. if file_Choose == '5':
  607. filename = ('/Users/King/iFiles/iRanges/SPY5.csv')
  608. with open(filename, 'r') as csv_file:
  609. csv_reader = csv.reader(csv_file)
  610. for row in csv_reader:
  611. Date = row[0]
  612. Time = row[1]
  613. range_ref_String = row[2]
  614. Close_Price = float(row[3])
  615. M_Price = float(row[4])
  616. TargetPrice = row[5]
  617. Money_Flow = float(row[6])
  618. f_Vol = float(row[7])
  619. OppRange = row[8]
  620. OppTarget = row[9]
  621. Liquidity = float(row[10])
  622. Liq_change = float(row[11])
  623. LFP = float(row[12])
  624. MIVI = float(row[13])
  625. ref_Num = int(row[15])
  626. CandleDuration = str(row[14])
  627. list = [Date, Time, range_ref_String]
  628. Targets = [M_Price, TargetPrice]
  629. MIV_Index = str(MIVI) + str('%')
  630. liq_flowPrice = str(round(LFP, 3))
  631. oppositePrices = [OppRange, OppTarget]
  632. Liq_change_String = str('$' + '{:20,.2f}'.format(Liq_change))
  633. listlist = []
  634. dict = {'': list, 'Targets: ':Targets, 'Found price: ':Close_Price,'Opposite Ranges/Targets':oppositePrices}
  635. range_info = {'MIV Index:': MIV_Index, 'Liq Change:':Liq_change_String,'Candle Duration:':CandleDuration, 'REF#':ref_Num}
  636. if MIVI < 0 and Liq_change > 0:
  637. infotext = colored(str(range_info), 'grey', 'on_cyan', attrs=['reverse', 'underline'])
  638. else:
  639. infotext = colored(str(range_info), 'grey', 'on_red', attrs=['reverse', 'underline'])
  640. for k, v in dict.items():
  641. time.sleep(.001)
  642. print(Fore.YELLOW, k, v)
  643. cprint(infotext)
  644. print('\n')
  645. break
  646.  
  647.  
  648.  
  649.  
  650. print('MIV Spike Count: ',MIV_Spike_Count)
  651. print('Avg MIV Spike',Avg_MIV_Spike,'%')
  652. print(Fore.CYAN + 'REF#:', ref_Num)
  653. time.sleep(.25)
  654. print(Fore.WHITE + Time)
  655. time.sleep(.25)
  656. print("Last:", "$" + str(Close_Price))
  657. time.sleep(.25)
  658. print("HLCC:", "$" + str(HLCC))
  659. time.sleep(.25)
  660. print("Money Price: ", "$" + str(round(M_Price, 2)))
  661. time.sleep(.25)
  662. print('Price Diff: ' + '$' + str(Diff))
  663. time.sleep(.25)
  664. if f_Vol > 1000000:
  665. print(Fore.YELLOW + 'Volume:' + '{:20,.2f}'.format(f_Vol))
  666. else:
  667. print(Fore.WHITE + 'Volume:' + '{:20,.2f}'.format(f_Vol))
  668. time.sleep(.25)
  669. if Money_Flow > 350000000:
  670. print(Fore.YELLOW + '$Flow:' + '{:20,.2f}'.format(Money_Flow))
  671. else:
  672. print(Fore.WHITE + '$Flow:' + '{:20,.2f}'.format(Money_Flow))
  673. time.sleep(.25)
  674. if Liq_change < 0:
  675. print(Fore.RED + 'Liq Change:', '{:20,.2f}'.format(Liq_change), Style.RESET_ALL)
  676. else:
  677. print(Fore.CYAN + 'Liq Change:', '{:20,.2f}'.format(Liq_change))
  678. time.sleep(.25)
  679. if Liquidity < 0:
  680. print(Fore.RED + 'Current Liquidity:' + '{:20,.2f}'.format(Liquidity), Style.RESET_ALL)
  681. else:
  682. print(Fore.CYAN + 'Current Liquidity:' + '{:20,.2f}'.format(Liquidity), Style.RESET_ALL)
  683. time.sleep(.25)
  684. print('Avg MIV Spike: ',Avg_MIV_Spike,'%')
  685. if percent_Strength >= -.68:
  686. percent_Strength_String = Fore.GREEN+'Current Strength: '+str(percent_Strength)+'%'
  687. print(percent_Strength_String)
  688. if percent_Strength <-.68:
  689. percent_Strength_String = Fore.RED+'Current Strength: '+str(percent_Strength)+'%'
  690. print(percent_Strength_String)
  691. if percent_Strength < 1 and percent_Strength > -.99:
  692. percent_Strength_String = colored('Current Strength: '+'#N/A', 'white', 'on_grey', attrs=['blink'])
  693. cprint(percent_Strength_String)
  694. new_Strength = 100-(100*abs(percent_Strength- -.3153) / .8794)
  695. if new_Strength > 70:
  696. new_Strength_String = Fore.CYAN+'Bullishness Percentile: '+str(round(new_Strength, 2))+'%'+Style.RESET_ALL
  697. else:
  698. new_Strength_String = Fore.RED+'Bullishness Percentile: '+str(round(new_Strength, 2))+'%'+Style.RESET_ALL
  699. print(new_Strength_String)
  700. print('\nLow Ranges/Targets Found|Filled:',lows_found, '| ', low_Ranges_Filled)
  701. print('\nHigh Ranges/Targets Found|Filled: ',highs_found, '| ', high_Ranges_Filled)
  702. print('Total found: ',found)
  703.  
  704. '''if found >0:
  705. tList = tList
  706. if tList[1] == 'High':
  707. print(Fore.GREEN+'LAST RANGE FOUND: [$' + str(Low_Range)+']','[$' + str(High_Range)+']', ' [' + range_ref_String + ': $' + str(Target)+']'+Style.RESET_ALL)
  708. print(Fore.GREEN+'POTENTIAL TARGETS: [$' + str(Low_Target)+']', '[$' + str(High_Target)+']'+Style.RESET_ALL)
  709. print(Fore.GREEN+'Found price: [$' + found_price + ']', 'Target implies a move of [' + implied_move + '%]'+'from current price ['+str(Close_Price)+']'+Style.RESET_ALL)
  710. else:
  711. tList = tList
  712. if tList[1] == 'Low':
  713. print(Fore.RED+'LAST RANGE FOUND: [$' + str(Low_Range)+']','$' + str(High_Range) + ' [' + range_ref_String + ': $' + str(Target)+Style.RESET_ALL)
  714. print(Fore.RED+'POTENTIAL TARGETS: [$' + str(Low_Target)+']', '$' + str(High_Target)+Style.RESET_ALL)
  715. print(Fore.RED+'Found price: [$' + (found_price) + ']', 'Target implies a move of [' + implied_move + '%]' + 'from current price [' + str(Close_Price) + ']'+Style.RESET_ALL)'''
  716.  
  717. '''input = input('Would you like to see other found ranges?: [y/n]')
  718. if input == 'y':
  719. with open('/Users/King/Desktop/RangeTargets.csv' 'r') as csv_file:
  720. csv_reader = csv.reader(csv_file)
  721. for row in csv_file:
  722. row[0] = Date
  723. row[1] = Time
  724. row[2] = range_ref_String
  725. row[3] = Close_Price
  726. row[4] = M_Price
  727. row[5] = TargetPrice
  728. print('\nLow Ranges/Targets Found|Filled: ', lows_found, '| ', low_Ranges_Filled, str(round(low_range_Accuracy, 2)), '%')
  729. low_range_Accuracy = low_Ranges_Filled / lows_found
  730.  
  731. row[6] = Money_Flow
  732. row[7] = f_Vol
  733. row[8] = OppRange
  734. row[9] = OppTarget'''
  735.  
  736. '''if abs(Liq_change) > 500000:
  737. time.sleep(.005)
  738. 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)
  739. else if Liquidity > 0:
  740. if Liq_change > 0:
  741. time.sleep(.005)
  742. 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)
  743. if Liq_change < 0:
  744. time.sleep(.005)
  745. 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)
  746. else if Liq_change > 0:
  747. time.sleep(.005)
  748. 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)
  749. else if Liq_change < 0:
  750. time.sleep(.005)
  751. print(Fore.RED+'['+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)'''
  752.  
  753. '''if menu_ans == '1' and Liquidity_Data == 'list':
  754. print(Fore.CYAN + 'REF#:', ref_Num)
  755. time.sleep(.05)
  756. print(Fore.WHITE + Time)
  757. time.sleep(.05)
  758. print("Last:", "$" + str(Close_Price))
  759. time.sleep(.05)
  760. print("HLCC:", "$" + str(HLCC))
  761. time.sleep(.05)
  762. print("Money Price: ", "$" + str(round(M_Price, 2)))
  763. time.sleep(.05)
  764. print('Price Diff: ' + '$' + str(Diff))
  765. time.sleep(.05)
  766. if f_Vol > 1000000:
  767. print(Fore.YELLOW + 'Volume:' + '{:20,.2f}'.format(f_Vol))
  768. else:
  769. print(Fore.WHITE + 'Volume:' + '{:20,.2f}'.format(f_Vol))
  770. time.sleep(.05)
  771. if Money_Flow > 350000000:
  772. print(Fore.YELLOW + '$Flow:' + '{:20,.2f}'.format(Money_Flow))
  773. else:
  774. print(Fore.WHITE + '$Flow:' + '{:20,.2f}'.format(Money_Flow))
  775. time.sleep(.05)
  776. if Liq_change < 0:
  777. print(Fore.RED + 'Liq Change:', '{:20,.2f}'.format(Liq_change), Style.RESET_ALL)
  778. else:
  779. print(Fore.CYAN + 'Liq Change:', '{:20,.2f}'.format(Liq_change))
  780. time.sleep(.05)
  781. if Liquidity < 0:
  782. print(Fore.RED + 'Current Liquidity:' + '{:20,.2f}'.format(Liquidity), Style.RESET_ALL)
  783. else:
  784. print(Fore.CYAN + 'Current Liquidity:' + '{:20,.2f}'.format(Liquidity), Style.RESET_ALL)
  785. time.sleep(.1)
  786. if NoStop == True:
  787. with open('/Users/King/Desktop/SPY_RangeTargets/NoStop.csv', 'r') as csv_file:
  788. csv_reader = csv.reader(csv_file)
  789. for row in csv_reader:
  790. Date = row[0]
  791. Time = row[1]
  792. range_ref_String = row[2]
  793. Close_Price = float(row[3])
  794. M_Price = float(row[4])
  795. TargetPrice = row[5]
  796. Money_Flow = float(row[6])
  797. f_Vol = float(row[7])
  798. OppRange = row[8]
  799. OppTarget = row[9]
  800. Liquidity = float(row[10])
  801. Liq_change = float(row[11])
  802. LFP = round(float(row[12]), 3)
  803. MIVI = float(row[13])
  804. ref_Num = int(row[14])
  805. list = [Date, Time, range_ref_String]
  806. Targets = [M_Price, TargetPrice]
  807. MIV_Index = str(MIVI)+str('%')
  808. liq_flowPrice = str(round(LFP, 3))
  809. oppositePrices = [OppRange, OppTarget]
  810. Liq_change_String = str('$'+'{:20,.2f}'.format(Liq_change))
  811. listlist = [MIV_Index, Liq_change, ref_Num]
  812. dict = {'':list, 'Targets: ':Targets, 'Found price: ':Close_Price, 'Opposite Ranges/Targets':oppositePrices}
  813. range_info = {'MIV Index: ':MIV_Index, ' Liq Change:':Liq_change_String, 'REF#':ref_Num}
  814. if MIVI < 0 and Liq_change > 0:
  815. infotext = colored(str(range_info), 'grey', 'on_cyan', attrs=['reverse', 'underline'])
  816. else:
  817. infotext = colored(str(range_info), 'grey', 'on_white', attrs=['reverse', 'underline'])
  818. for k,v in dict.items():
  819. time.sleep(.001)
  820. print(Fore.YELLOW, k,v)
  821.  
  822. cprint(infotext)
  823. print('\n')'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement