nevermind, I figured it out
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
C
Latest posts made by choc2015
-
Quickstart guide code not working
I'm trying to get the backtester quickstart guide code working however currently all it does is nothing is print the portfolio value and some line buffer object:
Starting Portfolio Value: 100000.00
<backtrader.linebuffer.LineBuffer object at 0x0000019BB31D1670> dataclose
Here is my code:from __future__ import(absolute_import, division, print_function, unicode_literals) import datetime import os.path import sys import btoandav20 import backtrader as bt below50 = False above150 = False class TestStrategy(bt.Strategy): params50 = 50 params100 = 100 params150 = 150 def __init__(self): self.dataclose = self.datas[0].close print(self.dataclose, "dataclose") self.ema50 = bt.indicators.EMA(self.data[0], period = self.params50) self.ema100 = bt.indicators.EMA(self.data[0], period = self.params100) self.ema150 = bt.indicators.EMA(self.data[0], period = self.params150) def log(self, txt, dt=None): dt = dt or self.datas[0].datetime.date(0) print(f'{dt.isoformat()}{txt}') def next(self): self.log('Close:' , self.dataclose[0]) print('Close:', self.dataclose[0]) if self.data[0] <= self.ema50 +0.0003 and below50 == False: below50 = True if self.data[0] < self.ema150 and below50 == True: below50 = True if self.data[0] == self.ema150 -0.0003: above150 = True if self.data[0] >= self.ema50 and above150 == True: above150 = False if below50 == True and self.data[0] >= self.ema50: self.log('BUY CREATE, %.2F' % self.data[0]) self.buy() if __name__ == '__main__': cerebro = bt.Cerebro() #modpath = os.path.dirname(os.path.abspath(sys.argv[0])) #datapath = ('C:\\Users\\admin1\\anaconda3\\Menu\\csv_data\\1m-2021-02-01') data = bt.feeds.YahooFinanceCSVData(dataname='C:\\Users\\admin1\\anaconda3\\EURUSD.csv') #data_resampled = data.resample(timeframe=bt.TimeFrame.Minutes, compression=1) cerebro.adddata(data) cerebro.broker.setcash(100000.0) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.addstrategy(TestStrategy) cerebro.run() print('Final Portfolio Value: %.2f' %cerebro.broker.getvalue())
-
help getting data from oanda
Hello, I dont understand how I'm supposed to get data from oanda I set up my code similar to the quickstart guide but I'm struggling to actually get the program to make trades and I havent been able to actually get data. Can anyone help me with this? Here is the current way my code recieves data.
data = btoandav20.stores.oandav20store.OandaV20Store.getdata(dataname="EUR_USD") data_resampled = data.resample(timeframe=bt.TimeFrame.Minutes, compression=1) cerebro.adddata(data) cerebro.broker.setcash(100000.0) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.addstrategy(TestStrategy) cerebro.run()
its currently saying array out of index when referencing self.data[0].close