Problem solved, using numpy to calculate and feed the average of account value.
lines = ('value', 'ma')
params = dict(ma_len=100)
plotinfo = dict(plot=True, subplot=True)
self.l.value = self._owner.broker.getvalue()
self.l.ma = np.average(self.l.value.get(size=self.p.ma_len))
If you're not referencing backfilling with your pandas data cache routine, and your issue is simply that no data for one security is available and thus ALL the feeds don't start, then this thread might be helpful: https://community.backtrader.com/topic/476/trades-don-t-happen-until-way-late-no-they-don-t
AFAIU, upon resampling new bars are built aggregating the information from the originals bars of the feed with a smaller timeframe. Those new bars have no knowledge about the non-standard attributes of the originals bars ( only datetime, high, low, open, close, volume and openinterest fields are processed), nor they know anything about how to aggregate such fields. This may explain the behavior you saw.
After further testing, the above 'fix' appears not to be good enough. The problem is with connection reset events:
<error id=-1, errorCode=1100, errorMsg=Connectivity between IB and Trader Workstation has been lost.>
In case of connection resets, the state of the data feeds seems not to be reset and stays in _ST_LIVE state.
Here the code from ibdata.py IBData class:
# (vladisld) ... code ommitted for clarity
if self._state == self._ST_LIVE:
# (vladisld) ... code ommitted for clarity
elif msg == -1100: # conn broken
# Tell to wait for a message to do a backfill
# self._state = self._ST_DISCONN
self._statelivereconn = self.p.backfill
Original code (without fix) would still reconnect the data feeds in that state. However with my 'fix' the reconnect will not work anymore.
Will update if a better fix is found. Any suggestion is appreciated of cause.
@ab_trader You are correct on all counts! I did in fact expect that behaviour.
As a trader, if Mondays close in the 10yr T-Note Future is 129'05 and I then work a limit sell at 129'10 for Tuesdays session. If I see the Tuesday close is 129'15, I know I was filled at 129'10. But as I write this, I see this is not a reasonable expectation when using a generic backtester that can take any data as a feed.
But, as you correctly point out, passing OHLC feed in resolves the problem. Muchas gracias.
@backtrader Thanks. One day I'll find it easy...
There is no such thing as old or new.
The chart you show below is what you get when executing on the console (which in most cases will use tkAgg)
The chart above is what you get in Jupyter. I personally don't use it but iplot=False worked when it was developed. I will have a look (in any case you are still constrained by the Jupyter configuration for the aspect)
The plotting code doesn't do recursion and doesn't see see the embedded indicators. The solutions you attempted as shown in the documentation page you linked are for the indicators and operations which happen directly in the strategy code.
The only trick I can offer you (not tested)
Create your indicator.
Create moving averages of period 1 which use your embedded indicators as data
my_indicator = MyIndicator(....)
emb_ind_1 = bt.ind.SMA(my_indicator.embedded_indicator1, period=1)
Now, the SMA doesn't know still where to plot itself, because the indicators won't be plotted.
emb_ind_1.plotinfo.plotmaster = self.data
emb_ind_1.plotinfo.subplot = True
which says that they should be considered indicators of self.data for plotting purposes and be plotted in an own sub-graph.
@Jenel-Videos said in StringIO Object to DataFeed:
data = btfeed.GenericCSVData(
After creating file (a pseudo-file) actually, why do you pass a string instead of the file-like object which you have already created?
The documentation says it:
Specific parameters (or specific meaning):
- ``dataname``: The filename to parse or a file-like object
Your best approach:
Load it with pandas.read_csv
Separate by symbol by using, for example, the clause where (that is, you create a mask that considers only the name of a ticker)
Write the result of each mask to a separate csv file.
The last step can actually be forfeited, because you end up with several pandas.DataFrames which can be directly fed to cerebro via PandasData
Don't take me for rude, but you say "trailing stop fired ...." and I could also say "trailing stop not fired ...".
There is no indication as to what you are doing, what's happening, if that is actually the right behavior.
Even if what you say would make some sense ... the following is completely wrong:
@fede3u said in Trailing stop fired by High and Low instead of Close price:
How can I modify the logic of the bt.Order.StopTrail.
You can also go and try to modify how the markets work. It may be easier and it will probably fit what you have backtested with something you have modified to fit your wishes and not to try to model how things work in the reality.
If StopTrail doesn't do what you expect, these are the possible reasons:
You don't know how such an order works in real markets
You do, but it's not the order type which fits what you try to model, but you have still chosen to do it.
Imho: very wrong way to approach your backtesting.
@ab_trader I don't agree your opinion,but I try my best to use english.The reason which I use chinese,maybe @Jingsi is a chinese,who can speak chinese more accurately. just as two persons who speaks english,they have a trip to Japan,when they communicate,you let them use Japanese?