@backtrader thank you for the guidance. I read the documentation but I struggle to implement it.
Why it seems pointless and illogical? In fact many brokers give you a choice what to include in the bracket order (stop only, limit only, or stop/limit). What is wrong in having a stop to prevent you from excessive loss while working your own logic about the closing conditions.
@backtrader said in Crossover indicator doesn't plot as expected:
Thanks for reply, according to your suggestion, I added plotmaster=self.data. But the adx_crossover still don't show up at the bottom.
import backtrader as bt
params = (
self.sma_fast = bt.talib.SMA(self.datas.close, timeperiod=self.p.pfast)
self.sma_slow = bt.talib.SMA(self.datas.close, timeperiod=self.p.pslow)
self.sma_crossover = bt.ind.CrossOver(self.sma_fast, self.sma_slow)
self.adx = bt.talib.ADX(self.datas.high, self.datas.low, self.datas.close)
self.adx_fast = bt.talib.SMA(self.adx, timeperiod=self.p.pfast)
self.adx_slow = bt.talib.SMA(self.adx, timeperiod=self.p.pslow)
self.adx_crossover = bt.ind.CrossOver(
self.adx_fast, self.adx_slow, plotmaster=self.data, plot=True, subplot=True)
if not self.position:
if self.sma_crossover > 0:
if self.sma_crossover < 0:
if __name__ == '__main__':
cerebro = bt.Cerebro()
datapath = 'datas/orcl-1995-2014.txt'
# Create a Data Feed
data = bt.feeds.YahooFinanceCSVData(
# Do not pass values before this date
fromdate=datetime.datetime(2000, 1, 1),
# Do not pass values before this date
todate=datetime.datetime(2000, 12, 31),
# Do not pass values after this date
@backtrader OK thanks for response :) It has nothing to do with me expecting an AI to have belief in other AI entities or any of whatever you're trying to imply.
It has to do with the simple expectation--of a framework--that a BUY order executed for a given symbol will have a position size reflected in any query on that same symbol, regardless of whatever timeframe the orders or queries are being executed on. It is counter-intuitive to operate in any other way.
I will work around that, and I will see what Alpaca has to say and post back here if its relevant. Cheers!
The resampler filter wouldn't know what to do with extra lines (add, max, min, sub, multiply, take the 3rd one, take the last ...) and works only with the fields for which it has a rule, the standard ones.
You can create a 2nd data feed, assign your desired fields to open (keep 1st), high/low (keep max/min), close (keep last), volume (add) and use that resampled to match the timeframe of your master data feed.
Or create your own resampling filter.
After further check - it seems the problem was caused by my own changes. The warning messages were pushed by mistake to the same message queue that was used by 'reqContractDetails'.
My apologies. Please ignore this topic.
Thank you for your answer.
I am used to MT4. The operation habit of order affects my understanding.
After understanding, I can think of an application: Calculate used margin
if order.status in [order.Completed]:
for bit in order.executed.exbits:
self.marginUsed += bit.openedvalue - bit.closedvalue
If this is not right, please give me suggestions and thank you again for your reply
@Ross-Coates said in TypeError: __init__() got an unexpected keyword argument 'size':
In any case let me point out that those three ticks (i.e ' vertical) are not backticks as in `
You may want to directly copy the ticks from the announcement at the top of the forum
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Just enumerate through the datas in a pythonic way by referencing d. if len(d) > self.lenofdata....
If you reference self.datas you'll only ever access self.datas. Each timeframe and datafeed will have its own data in datas. datas datas datas... datas[n]. Also self.len has the potential for a keyword conflict. I suggest following backtraders example above.
Have you reviewed the multiple datas example? You might want to search that out.
I don't think that this is the only thing you are missing. To initialize the value is very easy:
self.l.f1 = 0.0
But here is couple other items to correct:
you call undefined variables such as self.f1 or self.pf - this is the main reason of the error returned
this in the next()
self.v3 = bt.ind.Lowest(self.pf, period=self.p.length)
self.v4 = bt.ind.Highest(self.pf, period=self.p.length) - self.v3
.... self.v3 ....
.... self.v4 ....
Interesting. In your script you apply the indicator to the self.data0 ie 5 min data feed, but indicator itself works with the self.data1 which is daily bars. I would assume that self.addminperiod is also applied to minutes data feed, so you need lot to get 5 bars of daily data feed.
Try this (didn' run it by myself):
lines = ('dayHigh',)
params = (('period', 5),)
self.dayHigh = self.data.high[-self.p.period]
call in the strategy:
self.dayHigh = dummyIndicator(self.data1)
Hi, it should be compresssion = 15. Note: if your data is large, you may want to consider bt.feed.PandasDataDirect that seems to be faster than PandasData. Someone has conducted a perf analysis on this forum. you should be able to find easily. Cheers
Thanks a lot @Zachary-Harris
I've got the same error during live trading through IB (see my post here: https://community.backtrader.com/topic/642/iqfeed-store-and-feed-help-needed/12 ) and your fix seems to be working great.
This seems to be a pretty serious issue that should be fixed in the official source.
I just wonder why there are so little reports about it - it should have happen pretty often to everyone using backtrader for live trading.