Without really understanding what you mean with "rates", it seems the value of your asset moves around 1.14-1.15 with a very small variation.
The variation is so small that matplotlib changes the representation to accommodate such a small variation, indicating the reference value at the top with 1.145
You will have to dig in the matplotlib documentation to understand how this may be changed.
Ended up with just a small change that 'fixes' the issue for me (probably not the best fix of cause):
diff --git a/backtrader/feeds/ibdata.py b/backtrader/feeds/ibdata.py
index ab3c184..84cff62 100644
@@ -408,7 +408,7 @@ class IBData(with_metaclass(MetaIBData, DataBase)):
'''request real-time data. checks cash vs non-cash) and param useRT'''
- if self.contract is None:
+ if self.contract is None or self._state == self._ST_LIVE:
By the way ... in all cases it's a very bad idea to go All-In (no, All-In is not the new black)
If you use futures and try to go All-In, the slightest move against your entry price will have your broker closing your position until you meet the margin again (read the documentation from your broker), which means you can no longer 100% recover.
Use proper position sizing.
You have to indicate the position in which column each field is and which fields are not present (with -1)
In your loading example not a single column is specified and the code tries to find the values in the default column ordering (datetime, OHLCV)
In any case, your data is NOT tick data. Your data is bid/ask, which isn't the same. You have to choose in which fields you want to load the data.
One comment that I see.
I believe that we can remove the parameter on timeframe in stockkwargs so that it becomes as follows since we will be resampling the data anyway later on
stockkwargs = dict(
rtbar=False, # use RealTime 5 seconds bars
historical=True, # only historical download
qcheck=0.5, # timeout in seconds (float) to check for events
fromdate=datetime.datetime(2019, 9, 24), # get data from..
todate=datetime.datetime(2019, 9, 25), # get data from..
latethrough=False, # let late samples through
tradename=None # use a different asset as order target
Re: Daily Resample Data
The problem is solved after I remove timeframe and compression parameter in getdata().
Can I ask why would that resolve the problem?
Is the inclusion of parameters, timeframe and compression, in ibstore.getdata() redundant if I were to specify a value for rtbar?
See below correct code.
import backtrader as bt
import datetime as dt
class Test_Strategy (bt.Strategy):
def next (self):
def log (self, text):
print (self.data.datetime.datetime(0),": ", text)
if __name__ == '__main__':
ibstore = bt.stores.IBStore (host = '127.0.0.1', clientId = 100, port = 7497)
data = ibstore.getdata (dataname = 'GBP.USD-CASH-IDEALPRO',
rtbar = False,
historical = True,
fromdate = dt.datetime (2019,4,25),
todate = dt.datetime(2019,10,26),
cerebro = bt.Cerebro()
cerebro.resampledata (data, timeframe = bt.TimeFrame.Days, compression = 1)
Your strategy is not defined when being unpickled in a slave process due to the "strange" ordering in your code.
I would suggest you look at the sample and use a conventional ordering, with "declarations" first and "execution" afterwards.
@ab_trader said in IndexError: array index out of range:
If you need some advice, you may want to share full script. Not just arbitrary piece of it.
Indeed ... although this time
@YELNAr said in IndexError: array index out of range:
if (self.data.close < self.sma and self.data.close
It should be clear that looking into the future is still a very difficult feat.
@MuSaCN said in How to change the index of indicator to the opposite ？:
Is there any other way besides the function ?
I don't know which "function" you may be referring to, because there is no such function.
But if you want to change the semantics of backtrader about what's the past and what's the future, you should consider using something else.
The semantics were chosen to stay as close as possible to the semantics of "last" in Python (i.e.: -1) and have a pivot point around 0 (Python has no notion of a pivot for an array)
@ab_trader said in Error at the end of backtesting if I use resampled data:
Seems you didn't set time frame and compression for baseline data. If I remember correctly bts default time frame is Daily. So you are re-sampling from days to intraday now.
Thanks! It worked!
timeframe, compression = GRANULARITY[freqs]
data = bt.feeds.PandasData(