hell all,
no matter how many examples i try, i can't seem to get my columns to use.
i must have an error in what exactly i am calling to use on the bt.indicators because they don't match with the values in my dataframe...
and i think processing would be a lot faster if i only needed to calculate from my already known values..
this is for monitoring right now....
sorry, again, i tried pasting but it came out like below..
here is my code..
data = pd.read_sql("""
select datetime, open, high, low, close, volume, sma_20, sma_50, ema_8, mom, lin_ang
from stock_price_15
where symbol = :symbol
and sma_50 is not 0
and datetime > '2021-01-26'
and strftime('%H:%M:%S', datetime) >= '09:30:00'
and strftime('%H:%M:%S', datetime) < '16:00:00'
order by datetime asc
""", conn, params={"symbol": stock['symbol']}, index_col='datetime', parse_dates=['datetime'])
data = bt.feeds.PandasDirectData(dataname=data)
cerebro.adddata(data)
#CREATES THIS DF
== Analysing A ==
open high low close volume sma_20 sma_50 ema_8 mom
datetime
2021-01-26 09:30:00 125.50 125.95 124.550 125.040 92435 125.072505 125.919682 125.203493 0
2021-01-26 09:45:00 125.09 125.16 124.430 125.005 88188 125.070255 125.887382 125.159384 0
2021-01-26 10:00:00 125.04 125.36 124.740 124.845 39486 125.055005 125.850682 125.089521 0
2021-01-26 10:15:00 124.82 125.29 124.630 125.210 29410 125.072005 125.819482 125.116294 0
2021-01-26 10:30:00 125.24 125.66 125.170 125.550 43447 125.119005 125.791882 125.212673 0
... ... ... ... ... ... ... ... ... ...
2021-01-28 10:45:00 121.18 121.68 121.180 121.400 40882 120.019275 121.871370 120.669654 0
2021-01-28 11:00:00 121.43 121.89 121.340 121.870 43707 120.081025 121.810170 120.936397 0
2021-01-28 11:15:00 121.87 122.04 121.390 121.640 53618 120.141025 121.746970 121.092753 0
2021-01-28 11:30:00 121.65 122.25 121.550 122.195 37105 120.213775 121.691670 121.337697 0
2021-01-28 11:45:00 122.25 122.67 122.115 122.500 54387 120.31
then.............
create a Strategy
class OpeningRangeBreakout(bt.Strategy):
#class TestStrategy(bt.Strategy):
params = (
dict(num_opening_bars=15)
)
def log(self, txt, dt=None):
''' Logging function for this strategy'''
if dt is None:
dt = self.datas[0].datetime.datetime(0)
print('%s, %s' % (dt, txt))
########## DEFINING THE TEMPLATE AND VARIABLES TO USE
def __init__(self):
self.dataclose = self.datas[0].close
self.opening_range_low = 0
self.opening_range_high = 0
self.opening_range = 0
self.bought_today = False
self.order = None
self.buyprice = None
self.buycomm = None
## ADD INDICATORS ###########
self.sma_20 = bt.indicators.SimpleMovingAverage(
self.datas[0], period=20)
self.sma_50 = bt.indicators.SimpleMovingAverage(
self.datas[0], period=50)
# Indicators for the plotting show
self.ema_8 = bt.indicators.ExponentialMovingAverage(self.datas[0], period=8)
def next(self):
######### THE CURRENT SESSION #########################################
current_bar_ = self.data.num2date(self.data.datetime[0])
previous_bar = self.data.num2date(self.data.datetime[-1])
two__bars_back = self.data.num2date(self.data.datetime[-2])
three_bars_back = self.data.num2date(self.data.datetime[-3])