live trading daily timeframe



  • Hi,

    I have some questions regarding live trading. It will be great if anyone can help!

    1. Am i right that the live trading data feed, e.g. for IB, works by having the IBStore data feed repeatedly check (like a while loop) whether new data has been delivered? And if new data is available, it pushes them to cerebro strategy?
    2. I am interested in using backtrader for backtesting and subsequently as an expert adviser (as opposed to live trading). I am looking at an hourly timeframe. The workflow I have in mind is as follows:
      a) Run a wrapper for pulling hourly data from some source (e.g. Oanda v20)
      b) Run cerebro using data from (a) and plot time series of asset prices, my indicators, and buy-sell observers for visualization
      c) Send email notification if buy/sell signal is generated in last bar
      d) encapsulate (a)-(c) in a loop which runs hourly
      • check that a new bar has been retrieved in (a)

    Are there better ways of doing this? I am looking at this rather than ibtest.py because my platform is not supported. Also because I am not trading at seconds/minute timeframes, I think I can manage trading manually at hourly timeframes.

    Thanks!!


  • administrators

    @skw said in live trading daily timeframe:

    1. Am i right that the live trading data feed, e.g. for IB, works by having the IBStore data feed repeatedly check (like a while loop) whether new data has been delivered? And if new data is available, it pushes them to cerebro strategy?

    No. TWS generates events and when the appropriate ones are received by the store, they are passed on to the data feed. Cerebro receives a further notification from the feeds and then invokes the strategy, which is free to use the data or not.

    @skw said in live trading daily timeframe:

    1. I am interested in using backt...
      Are there better ways of doing this?

    Seems a reasonable way of achieving your target. There is no canonical or "better way".



  • Thank you for the quick reply!

    I am also thinking of writing a custom live data feed. I read in one of the threads (https://community.backtrader.com/topic/543/how-to-create-live-data-feed) that "Docs Binary Datafeed Development" is relevant. You mentioned a method "live" which is not currently in the document. I tried looking through the code base at github (specifically feeds/oanda.py) but could only find the method "islive". Is this the method you were referring to? Does setting this to return True stops Cerebro from terminating like a backtest but stay idle and wait for further notification from the feeds?


  • administrators

    Yes, islive is the actual method which is defined in the base class for all feeds.

    If the method returns True, the engine will switch into runonce=False (i.e.: it will run everything step by step, because the expectation is that the actual end of the stream for a live feed is unknown). There is no practical difference between backtesting and live trading. The engine doesn't really know. Only if all data feeds say that no more data will be delivered, will the engine terminate.


  • administrators

    Actually what you are probably looking for is the parameter sessionend to the data feeds. The default value is None. If you specifically set it with a datetime.time(hh, mm, ss) instance, that will be used as the time also for daily bars.

    mydata = DataFeedCls(dataname='xxx', sessionend=datetime.time(hh, mm, ss))
    

Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.