Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash python
- import csv
- import datetime
- from datetime import datetime
- from colorama import Back, Fore, Style
- from colorama import init
- import time
- import itertools
- from itertools import zip_longest
- from time import sleep
- with open('/Users/King/Spy_Current.csv', 'r') as csv_file:
- csv_reader = csv.reader(csv_file)
- header = next(csv_reader)
- ref = [] # Start off w/ empty list
- ref_Num = int(0) # First to go in list = ref # (390 cells in 1 day)(using ref+=1 for each row)
- data = [] # Not sure but I could rearrange for liquidity?
- Liquidity = float()
- found = int(0)
- Range = []
- Target = []
- Range_List = {}
- Low_Range_Found = {}
- High_Range_Found = {}
- Range_Found = {}
- range_ref_String = ('')
- dTime = []
- printRanges = str()
- range_identifier_low = 'Low'
- range_identifier_high = 'High'
- range_identifier_all = 'All'
- All_Range_References = []
- All_Referenced_Prices = []
- menu_ans = input('What would you like to do? \n [1] Print Liquidity Data | [2] See previous ranges | [3] Test\n')
- if menu_ans == '1':
- Liquidity_Data = input('Would you like to print liquidity data? [y/n]: ')
- if menu_ans == '2':
- printRanges = input('Which ranges would you like to see?: [High/Low/All]\n')
- range_identifier = ''
- new_range = bool
- t = bool
- tLow = bool
- tHigh = bool
- Target = float()
- Range_Dict = {}
- TickString = str()
- TickSum = int()
- Tick = int(0)
- Tick_String = ''
- StartTraceback = {}
- day_Count = int()
- tList = []
- last = float()
- LT = float()
- HT = float()
- last = float()
- Strength = int()
- TrendStrength = ''
- Price_Tick = int()
- Previous = []
- for row in csv_reader:
- # row = [Time, Open, Close, High, Low, realVol, Money_Flow]
- ref_Num += 1 # Starting at 0
- dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
- Time = dTime[-14:]
- Open_Price = float(row[1]) # Price Data Dictionary
- Close_Price = float(row[2]) # Price Data Dictionary
- High_Price = float(row[3]) # Price Data Dictionary
- Low_Price = float(row[4]) # Price Data Dictionary
- Money_Flow = float(row[6]) # Price Data Dictionary
- Vol = row[5] # Price Data Dictionary
- f_Vol = float(Vol[:-1]) # Price Data Dictionary
- m_Vol = str(Vol[-1:]) # Price Data Dictionary
- if m_Vol == "K": # Price Data Dictionary
- f_Vol = f_Vol * 1000 # Price Data Dictionary
- if m_Vol == "M": # Price Data Dictionary
- f_Vol = f_Vol * 1000000
- if m_Vol != "K" and m_Vol != "M":
- f_Vol = float(row[5]) # Price Data Dictionary
- HLCC = round(float(High_Price + Low_Price + Close_Price + Close_Price)/4, 2) # Price Data Dictionary & RangeReference Dictionary
- M_Price = round(float(Money_Flow) / f_Vol, 2) # Price Data Dictionary & RangeReference Dictionary
- Diff = round(HLCC - M_Price, 2) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
- MMM = float(f_Vol * HLCC) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
- Liq_change = float(Money_Flow - MMM) # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
- Liquidity += Liq_change # Price Data Dictionary & RangeReference Dictionary & Data Dictionary
- Date = str(Time[:5]) # Important
- military_time = str(Time[-8:])
- criteria = abs(.003*HLCC) # Important
- allData = [ref_Num,Date, military_time, High_Price,Low_Price,Close_Price, HLCC, M_Price, f_Vol, Money_Flow,MMM, Liquidity,Liq_change]
- Data_Dict = {'REF#':[ref_Num],'Date':[Date],'Time':[military_time], 'Close_Price':[Close_Price], 'M_Price':[M_Price], 'Volume':[f_Vol]}
- '''USING THIS DATA
- [0]REFERENCE NUMBER
- [1]DATE
- [2]MILITARY_TIME
- [3]HIGH_PRICE
- [4]LOW_PRICE
- [5]CLOSE_PRICE
- [6]HLCC
- [7]M_Price
- [8]F_VOL
- [9]MONEY_FLOW
- [10]MARKETMAKERMOVE 'MMM'
- [11]LIQUIDITY
- [12]LIQ_CHANGE
- '''
- if abs(allData[7]-allData[6]) > criteria:
- found +=1
- diff = abs(M_Price - Close_Price)
- Range_Clause = True
- range_identifier_all = 'All'
- if Range_Clause == True:
- t_price = M_Price
- found_Price = HLCC
- Low_Range = round(HLCC - abs(float(M_Price - HLCC)), 2)
- High_Range = round(HLCC + abs(float(M_Price - HLCC)), 2)
- Low_Target = round(Low_Range - abs(float(M_Price - HLCC)), 2)
- High_Target = round(High_Range + abs(float(M_Price - HLCC)), 2)
- if M_Price >= found_Price+diff:
- range_ref_String = "HIGH TARGET"
- tHigh = True
- Target = M_Price
- range_identifier = 'High'
- found_Price = HLCC
- tList = ['High', High_Target]
- elif M_Price<= found_Price-diff:
- range_ref_String = "LOW TARGET"
- tLow = True
- Target = M_Price
- range_identifier = 'Low'
- found_Price = HLCC
- tList = ['Low', Low_Target]
- RT_Reference1 = [Low_Range, High_Range, Low_Target, High_Target]
- LRS = '$'+str(Low_Range)
- LRT = '$'+str(Low_Target)
- HRS = '$'+str(High_Range)
- HRT = '$'+str(High_Target)
- found_Price_String = '$'+str(found_Price)
- RT_Reference = [LRS, LRT, HRS, HRT]
- Target = round(Target, 2)
- Target_String = '$'+str(Target)
- lows = [LRS, LRT]
- highs = [HRS, HRT]
- target_String = range_ref_String+': $'
- end_String = 'Price while found: $'+str(Close_Price)
- if printRanges == range_identifier and range_identifier == range_identifier_low:
- Low_Range_Reference = [Date, military_time, range_ref_String, Target_String, end_String]
- Low_Range_Found = {'\nData Found':Low_Range_Reference, 'Watch for: $':lows, 'Potential Resistance: ':highs}
- Low_Range = Low_Range_Found
- for k, v in dict.items(Low_Range):
- print(Fore.RED, k, v)
- if printRanges == range_identifier and range_identifier == range_identifier_high:
- High_Range_Reference = [Date, military_time, range_ref_String, Target_String, end_String]
- High_Range_Found = {'\nData Found': High_Range_Reference, 'Watch for: $':highs, 'Potential Support: ':lows}
- High_Range = High_Range_Found
- for k, v in dict.items(High_Range):
- print(Fore.CYAN, k, v)
- if printRanges == range_identifier_all and range_identifier_all == range_identifier_all:
- Range_Reference = [Date, military_time, Close_Price, range_ref_String]
- TRange_Reference = [LRS, HRS, LRT, HRT]
- Range_Found = {'<-- Reference': Range_Reference, 'TRange Reference': TRange_Reference}
- Range_List[ref_Num] = Range_Found
- print(Back.BLUE+Fore.WHITE+str(found), str(Range_Found)+Style.RESET_ALL)
- else:
- Range_Clause = False
- tHigh = False
- tLow = False
- if menu_ans == '1' and Liquidity_Data =='y':
- if Close_Price > Open_Price:
- Price_Tick = 1
- if Close_Price < Open_Price:
- Price_Tick = -1
- if Liq_change > 0:
- Liq_Tick = 1
- if Liq_change < 0:
- Liq_Tick = -1
- Tick = Liq_Tick + Price_Tick
- Strength += Tick
- if Tick > 0:
- Tick_String = Fore.BLUE+Back.GREEN+'STRONG BUYERS'
- if Tick < 0:
- Tick_String = Fore.RED+Back.YELLOW+'STRONG SELLERS'
- if Tick == 0 and Price_Tick > 0:
- Tick_String = Fore.WHITE+'WEAK BUYERS'
- if Tick == 0 and Liq_Tick > 0:
- Tick_String = Fore.RED+'SHORT COVERING'
- Range_List[ref_Num] = Range_Found
- t = False
- tHigh = tHigh
- tLow = tLow
- Close_Price = Close_Price
- if tHigh == True:
- t = True
- HRS = str(High_Range)
- HRT = str(High_Target)
- LRS = str(Low_Range)
- LRT = str(Low_Target)
- 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)
- time.sleep(2)
- add_Range_Target = input('Would you like to add this range to file?: [y/n]:')
- if add_Range_Target == 'y':
- with open('/Users/King/Desktop/RangeTargets.csv', 'a') as csv_file:
- file_PriceList = [Date, military_time, range_ref_String, Close_Price, M_Price, HRT, Money_Flow, f_Vol, LRS, LRT]
- wr = csv.writer(csv_file)
- wr.writerow(file_PriceList)
- else:
- t = False
- Close_Price = Close_Price
- if tLow == True:
- t = True
- HRS = str(High_Range)
- HRT = str(High_Target)
- LRS = str(Low_Range)
- LRT = str(Low_Target)
- Low_Prices = {'LOW RANGE: $': Low_Range, 'LOW TARGET: $': Low_Target} ##### May not need this line
- 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)
- time.sleep(2)
- add_Range_Target = input('Would you like to add this range to file?: [y/n]:')
- if add_Range_Target == 'y':
- with open('/Users/King/Desktop/RangeTargets.csv', 'a') as csv_file:
- file_PriceList = [Date, military_time, range_ref_String, Close_Price, M_Price, LRT, Money_Flow, f_Vol, HRS, HRT]
- wr = csv.writer(csv_file)
- wr.writerow(file_PriceList)
- else:
- t = False
- if abs(Liq_change) > 500000:
- time.sleep(.005)
- 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)
- elif Liquidity > 0:
- if Liq_change > 0:
- time.sleep(.005)
- 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)
- if Liq_change < 0:
- time.sleep(.005)
- 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)
- elif Liq_change > 0:
- time.sleep(.005)
- 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)
- elif Liq_change < 0:
- time.sleep(.005)
- 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)
- if menu_ans == '3':
- Days = ref_Num // 390
- Hours = float(ref_Num / 60)
- HoursLeft = float(ref_Num / 390 - Days) / 60
- Minutes = ref_Num
- MinutesLeft = HoursLeft * 100
- print('Total Minutes recorded: ',ref_Num)
- print('Total Days recorded ', Days,'Days', str(round(HoursLeft, 2)), 'Hours', str(round(MinutesLeft, 2)), 'Minutes')
- input = input('Would you like to see other found ranges?: [y/n]')
- if input == 'y':
- with open('/Users/King/Desktop/RangeTargets.csv', 'r') as csv_file:
- csv_reader = csv.reader(csv_file)
- for row in csv_reader:
- Date = row[0]
- Time = row[1]
- range_ref_String = row[2]
- Close_Price = float(row[3])
- M_Price = float(row[4])
- TargetPrice = row[5]
- Money_Flow = float(row[6])
- f_Vol = float(row[7])
- OppRange = row[8]
- OppTarget = row[9]
- list = [Date, Time, range_ref_String]
- Targets = [M_Price, TargetPrice]
- oppositePrices = [OppRange, OppTarget]
- listlist = [TargetPrice, OppRange, OppTarget]
- dict = {'Info':list, 'Targets: ':Targets, 'Found price: ':Close_Price, 'Opposite Ranges/Targets':oppositePrices}
- print(dict)
- print(Fore.CYAN+'REF#:', ref_Num)
- time.sleep(.25)
- print(Fore.WHITE+Time)
- time.sleep(.25)
- print("Last:", "$" + str(Close_Price))
- time.sleep(.25)
- print("HLCC:", "$" + str(HLCC))
- time.sleep(.25)
- print("Money Price: ", "$" + str(round(M_Price, 2)))
- time.sleep(.25)
- print('Price Diff: '+'$'+str(Diff))
- time.sleep(.25)
- if f_Vol > 1000000:
- print(Fore.YELLOW+'Volume:' + '{:20,.2f}'.format(f_Vol))
- else:
- print(Fore.WHITE+'Volume:' + '{:20,.2f}'.format(f_Vol))
- time.sleep(.25)
- if Money_Flow > 350000000:
- print(Fore.YELLOW+'$Flow:' + '{:20,.2f}'.format(Money_Flow))
- else:
- print(Fore.WHITE+'$Flow:' + '{:20,.2f}'.format(Money_Flow))
- time.sleep(.25)
- if Liq_change < 0:
- print(Fore.RED+'Liq Change:', '{:20,.2f}'.format(Liq_change), Style.RESET_ALL)
- else:
- print(Fore.CYAN+'Liq Change:', '{:20,.2f}'.format(Liq_change))
- time.sleep(.25)
- if Liquidity < 0:
- print(Fore.RED+'Current Liquidity:' + '{:20,.2f}'.format(Liquidity),Style.RESET_ALL)
- else:
- print(Fore.CYAN+'Current Liquidity:' + '{:20,.2f}'.format(Liquidity),Style.RESET_ALL)
- time.sleep(.25)
- if abs(Strength) > 2 and Strength > 2:
- print(Fore.CYAN+'Current Strength: '+ str(Strength))
- if Strength < -2:
- print(Fore.RED+'Current Strength: ' +str(Strength))
- '''if found >0:
- tList = tList
- if tList[1] == 'High':
- print(Fore.GREEN+'LAST RANGE FOUND: [$' + str(Low_Range)+']','[$' + str(High_Range)+']', ' [' + range_ref_String + ': $' + str(Target)+']'+Style.RESET_ALL)
- print(Fore.GREEN+'POTENTIAL TARGETS: [$' + str(Low_Target)+']', '[$' + str(High_Target)+']'+Style.RESET_ALL)
- print(Fore.GREEN+'Found price: [$' + found_price + ']', 'Target implies a move of [' + implied_move + '%]'+'from current price ['+str(Close_Price)+']'+Style.RESET_ALL)
- else:
- tList = tList
- if tList[1] == 'Low':
- print(Fore.RED+'LAST RANGE FOUND: [$' + str(Low_Range)+']','$' + str(High_Range) + ' [' + range_ref_String + ': $' + str(Target)+Style.RESET_ALL)
- print(Fore.RED+'POTENTIAL TARGETS: [$' + str(Low_Target)+']', '$' + str(High_Target)+Style.RESET_ALL)
- print(Fore.RED+'Found price: [$' + (found_price) + ']', 'Target implies a move of [' + implied_move + '%]' + 'from current price [' + str(Close_Price) + ']'+Style.RESET_ALL)'''
- '''input = input('Would you like to see other found ranges?: [y/n]')
- if input == 'y':
- with open('/Users/King/Desktop/RangeTargets.csv' 'r') as csv_file:
- csv_reader = csv.reader(csv_file)
- for row in csv_file:
- row[0] = Date
- row[1] = Time
- row[2] = range_ref_String
- row[3] = Close_Price
- row[4] = M_Price
- row[5] = TargetPrice
- row[6] = Money_Flow
- row[7] = f_Vol
- row[8] = OppRange
- row[9] = OppTarget'''
- '''if abs(Liq_change) > 500000:
- time.sleep(.005)
- 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)
- else if Liquidity > 0:
- if Liq_change > 0:
- time.sleep(.005)
- 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)
- if Liq_change < 0:
- time.sleep(.005)
- 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)
- else if Liq_change > 0:
- time.sleep(.005)
- 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)
- else if Liq_change < 0:
- time.sleep(.005)
- 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)'''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement