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
- ref_Num = int(0)
- Liquidity = float()
- Balance = 1000
- prevPrice = float(1)
- Long = bool
- Short = bool
- LN = float()
- NewBalance = float(1)
- range_ref_Str = str()
- Highs_Found = int(0)
- Lows_Found = int(0)
- Highs_Filled = int(0)
- Lows_Filled = int(0)
- LowAccuracy = float()
- HighAccuracy = float()
- Start = bool
- Stop = bool
- tHigh = bool
- tLow = bool
- Filled = bool
- indent = str(' | ')
- prevPrice = float(1)
- prevFlow = float(1)
- prevVol = int(1)
- with open('/Users/King/iFiles/SPY1.csv', 'r') as csv_file:
- reader = csv.reader(csv_file)
- header = next(reader)
- for row in reader:
- 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
- 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 # Price Data Dictionary & RangeReference Dictionary # 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(HLCC*.003)
- Profit = 100*round(Close_Price - Open_Price, 2) / Open_Price
- if Money_Flow > 0:
- MIV_Index = round(100 * (f_Vol / prevVol) - 100 * ((Money_Flow * HLCC) / (prevFlow * prevPrice)), 3)
- prevPrice = Close_Price
- prevFlow = Money_Flow
- prevVol = f_Vol
- if abs(M_Price - HLCC) >= criteria:
- Range_Clause = True
- diff = M_Price - HLCC
- r_Price = HLCC + diff
- t_Price = r_Price + diff
- else:
- Range_Clause = False
- range_ref_Str = ('')
- if Range_Clause == True:
- 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 r_Price > HLCC and Range_Clause == True:
- if MIV_Index < 0:
- tHigh = True
- tLow = False
- Filled = False
- indent = ' '
- HighrefStr = Fore.CYAN+"HIGH TARGET"
- '''print(indent,HighrefStr)
- time.sleep(2)'''
- Highs_Found += 1
- if r_Price < HLCC and Range_Clause == True:
- tHigh = False
- tLow = True
- Filled = False
- Lows_Found += 1
- indent = ' '
- LowrefStr = Fore.RED+"LOW TARGET"
- '''print(indent,LowrefStr)
- time.sleep(2)'''
- if tHigh == True and Range_Clause == False:
- LN += Profit
- '''print(' '+Fore.CYAN,LN,'%'+Style.RESET_ALL)'''
- if Filled == False:
- if High_Price >= r_Price:
- Filled = True
- Highs_Filled += 1
- '''time.sleep(1)
- print(Fore.CYAN+'HIGH RANGE FILLED'+Style.RESET_ALL)'''
- else:
- Filled = False
- if tLow == True and Range_Clause == False:
- LN += Profit*-1
- '''print(' '+Fore.RED,LN,'%'+Style.RESET_ALL)'''
- if Filled == False:
- if Low_Price <= r_Price:
- Filled = True
- Lows_Filled += 1
- '''time.sleep(1)
- print(Fore.YELLOW+'LOW RANGE FILLED'+Style.RESET_ALL)'''
- else:
- Filled = False
- '''time.sleep(.001)
- print(Date, Close_Price)'''
- if Lows_Found > 0 or Highs_Found > 0:
- if Lows_Filled > 0 or Highs_Filled > 0:
- LowAccuracy = 100*round(Lows_Filled / Lows_Found, 2)
- HighAccuracy = 100*round(Highs_Filled / Highs_Found, 2)
- print('Lows Found: ',Lows_Found,indent+'Lows Filled: ',Lows_Filled,indent+'Low Accuracy',LowAccuracy,'%')
- print('Highs Found: ',Highs_Found,indent+'Highs Filled: ',Highs_Filled,indent+'High Accuracy: ',HighAccuracy,'%')
- TotalReturn = Profit*100
- print('Total Return: ',TotalReturn,'%')
Advertisement
Add Comment
Please, Sign In to add comment