Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Develop a Strategy From Scratch With Pure Backtesting or Live Trading Template?

    General Code/Help
    3
    7
    1645
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NewestTrader
      NewestTrader last edited by NewestTrader

      Hi,

      I would like to use backtrader for live trading.

      My preferred broker would be OANDA and I will use the backtrader-oandav20 project to connect with OANDA.

      The supplied sample test script oandav20test.py in backtrader-oandav20 is quite close to the samples/oandatest/oandatest.py script in backtrader.

      Presently, I wonder how I can develop my strategy code. I would like to run it first with synthetic csvdata that reflects what I hope the real (live) price data will look like in reality.

      My question is:

      Should I take a simple pure backtesting example like one of the quickstart tutorial to start with, because I can rely on the csv data import easily?

      Or is it better to use oandatest.py respectively oandav20test.py, because then I am closer to real live trading already? And if I go this way: how would I have to call oandatest.py to feed it with pure csvdata?

      Thanks in advance!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        The logic for the strategy has nothing to do with brokers or data feeds and that means you can choose the path that best suits you.

        1 Reply Last reply Reply Quote 0
        • NewestTrader
          NewestTrader last edited by

          @newesttrader said in Develop a Strategy From Scratch With Pure Backtesting or Live Trading Template?:

          oandatest

          Hi,

          thanks for your reply.

          But I just struggle with the way I have to call samples/oandatest/oandatest.py to do a pure csv based backtesting.

          B 1 Reply Last reply Reply Quote 0
          • D
            dasch last edited by

            If you want to do backtesting with csv files, you mostly won't need to use oanda.

            Set up your csv feeds, no need to use oanda broker or oanda store. You would use the oanda store for fetching data from oanda and do live trading with oanda with your strategies.

            data = btfeed.GenericCSVData(
                dataname='OANDA_EUR_USD_M5_MID.csv',
                name="primary",
                nullvalue=0.0,
                headers=True,
                timeframe=bt.TimeFrame.Minutes,
                compression=5,
                dtformat=('%Y-%m-%dT%H:%M:%S.%fZ'),
                datetime=0,
                time=-1,
                open=1,
                high=2,
                low=3,
                close=4,
                volume=5,
                openinterest=-1
            )
            cerebro.adddata(data)
            
            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators @NewestTrader last edited by

              @newesttrader said in Develop a Strategy From Scratch With Pure Backtesting or Live Trading Template?:

              But I just struggle with the way I have to call samples/oandatest/oandatest.py to do a pure csv based backtesting.

              Because that is a sample meant to test the functionalities in Oanda and not a one-script-fits-all-for-universal-backtesting-and-trading-machine-for-printing-free-money-with-no-effort*

              There are tens of samples. Pick one to have your skeleton or create your own. As stated above: the logic in a Strategy class is independent of data feeds and brokers, be it for backtesting or trading.

              1 Reply Last reply Reply Quote 0
              • D
                dasch last edited by

                You may find some starting information in the backtrader documentation:

                https://www.backtrader.com/docu/operating.html

                Basically, backtrader is doing all the magic, the store / broker just executes the requests created in backtrader or feeds backtrader with data coming in.

                If you do backtesting, you would use a different broker than in live trading.

                When working on a strategy, you could set up a backtesting script, which is using csv files. this data is pushed to your strategy when backtrader is running.
                When your strategy creates a buy / sell / close request, this will be processed in the broker. If you do not do live trading, then you will use a different broker (if you use the oanda broker on backtesting, it would send the orders to oanda with prices from backtesting, not the live prices).

                That is one of the great things about backtrader, being so flexible.

                NewestTrader 1 Reply Last reply Reply Quote 0
                • NewestTrader
                  NewestTrader @dasch last edited by

                  thanks for your comments and input!

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors