There is code to check the position in the post you linked.
Posts made by backtrader
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
The chart above is what you get in
Jupyter. I personally don't use it but
iplot=Falseworked when it was developed. I will have a look (in any case you are still constrained by the
Jupyterconfiguration for the aspect)
RE: plotting indicators that are inside another indicator
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)
SMAdoesn'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.datafor plotting purposes and be plotted in an own sub-graph.
RE: Adding MA to Equity Curve
def __init__(self): self.l.ma = bt.indicators.MovingAverageSimple(self.l.value, period=20) def next(self): self.l.value = self._owner.broker.getvalue()
There is a problem there. The moving average is calculated before you set the value. Which means that the moving average is constantly calculating the average of
You need to define an indicator which stores the value of the broker. You instantiate it just before the moving average and then do the moving average of that.
RE: 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
RE: Multiple Symbols in one CSV file
Your best approach:
Load it with
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
The last step can actually be forfeited, because you end up with several
pandas.DataFrameswhich can be directly fed to
RE: Trailing stop fired by High and Low instead of Close price
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:
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.
StopTraildoesn'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.
RE: Continuous working of limit orders
The first NOTIFY ORDER shows the calculated bollinger.lines.top from the previous discrete bar (the Limit order.price of 254.37602), which I assume is filled at 254.37602 now that the current close is 260.0. We have a short trade.
See, "assuming" when you are trading is a dangerous business. Instead of relying on what you passed, why don't check the actual execution price?
order.executed.price. It's in the documents. There is an entire section with several entries about order.
For excample Docs - Order Creation/Execution
which is using the Close prices, not the Limit order.price.
That's again your assumption. Check the right things and you will see that the calculations are right.
How do I get the code to use the order.price
You CANNOT. You can say that you don't want an execution which is worst than the
Limitprice, but it can be different if the price gaps in your favor.
RE: Same entry, different exits
With OOP the obvious approach is having a base class which defines the entry setup (invoked for example with method name
That same class defines the logic to call another method for the strategy, for example:
Subclasses of the base class have all the same entry method, but override and have different logics for the