Group Details Private

administrators

Member List

  • RE: Issue with positions when live trading

    Sorry, I don't know how I can help. Let me quote from above

    @CooleRnax said in Issue with positions when live trading:

    I use custom broker for bitfinex

    That's the key. Your custom broker has to let the engine know there are open trades. Because trades start with an opening order, you need to create fake orders that will trigger the start of a trade if you want to restart with an open position.

    posted in General Code/Help
  • RE: Multiple Timeframes with Multiple Datafeeds

    @Rumen-Nenov said in Multiple Timeframes with Multiple Datafeeds:

    For multiple datafeeds however, looks like backtrader includes both the 5 min and daily timeframes in same set of feeds (self.datas)

    For a single data feed too. Each and every data feed is present in the self.datas iterable, exactly in the order in which they were introduced in the system.

    @Rumen-Nenov said in Multiple Timeframes with Multiple Datafeeds:

    and from here on I cannot pass the data I want to the relevant indicators

    And why not? They are data feeds, they can be passed to any indicator.

    @Rumen-Nenov said in Multiple Timeframes with Multiple Datafeeds:

    Not only this but the daily data also messes around with my intraday indicators.

    Exactly how? This would be the first time.

    @Rumen-Nenov said in Multiple Timeframes with Multiple Datafeeds:

    for i, d1 in enumerate(self.data1):

    Sorry but self.data1 is a data feed and not and array of data feeds. This is for sure not in the documentation. It seems you assume that daily data feeds get magically all packed inside self.data1. No.

    See here for what self.data1 means: Docs - Platform Concepts

    What you need is to have a convention for the addition order of the data feeds to cerebro. If you add a 5-min / 1-day data feeds per instrument, you can use something like for i in range(0, len(self.datas), 2), where self.datas[i]will have the5-minfeed andself.datas[i + 1]will have the1-day` feed.

    posted in General Code/Help
  • RE: Update on position gains

    There is code to check the position in the post you linked.

    posted in General Code/Help
  • RE: Plotting

    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)

    posted in General Code/Help
  • 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

    Something as

    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.

    Try then:

    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.

    posted in General Code/Help
  • RE: Adding MA to Equity Curve

    @Mango-Loco said in 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[0] = 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 Nan values.

    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.

    posted in General Code/Help
  • RE: How to ignore 2 headers in a GenericCSV

    The subclass from @vladisld does for sure work.

    You may also read the file with pandas.read_csv, skip what you need and pass it to Cerebro as a PandasData feed.

    posted in General Code/Help
  • RE: StringIO Object to DataFeed

    @Jenel-Videos said in StringIO Object to DataFeed:

    data = btfeed.GenericCSVData(
    dataname=d["FETBTC"].getvalue(),

    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
    
    posted in General Code/Help
  • RE: Multiple Symbols in one CSV file

    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

    posted in General Code/Help
  • 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:

    @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.

    posted in General Code/Help
});