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
- import sys
- from termcolor import colored, cprint
- from colorama import init
- import numbers
- import time
- import itertools
- from itertools import zip_longest
- from time import sleep
- import pathlib
- import os
- import os.path
- from pathlib import Path
- import glob
- from progress.bar import Bar
- import hashlib
- #File Entry / Open / Confirm
- # filename_input = input('Filename: ')
- dir = '/Users/King/iFiles/'
- # confirmFile = Path(dir+filename_input+'.csv')
- # FileExists = Path.is_file(confirmFile)
- #Data in File
- for file in glob.glob(dir+'*2.csv'):
- filename = file[19:-4]
- ticker = filename[:-1]
- candleDur = filename[-1:]
- ref_Num = int(0)
- Liquidity = float()
- #HashAll
- CurrentInfo = []
- regDate = []
- regTime = []
- hashDateTime1 = []
- hashDateTime2 = []
- hashData1 = []
- #MIV
- MIVList = []
- prevPrice = float(1)
- prevFlow = float(1)
- prevVol = int(1)
- counter = int()
- xLiq = float()
- xVol = int()
- xLFP = float()
- xVLiq = float()
- xMIV = float()
- #Ranges
- tHigh = bool
- tLow = bool
- Filled = bool
- lows_Found = int()
- lows_Filled = int()
- highs_Found = int()
- highs_Filled = int()
- Found = int()
- last = float()
- #TimeTakenForRangesToGetFilled
- timeTaken = []
- count = int()
- x = int(0)
- n = int(0)
- with open(file, 'r') as csv_file:
- reader = csv.reader(csv_file)
- header = next(reader)
- for row in reader:
- ref_Num += 1
- dTime = str(datetime.strptime(row[0], '%a %b %d %H:%M'))
- Time = dTime[-14:]
- Open_Price = float(row[1])
- Close_Price = float(row[2])
- High_Price = float(row[3])
- Low_Price = float(row[4])
- Money_Flow = float(row[6])
- last = Close_Price
- Vol = row[5]
- f_Vol = float(Vol[:-1])
- m_Vol = str(Vol[-1:])
- if m_Vol == "K":
- f_Vol = f_Vol * 1000
- if m_Vol == "M":
- f_Vol = f_Vol * 1000000
- if m_Vol != "K" and m_Vol != "M":
- f_Vol = float(row[5])
- if f_Vol < 1:
- M_Price = HLCC
- else:
- M_Price = round(float(Money_Flow) / f_Vol, 2)
- HLCC = float(High_Price + Low_Price + Close_Price + Close_Price)/4
- Diff = round(HLCC - M_Price, 2)
- MMM = float(f_Vol * HLCC)
- Liq_change = float(Money_Flow - MMM)
- Liquidity += Liq_change
- Date = str(Time[:5])
- military_time = str(Time[-8:])
- criteria = abs(.0035*HLCC)
- if abs(Liq_change) > 0:
- LiqFlowPrice = round(Money_Flow / abs(Liq_change), 2)
- VolLiqPrice = round(f_Vol / abs(Liq_change), 2)
- LiqFlowPriceClone = round(1000*(abs(Liq_change) / Money_Flow), 4)
- if Money_Flow > 0:
- MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 2)
- prevPrice = Close_Price
- prevFlow = Money_Flow
- prevVol = f_Vol
- if abs(MIV_Index) > 3:
- Volume = '{:20,.2f}'.format(f_Vol)
- AbsLiqChange = '{:20,.2f}'.format(Liq_change)
- LFP = '{:20,.2f}'.format(LiqFlowPrice)
- VolumeLiqPrice = '{:20,.2f}'.format(VolLiqPrice)
- ExtremeMIVList = [Date,military_time,MIV_Index,AbsLiqChange,Volume,LFP,VolumeLiqPrice,LiqFlowPriceClone]
- MIVList.append(ExtremeMIVList)
- if abs(M_Price-HLCC) >= criteria:
- diff = M_Price - HLCC
- Range_Clause = True
- Found += 1
- FoundPrice = Close_Price
- 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)
- r_Price = M_Price
- t_Price = M_Price + diff
- opp_Range = round(float(HLCC + (diff*-1)), 2)
- opp_Target = round(float(opp_Range + (diff*-1)), 2)
- if r_Price == Low_Range:
- tLow = True
- tHigh = False
- Filled = False
- lows_Found += 1
- RangeString = str(r_Price)
- FoundPriceString = str(FoundPrice)
- range_ref_String = Fore.RED+"[LOW TARGET]"
- foundDate = Fore.RED+Date+' '+military_time
- TargetString = str(t_Price)
- '''print(Fore.RED+"LOW TARGET",RangeString, TargetString, Style.RESET_ALL)
- time.sleep(1.5)'''
- if r_Price == High_Range and MIV_Index < 0:
- foundDate = Fore.CYAN+Date+' '+military_time
- range_ref_String = Fore.CYAN+"[HIGH TARGET]"
- tLow = False
- tHigh = True
- Filled = False
- highs_Found += 1
- RangeString = str(r_Price)
- TargetString = str(t_Price)
- '''print(Fore.CYAN+"HIGH TARGET",RangeString, TargetString, Style.RESET_ALL)
- time.sleep(1.5)'''
- if Filled == False and tHigh == True:
- count += 1
- if High_Price >= High_Range:
- timeTaken.append(count)
- Filled = True
- highs_Filled += 1
- '''print(Fore.CYAN+"HIGH RANGE FILLED", Style.RESET_ALL)
- time.sleep(1)'''
- count = count*0
- if Filled == False and tLow == True:
- count += 1
- if Low_Price <= Low_Range:
- timeTaken.append(count)
- Filled = True
- lows_Filled += 1
- '''print(Fore.RED+"LOW RANGE FILLED", Style.RESET_ALL)
- time.sleep(1)'''
- count = count*0
- '''print(Date, military_time, Close_Price)'''
- if highs_Found > 0 and lows_Found > 0:
- if highs_Filled and lows_Filled > 0:
- lowAccuracy = 100*round(lows_Filled / lows_Found, 2)
- highAccuracy = 100*round(highs_Filled / highs_Found, 2)
- print('$%s' % ticker, '%s Min File' % candleDur)
- if lowAccuracy > 70:
- print(Fore.RED+'Lows Found: '+Fore.CYAN,lows_Found, ' | ', lows_Filled, '[',lowAccuracy,'%]'+Style.RESET_ALL)
- else:
- print(Fore.RED+'Lows Found: '+Fore.YELLOW,lows_Found, ' | ', lows_Filled, '[',lowAccuracy,'%]'+Style.RESET_ALL)
- if highAccuracy > 70:
- print(Fore.CYAN+'Highs Found: ',highs_Found, ' | ', highs_Filled, '[',highAccuracy,'%]'+Style.RESET_ALL)
- else:
- print(Fore.CYAN+'Highs Found: '+Fore.YELLOW,highs_Found, ' | ', highs_Filled, '[',highAccuracy,'%]'+Style.RESET_ALL)
- AbsolutePriceRange = abs(Close_Price - t_Price) + abs(Close_Price - opp_Target)
- percent_in_range = 100-(100*round(abs(Close_Price - t_Price) / AbsolutePriceRange, 2))
- print('Direction: %s' % range_ref_String+Style.RESET_ALL)
- print('Last Price: [$',Close_Price,']','Found Price: [$',FoundPrice,']')
- print('Range Price: [$',r_Price,']', 'Opposite Range: [$',opp_Range,']')
- print('Percent in Range: [',percent_in_range,'%]')
- LN = round(100*(Close_Price - FoundPrice) / Close_Price, 2)
- print(Fore.WHITE+'Found: '+foundDate)
- if LN > 0:
- LNString = Fore.CYAN+str(LN)
- print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
- if LN < 0:
- LNString = Fore.RED+str(LN)
- print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
- for i in timeTaken[-5:]:
- i = int(i)
- x += i
- n += 1
- Minute = 1
- AvgTimeTakenFilled = round(x / n, 2)
- if x > 60:
- Hour = AvgTimeTakenFilled // 60
- Minute = round(AvgTimeTakenFilled - (Hour*60), 2)
- print('\nAvg Time Taken until Filled, Hours: [',Hour,'] Minutes: [',Minute,']\n')
- else:
- if highs_Found > 0 or lows_Found >0:
- print(Fore.WHITE+'$%s' % ticker, '%s Min File' % candleDur, '[Insufficient Accuracy Data]'+Style.RESET_ALL)
- print(Fore.RED+'Lows Found: ',lows_Found)
- print(Fore.CYAN+'Highs Found: ',highs_Found)
- AbsolutePriceRange = abs(Close_Price - t_Price) + abs(Close_Price - opp_Target)
- percent_in_range = 100-(100*round(abs(Close_Price - t_Price) / AbsolutePriceRange, 3))
- print('Direction: %s' % range_ref_String+Style.RESET_ALL)
- print('Last Price: [$',Close_Price,']','Found Price: [$',FoundPrice,']')
- print('Range Price: [$',r_Price,']', 'Opposite Range: [$',opp_Range,']')
- print('Percent in Range: [',percent_in_range,'%]')
- LN = round(100*(Close_Price - FoundPrice) / Close_Price, 2)
- print(Fore.WHITE+'Found: '+foundDate)
- if LN > 0:
- LNString = Fore.CYAN+str(LN)
- print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
- if LN < 0:
- LNString = Fore.RED+str(LN)
- print(Fore.WHITE+'% Change Since Found: '+Style.RESET_ALL+LNString,'%'+Style.RESET_ALL)
- print('\n')
- #
- # '''Title = 'DATE Time MIV Liq Change Volume LiqFlowPrice VolLiqPrice | Liq/$Flow '
- # print(Title)
- #
- #
- #
- #
- #
- #
- # for i in MIVList[1:]:
- # counter += 1
- # Date = i[0]
- # military_time = i[1]
- # MIV = i[2]
- # Liq_Change = i[3]
- # Volume = i[4]
- # LiqFlowPrice = i[5]
- # VolLiqPrice = i[6]
- # LiqFlow = i[7]
- #
- # if MIV < 0:
- # print(Fore.CYAN,i,Style.RESET_ALL)
- # if MIV > 0:
- # print(Fore.RED,i,Style.RESET_ALL)'''
- # xMIV += abs(MIV)
- # xLiq += abs(Liq_Change)
- # xVol += Volume
- # xLFP += LiqFlow
- # xVolLiq += VolLiqPrice
- #
- # avgMIV = xMIV / counter
- # avgLiqChange = xLiq / counter
- # avgVol = xVol / counter
- # avgLFP = xLFP / counter
- # avgVolLiq = xVolLiq / counter
- # if abs(MIV) > avgMIV:
- # MIV_String = str(Fore.YELLOW+MIV+Style.RESET_ALL)
- # if abs(Liq_change) > avgLiqChange:
- # Liq_changeString = str(Fore.YELLOW+Liq_changeString+Style.RESET_ALL)
- # if Volume > avgVol:
- # VolumeString = str(Fore.YELLOW+Volume+Style.RESET_ALL)
- # if LiqFlowPrice > avgLFP:
- # LiqFlowPriceString = str(Fore.YELLOW+LiqFlowPrice+Style.RESET_ALL)
- # if VolLiqPrice > avgVolLiq:
- # VolLiqPriceString = str(Fore.YELLOW+VolLiqPriceString+Style.RESET_ALL)
- # if LFP > avgLFP:
- # LFPString = str(Fore.YELLOW+LFP+Style.RESET_ALL)
- # else:
- # print(Fore.WHITE,i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement