ImDerekD

ScratchFlow.py(01_05)

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