| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
import statistics as st
import pandas as pd
import numpy as np
class test_stocks(QCAlgorithm):
def Initialize(self):
# User input list of stocks
self.user_list = ["TSLA"]
# User input for stop loss %
self.stop_loss_percent = 1
# User input for allowed operations
self.allowed_operations = 6
# Do we do the check the buy signal 1 minute check?
self.one_minute_check = True
# Do we do the check the buy signal 5 minute check?
self.five_minute_check = False
# Do we do the check the buy signal 5 minute index check?
self.five_minute_index_check = False
# Global variables
self.trade = False
self.data = None
self.tradebars = None
self.portions = 0.01 * (100/self.allowed_operations)
self.remaining_operations = self.allowed_operations
self.longoper_price = []
self.tickers = []
self.universe_items = []
self.final_list = []
self.five_minute_check_passed = []
self.one_minute_check_passed = []
self.five_minute_index_check_passed = False
self.p_average = 0
# Index
self.ndx = self.AddIndex("NDX", Resolution.Minute).Symbol
self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol
# QC settings
self.SetStartDate(2021, 10, 1)
self.SetCash(3000)
self.UniverseSettings.Resolution = Resolution.Second
self.UniverseSettings.ExtendedMarketHours = False # is that PRE - Market
# Subscribe to data for stocks in self.user_list
for ticker in self.user_list:
self.AddEquity(ticker, Resolution.Second, extendedMarketHours= False)
# Consolidators
self.minute_consolidators = {}
self.five_minute_consolidators = {}
# Indicators one minute
self.macd_one_minute = {}
self.vwap_one_minute = {}
self.stochastics_one_minute = {}
# Indicators five minute
self.macd_five_minute = {}
self.vwap_five_minute = {}
self.rsi_five_minute = {}
self.stochastics_five_minute = {}
# Stochastics indicator storage
self.stoch_K_minute_storage = {}
self.stoch_D_minute_storage = {}
self.stoch_K_five_minute_storage = {}
self.stoch_D_five_minute_storage = {}
# RSI indicator storage
self.rsi_minute_storage = {}
self.rsi_five_minute_storage = {}
# MACD indicator storage
self.macd_value_minute_storage = {}
self.macd_signal_minute_storage = {}
# VWAP indicator storage
self.vwap_minute_storage = {}
self.vwap_five_minute_storage = {}
# Close prices storage
self.minute_close_prices_storage = {}
self.five_minute_close_prices_storage = {}
## buy and sell??
#Start running buy and sell logic at 10 am
self.Schedule.On(self.DateRules.EveryDay("SPY"),
self.TimeRules.AfterMarketOpen("SPY", 30),
self.is_market)
## buy and sell??
#Stop running buy logic and sell at 3 pm
self.Schedule.On(self.DateRules.EveryDay("SPY"),
self.TimeRules.BeforeMarketClose("SPY", 60),
self.not_market)
def OnSecuritiesChanged(self, changes):
# No securities will be removed, so "pass"
for security in changes.RemovedSecurities:
pass
# Loop through added securities
for security in changes.AddedSecurities:
# If symbol not already in algorithm
if security.Symbol not in self.universe_items:
# Add to univere items
self.universe_items.append(security.Symbol)
# If symbol is NDX, we manually create consolidator and indicators
if security.Symbol == self.ndx:
# Create consolidator for NDX
five_minute_consolidator = TradeBarConsolidator(timedelta(minutes=5))
five_minute_consolidator.DataConsolidated += self.FiveMinuteBarHandler
self.SubscriptionManager.AddConsolidator(security.Symbol, five_minute_consolidator)
self.five_minute_consolidators[security.Symbol] = five_minute_consolidator
# Create stochastics for NDX
self.stochastics_five_minute[security.Symbol] = Stochastic(14, 3, 3)
self.RegisterIndicator(security.Symbol, self.stochastics_five_minute[security.Symbol], five_minute_consolidator)
# RSI storage
self.rsi_five_minute_storage[security.Symbol] = []
# Stochastics storage
self.stoch_K_five_minute_storage[security.Symbol] = []
self.stoch_D_five_minute_storage[security.Symbol] = []
# Five minute close prices storage
self.five_minute_close_prices_storage[security.Symbol] = []
# Minute close prices storage
self.minute_close_prices_storage[security.Symbol] = []
# If symbol is SPY, continue
elif security.Symbol == self.spy:
continue
# All other symbols
else:
# Add to tickers
self.tickers.append(security.Symbol)
# Minute consolidator
minute_consolidator = TradeBarConsolidator(timedelta(minutes=1))
minute_consolidator.DataConsolidated += self.MinuteBarHandler
self.SubscriptionManager.AddConsolidator(security.Symbol, minute_consolidator)
self.minute_consolidators[security.Symbol] = minute_consolidator
# Five minute consolidator
five_minute_consolidator = TradeBarConsolidator(timedelta(minutes=5))
five_minute_consolidator.DataConsolidated += self.FiveMinuteBarHandler
self.SubscriptionManager.AddConsolidator(security.Symbol, five_minute_consolidator)
self.five_minute_consolidators[security.Symbol] = five_minute_consolidator
# MACD
self.macd_one_minute[security.Symbol] = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential)
self.macd_five_minute[security.Symbol] = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential)
self.RegisterIndicator(security.Symbol, self.macd_one_minute[security.Symbol], minute_consolidator)
self.RegisterIndicator(security.Symbol, self.macd_five_minute[security.Symbol], five_minute_consolidator)
# VWAP
self.vwap_one_minute[security.Symbol] = VolumeWeightedAveragePriceIndicator(14)
self.vwap_five_minute[security.Symbol] = VolumeWeightedAveragePriceIndicator(14)
self.RegisterIndicator(security.Symbol, self.vwap_one_minute[security.Symbol], minute_consolidator)
self.RegisterIndicator(security.Symbol, self.vwap_five_minute[security.Symbol], five_minute_consolidator)
# Stochastics
self.stochastics_one_minute[security.Symbol] = Stochastic(14, 3, 3)
self.stochastics_five_minute[security.Symbol] = Stochastic(14, 3, 3)
self.RegisterIndicator(security.Symbol, self.stochastics_one_minute[security.Symbol], minute_consolidator)
self.RegisterIndicator(security.Symbol, self.stochastics_five_minute[security.Symbol], five_minute_consolidator)
# MACD storaage
self.macd_value_minute_storage[security.Symbol] = []
self.macd_signal_minute_storage[security.Symbol] = []
# RSI storage
self.rsi_minute_storage[security.Symbol] = []
self.rsi_five_minute_storage[security.Symbol] = []
# Stochastics storage
self.stoch_K_minute_storage[security.Symbol] = []
self.stoch_D_minute_storage[security.Symbol] = []
self.stoch_K_five_minute_storage[security.Symbol] = []
self.stoch_D_five_minute_storage[security.Symbol] = []
# VWAP storage
self.vwap_minute_storage[security.Symbol] = []
self.vwap_five_minute_storage[security.Symbol] = []
# Close prices storage
self.five_minute_close_prices_storage[security.Symbol] = []
# Store last 50 minute close history data into minute prices storage
self.minute_close_prices_storage[security.Symbol] = []
def OnData(self, data):
# Check if it's market hours
if self.trade == True:
# Get data into global variable
self.data = data
# Get bars of data into global variable
self.tradebars = data.Bars
# Check if we haven't made any orders or we currently are not holding onto any stocks
if self.remaining_operations == self.allowed_operations:
# Check if user wants to do 5 minute index buy signal check
if self.five_minute_index_check == True:
# If latest NDX five minute RSI less than or equal to 35
if self.rsi_five_minute_storage[self.ndx][-1] <= 40:
# If latest NDX five minute stochK value less than or equal to 20 or stochD value less than or equal to 20
if self.stoch_K_five_minute_storage[self.ndx][-1] <= 20 or self.stoch_D_five_minute_storage[self.ndx][-1] <= 20:
# Switch five minute index buy signal check to True
self.five_minute_index_check_passed = True
# Loop through self.tickers
for i in self.tickers:
#Check if round of data contains data for ticker[i]
if not self.data.ContainsKey(i):
continue
#Check if item contains trade bar data
if not self.data.Bars.ContainsKey(i):
continue
# Check if user wants to do 1 minute buy signal check
if self.one_minute_check == True:
# If RSI of stock less than 30
if self.rsi_minute_storage[i][-1] <= 30:
# Get minute stoch D of stock 2 periods ago - minute stoch K of stock 2 periods ago
stochD_minus_stochK_two = abs(self.stoch_D_minute_storage[i][-2] - self.stoch_K_minute_storage[i][-2])
# Get minute stock D of stock 1 periods ago - minute stoch K of stock 1 periods ago
stochD_minus_stochK_one = abs(self.stoch_D_minute_storage[i][-1] - self.stoch_K_minute_storage[i][-1])
# Get minute stoch D of stock 3 periods ago - minute stoch K of stock 3 periods ago
stochD_minus_stochK_three = abs(self.stoch_D_minute_storage[i][-3] - self.stoch_K_minute_storage[i][-3])
# Compare difference
if stochD_minus_stochK_two > stochD_minus_stochK_one or stochD_minus_stochK_three > stochD_minus_stochK_two:
# Compare latest minute stoch K and stoch D values of stock with 20
if self.stoch_K_minute_storage[i][-1] <= 20 or self.stoch_D_minute_storage[i][-1] <= 20:
# If latest MACD value of stock less than 0
if self.macd_value_minute_storage[i][-1] < 0:
# If latest MACD signal value of stock less than 0
if self.macd_signal_minute_storage[i][-1] < 0:
# Compare macd value with macd signal value
if self.macd_value_minute_storage[i][-1] <= self.macd_signal_minute_storage[i][-1]:
# Get macd signal value - macd value of stock 2 periods ago
macd_signal_difference_two = abs(self.macd_signal_minute_storage[i][-2] - self.macd_value_minute_storage[i][-2])
# Get latest macd signal value - macd value of stock
macd_signal_difference = abs(self.macd_signal_minute_storage[i][-1] - self.macd_value_minute_storage[i][-1])
# Compare
if macd_signal_difference_two > macd_signal_difference:
# Add to list that stores stocks that pass buy signal one minute check
self.one_minute_check_passed.append(i)
# Check if user wants to do 5 minute buy signal check
if self.five_minute_check == True:
# If five minute RSI of stock less than or equal to 35
if self.rsi_five_minute_storage[i][-1] <= 35:
# If latest five minute stochK of stock less than 20
if self.stoch_K_five_minute_storage[i][-1] < 20:
# If latest five minute stochD of stock less than 20
if self.stoch_D_five_minute_storage[i][-1] < 20:
# Add to list that stores stocks that pass buy signal five minute check
self.five_minute_check_passed.append(i)
# Loop through stocks
for i in self.tickers:
# Check if user wants to do 1 minute buy signal check
if self.one_minute_check == True:
# Check if stock passed one minute buy signal check
if i in self.one_minute_check_passed:
# Add to final list
self.final_list.append(i)
# Check if user wants to do 5 minute buy signal check
if self.five_minute_check == True:
# Check if stock passed five minute buy signal check
if i in self.five_minute_check_passed:
# Check if one minute check enabled
if self.one_minute_check == True:
# Check if stock passed one minute check
if i not in self.final_list:
# Continue to next stock
continue
# If one minute check not enabled
else:
# Add to final list
self.final_list.append(i)
# If stock didn't pass five minute buy signal check
else:
# If stock in final list
if i in self.final_list:
# Remove from final list
self.final_list.remove(i)
# Check if user wants to do 5 minute index buy signal check
if self.five_minute_index_check == True:
# If five minute index buy signal check failed
if self.five_minute_index_check_passed == False:
# Clear final list
self.final_list.clear()
# Check length of final list
if len(self.final_list) > 0:
### Loop over all stocks??
## final_list = each stocks??
# Loop through final list to buy first stock
for i in self.final_list:
# Reduce remaining operations allocation
self.remaining_operations -= 1
# Buy stock
self.SetHoldings(i, self.portions)
# Update longoper price storage with current stock price
self.longoper_price.append(self.tradebars[i].Close)
# Update p_average
self.p_average = st.mean(self.longoper_price)
# Log purchase order submitted
self.Debug("First order for " + i.Value + " submitted.")
# Exit loop
break
# Reset signal variables
self.Reset_Signal_variables()
# Check if remaining operations less than allowed operations to run more buy signals
if self.remaining_operations < self.allowed_operations and self.remaining_operations > 0:
#Get invested items from portfolio
invested = [x.Key for x in self.Portfolio if x.Value.Invested]
# Get invested stock
stock = invested[0]
# Reduce remaining operations by 1
self.remaining_operations -= 1
self.MarketOrder(stock, 1)
# #Check if round of data contains data for ticker[i]
# if self.data.ContainsKey(stock):
# #Check if item contains trade bar data
# if self.data.Bars.ContainsKey(stock):
# # If latest RSI of stock is less than or equal to 30
# if self.rsi_minute_storage[stock][-1] <= 30:
# # If latest stoch K is less than 20 or latest stoch D less than 20
# if self.stoch_K_minute_storage[stock][-1] < 20 or self.stoch_D_minute_storage[stock][-1] < 20:
# # If latest macd less than 0
# if self.macd_value_minute_storage[stock][-1] < 0:
# # If latest macd signal less than 0
# if self.macd_signal_minute_storage[stock][-1] < 0:
# # If macd value less than macd signal value
# if self.macd_value_minute_storage[stock][-1] <= self.macd_signal_minute_storage[stock][-1]:
# # Get latest price
# current_last_price = self.tradebars[stock].Close
# # Check if latest price less than previous purchase price
# if current_last_price < ((1 - 0.0004) * self.longoper_price[-1]):
# # Reduce remaining operations by 1
# self.remaining_operations -= 1
# # Buy stock with portion allocated
# self.SetHoldings(stock, self.portions)
# # Store latest price
# self.longoper_price.append(current_last_price)
# # Get average of all prices stored
# self.p_average = st.mean(self.longoper_price)
# Check if we are currently invested, if so, run stop loss
if self.remaining_operations < self.allowed_operations and self.remaining_operations == 0:
#Get invested items from portfolio
invested = [x.Key for x in self.Portfolio if x.Value.Invested]
# Get invested stock
stock = invested[0]
#Check if round of data contains data for ticker[i]
if self.data.ContainsKey(stock):
#Check if item contains trade bar data
if self.data.Bars.ContainsKey(stock):
#Get last price
current_last_price = self.tradebars[stock].Close
# Stop loss check
if current_last_price < ((1 - (0.01 * self.stop_loss_percent)) * self.longoper_price[-1]):
#Sell stock
self.Liquidate()
#Reset variables
self.Reset_Variables()
self.Debug(" Sell signal 1 triggered" + str(self.Securities[stock].Close))
# Check if we are currently invested, if so, run sell logic 1
if self.remaining_operations < self.allowed_operations:
# Get invested items from portfolio
invested = [x.Key for x in self.Portfolio if x.Value.Invested]
# Get invested stock
stock = invested[0]
# Check if round of data contains data for ticker[i]
if self.data.ContainsKey(stock):
# Check if item contains trade bar data
if self.data.Bars.ContainsKey(stock):
# Last price
current_last_price = self.tradebars[stock].Close
# Pl longoper
pl_longoper_stock = self.p_average - current_last_price
# Check if minute RSI of stock greater than or equal to 70
if self.rsi_minute_storage[stock][-1] >= 70:
# Check if macd value greater than 0
if self.macd_value_minute_storage[stock][-1] > 0:
# Check if macd signal value greater than 0
if self.macd_signal_minute_storage[stock][-1] > 0:
# Check if macd greater than macd signal
if self.macd_value_minute_storage[stock][-1] >= self.macd_signal_minute_storage[stock][-1]:
#Sell stock
self.Liquidate()
#Reset variables
self.Reset_Variables()
self.Debug(" Sell signal 2 triggered" + str(self.Securities[stock].Close))
# Check if we are currently invested, if so, run sell logic 2
if self.remaining_operations < self.allowed_operations:
#Get invested items from portfolio
invested = [x.Key for x in self.Portfolio if x.Value.Invested]
#Get invested stock
stock = invested[0]
# Check if round of data contains data for ticker[i]
if self.data.ContainsKey(stock):
# Check if item contains trade bar data
if self.data.Bars.ContainsKey(stock):
# Last price
current_last_price = self.tradebars[stock].Close
# Latest minute VWAP value fo stock
vwap_latest = self.vwap_minute_storage[stock][-1]
# Check if latest minute VWAP greater than latest price
if vwap_latest > current_last_price:
# Check if latest price within range of VWAP
if current_last_price >= (0.955 * vwap_latest) and current_last_price <= (0.965 * vwap_latest):
#Sell stock
self.Liquidate()
#Reset variables
self.Reset_Variables()
self.Debug(" Sell signal 3 triggered" + str(self.Securities[stock].Close))
def MinuteBarHandler(self, sender, bar):
# Store minute close data
self.minute_close_prices_storage[bar.Symbol].append(bar.Close)
# Check length of close prices stored
if len(self.minute_close_prices_storage[bar.Symbol]) > 20:
# Get close prices into dataframe
df = pd.DataFrame(self.minute_close_prices_storage[bar.Symbol], columns = ["close"])
# Get rsi period
rsi_period = 14
# Get change
df["change"] = df["close"] - df["close"].shift(1)
# Get gain
df["gain"] = np.where(df["change"] >= 0, df["change"], 0)
# Get loss
df["loss"] = np.where(df["change"] <= 0, -1 * df["change"], 0)
# Get average gain
df["avg_gain"] = df["gain"].ewm(alpha = 1 / rsi_period, min_periods = rsi_period).mean()
# Get average loss
df["avg_loss"] = df["loss"].ewm(alpha = 1 / rsi_period, min_periods = rsi_period).mean()
# Get relative strength
df["rs"] = df["avg_gain"] / df["avg_loss"]
# Get relative strength index
df["rsi"] = 100 - (100 / (1 + df["rs"]))
# Save relative strength index to storage
self.rsi_minute_storage[bar.Symbol] = df["rsi"].to_list()
# Stoch
self.stoch_K_minute_storage[bar.Symbol].append(self.stochastics_one_minute[bar.Symbol].StochK.Current.Value)
self.stoch_D_minute_storage[bar.Symbol].append(self.stochastics_one_minute[bar.Symbol].StochD.Current.Value)
# MACD
self.macd_value_minute_storage[bar.Symbol].append(self.macd_one_minute[bar.Symbol].Current.Value)
self.macd_signal_minute_storage[bar.Symbol].append(self.macd_one_minute[bar.Symbol].Signal.Current.Value)
# VWAP
self.vwap_minute_storage[bar.Symbol].append(self.vwap_one_minute[bar.Symbol].Current.Value)
# Storage control
if len(self.stoch_K_minute_storage[bar.Symbol]) > 3:
self.stoch_K_minute_storage[bar.Symbol] = self.stoch_K_minute_storage[bar.Symbol][-3:]
self.stoch_D_minute_storage[bar.Symbol] = self.stoch_D_minute_storage[bar.Symbol][-3:]
self.macd_value_minute_storage[bar.Symbol] = self.macd_value_minute_storage[bar.Symbol][-3:]
self.macd_signal_minute_storage[bar.Symbol] = self.macd_signal_minute_storage[bar.Symbol][-3:]
self.rsi_minute_storage[bar.Symbol] = self.rsi_minute_storage[bar.Symbol][-3:]
self.vwap_minute_storage[bar.Symbol] = self.vwap_minute_storage[bar.Symbol][-3:]
self.minute_close_prices_storage[bar.Symbol] = self.minute_close_prices_storage[bar.Symbol][-50:]
def FiveMinuteBarHandler(self, sender, bar):
# If symbol is NDX
if bar.Symbol == self.ndx:
# Store minute close data
self.five_minute_close_prices_storage[bar.Symbol].append(bar.Close)
# Check length of five minute close prices stored
if len(self.five_minute_close_prices_storage[bar.Symbol]) > 20:
# Get close prices into dataframe
df = pd.DataFrame(self.five_minute_close_prices_storage[bar.Symbol], columns = ["close"])
# Get rsi period
rsi_period = 14
# Get change
df["change"] = df["close"] - df["close"].shift(1)
# Get gain
df["gain"] = np.where(df["change"] >= 0, df["change"], 0)
# Get loss
df["loss"] = np.where(df["change"] <= 0, -1 * df["change"], 0)
# Get average gain
df["avg_gain"] = df["gain"].ewm(alpha = 1 / rsi_period, min_periods = rsi_period).mean()
# Get average loss
df["avg_loss"] = df["loss"].ewm(alpha = 1 / rsi_period, min_periods = rsi_period).mean()
# Get relative strength
df["rs"] = df["avg_gain"] / df["avg_loss"]
# Get relative strength index
df["rsi"] = 100 - (100 / (1 + df["rs"]))
# Save relative strength index to storage
self.rsi_five_minute_storage[bar.Symbol] = df["rsi"].to_list()
# Stochastics
self.stoch_K_five_minute_storage[bar.Symbol].append(self.stochastics_five_minute[bar.Symbol].StochK.Current.Value)
self.stoch_D_five_minute_storage[bar.Symbol].append(self.stochastics_five_minute[bar.Symbol].StochD.Current.Value)
# Storage econtrol
if len(self.rsi_five_minute_storage[bar.Symbol]) > 3:
self.rsi_five_minute_storage[bar.Symbol] = self.rsi_five_minute_storage[bar.Symbol][-3:]
self.stoch_K_five_minute_storage[bar.Symbol] = self.stoch_K_five_minute_storage[bar.Symbol][-3:]
self.stoch_D_five_minute_storage[bar.Symbol] = self.stoch_D_five_minute_storage[bar.Symbol][-3:]
self.five_minute_close_prices_storage[bar.Symbol] = self.five_minute_close_prices_storage[bar.Symbol][-50:]
# If symbol not NDX
else:
# Store minute close data
self.five_minute_close_prices_storage[bar.Symbol].append(bar.Close)
# Check length of five minute close prices stored
if len(self.five_minute_close_prices_storage[bar.Symbol]) > 20:
# Get close prices into dataframe
df = pd.DataFrame(self.five_minute_close_prices_storage[bar.Symbol], columns = ["close"])
# Get rsi period
rsi_period = 14
# Get change
df["change"] = df["close"] - df["close"].shift(1)
# Get gain
df["gain"] = np.where(df["change"] >= 0, df["change"], 0)
# Get loss
df["loss"] = np.where(df["change"] <= 0, -1 * df["change"], 0)
# Get average gain
df["avg_gain"] = df["gain"].ewm(alpha = 1 / rsi_period, min_periods = rsi_period).mean()
# Get average loss
df["avg_loss"] = df["loss"].ewm(alpha = 1 / rsi_period, min_periods = rsi_period).mean()
# Get relative strength
df["rs"] = df["avg_gain"] / df["avg_loss"]
# Get relative strength index
df["rsi"] = 100 - (100 / (1 + df["rs"]))
# Save relative strength index to storage
self.rsi_five_minute_storage[bar.Symbol] = df["rsi"].to_list()
# Stoch
self.stoch_K_five_minute_storage[bar.Symbol].append(self.stochastics_five_minute[bar.Symbol].StochK.Current.Value)
self.stoch_D_five_minute_storage[bar.Symbol].append(self.stochastics_five_minute[bar.Symbol].StochD.Current.Value)
# VWAP
self.vwap_five_minute_storage[bar.Symbol].append(self.vwap_five_minute[bar.Symbol].Current.Value)
# Storage control
if len(self.rsi_five_minute_storage[bar.Symbol]) > 3:
self.rsi_five_minute_storage[bar.Symbol] = self.rsi_five_minute_storage[bar.Symbol][-3:]
self.stoch_K_five_minute_storage[bar.Symbol] = self.stoch_K_five_minute_storage[bar.Symbol][-3:]
self.stoch_D_five_minute_storage[bar.Symbol] = self.stoch_D_five_minute_storage[bar.Symbol][-3:]
self.vwap_five_minute_storage[bar.Symbol] = self.vwap_five_minute_storage[bar.Symbol][-3:]
self.five_minute_close_prices_storage[bar.Symbol] = self.five_minute_close_prices_storage[bar.Symbol][-50:]
def Reset_Variables(self):
self.remaining_operations = self.allowed_operations
self.buy_signal_one_minute = 0
self.buy_signal_five_minute = 0
self.buy_signal_five_minute_index = 0
self.longoper_price = []
self.p_average = 0
def Reset_Signal_variables(self):
self.final_list.clear()
self.five_minute_check_passed.clear()
self.one_minute_check_passed.clear()
self.five_minute_index_check_passed = False
def is_market(self):
self.trade = True
def not_market(self):
self.trade = False
self.Liquidate()
self.Reset_Variables()