Advertisement
ImDerekD

ScratchFlow_(01_05)_419PM

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