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/

    Best Approach for Live-Trading With Cheat on Open

    General Code/Help
    cheat on open live trading
    2
    12
    2595
    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

      Hi,

      I would like to use Oanda V20 live trading on a relative long timeframe base. Perhaps something like candlesticks with a 4 hour resolution.

      My approach would be something like:
      After I identified the relevant criteria in next(), I would like to wait for the next open price and - dependent from that value - to execute an order.

      As far as I understood it, a prerequesite would be to set

      cerebro = bt.Cerebro(cheat_on_open=True)
      

      and to wait in

      def prenext(self):
      

      that the live broker is triggering this method.

      My question is:

      is this really foreseen?

      If not: what would be an alternative?

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

        @newesttrader said in Best Approach for Live-Trading With Cheat on Open:

        After I identified the relevant criteria in next(), I would like to wait for the next open price and - dependent from that value - to execute an order.
        As far as I understood it, a prerequesite would be to set

        You have understood it wrong. cheat-on-open carries the cheat tag because you are cheating. And you cannot obviously cheat when you are running against a live broker.

        @newesttrader said in Best Approach for Live-Trading With Cheat on Open:

        If not: what would be an alternative?

        You have to use intraday data with the lowest possible resolutions to try to be active during the opening tick.

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

          @backtrader

          Re: Best Approach for Live-Trading With Cheat on Open

          thanks for your reply.

          So, in my opinion, it would be cool to get a trigger for every new price tick that get's available from the live broker - even in between ohlc candlesticks.

          But I assume that this would be somehow contradictionary to the general concept of the platform.

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

            @newesttrader said in Best Approach for Live-Trading With Cheat on Open:

            So, in my opinion, it would be cool to get a trigger for every new price tick that get's available from the live broker - even in between ohlc candlesticks.
            But I assume that this would be somehow contradictionary to the general concept of the platform.

            Sorry but that a very bold statement. backtrader is 100% event based framework for your strategy, be it during backtesting or live trading. The data events are the calls to your next method.

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

              @backtrader said in Best Approach for Live-Trading With Cheat on Open:

              Sorry but that a very bold statement. backtrader is 100% event based framework for your strategy, be it during backtesting or live trading. The data events are the calls to your next method.

              Thanks for your message.

              And just as a loud-spoken thought:

              Would it make sense (for my very own use case), that I extend backtrader-oandav20 by myself and inherit / implement some method that I wrote myself that gives me a trigger for every price action in a method that could get the name ontick()?

              Or is the right place to do this by myself in backtrader directly?

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

                Why go such complex lengths instead of having a data feed which has a Ticks timeframe?

                NewestTrader 1 Reply Last reply Reply Quote 1
                • NewestTrader
                  NewestTrader @backtrader last edited by

                  @backtrader said in Best Approach for Live-Trading With Cheat on Open:

                  Why go such complex lengths instead of having a data feed which has a Ticks timeframe?

                  I thought that http://developer.oanda.com/rest-live-v20/instrument-df/ would not offer that

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

                    as only this CandlestickGranularity would be valid:

                    Value	Description
                    S5	5 second candlesticks, minute alignment
                    S10	10 second candlesticks, minute alignment
                    S15	15 second candlesticks, minute alignment
                    S30	30 second candlesticks, minute alignment
                    M1	1 minute candlesticks, minute alignment
                    M2	2 minute candlesticks, hour alignment
                    M4	4 minute candlesticks, hour alignment
                    M5	5 minute candlesticks, hour alignment
                    M10	10 minute candlesticks, hour alignment
                    M15	15 minute candlesticks, hour alignment
                    M30	30 minute candlesticks, hour alignment
                    H1	1 hour candlesticks, hour alignment
                    H2	2 hour candlesticks, day alignment
                    H3	3 hour candlesticks, day alignment
                    H4	4 hour candlesticks, day alignment
                    H6	6 hour candlesticks, day alignment
                    H8	8 hour candlesticks, day alignment
                    H12	12 hour candlesticks, day alignment
                    D	1 day candlesticks, day alignment
                    W	1 week candlesticks, aligned to start of week
                    M	1 month candlesticks, aligned to first day of the month
                    
                    1 Reply Last reply Reply Quote 0
                    • B
                      backtrader administrators last edited by

                      You are not asking for Candlesticks, you want to ask for Ticks. 4 components (OHLC) vs only 1 (the tick itself)

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

                        @backtrader said in Best Approach for Live-Trading With Cheat on Open:

                        You are not asking for Candlesticks, you want to ask for Ticks. 4 components (OHLC) vs only 1 (the tick itself)

                        ok, thanks.

                        So it seems that I have to supply the --replay parameter in oandav20test.py.
                        With that, during replay I get that candlestick granularity which I supplied in

                                "--timeframe", "Seconds",
                                "--compression", "30",
                        

                        .

                        During livetrading, I seem to get a trigger in next() whenever a trade happened in the oanda backend.

                        (unfortunately, I cannot verify this with the original oandatest.py, as I have a v20 account)

                        So then I would do the aggregation to the timeframe I need (e.g. 4 hour candlestick) based on the ticks I get during live trading.

                        And I have another question: is it perhaps even possible to get ticks also during the replay of the past periods (when the script is started)?

                        Thanks in advance, Mastro backtrader! :-)

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

                          @newesttrader said in Best Approach for Live-Trading With Cheat on Open:

                          So it seems that I have to supply the --replay parameter in oandav20test.py.

                          I don't know. What you need is a data source which is tick based. You said you wanted to be notified of each price change. There should be no need to replay anything for that data feed.

                          @newesttrader said in Best Approach for Live-Trading With Cheat on Open:

                          And I have another question: is it perhaps even possible to get ticks also during the replay of the past periods (when the script is started)?

                          It would seem pointless ... given that you cannot trade during that periods and the amount of ticks you would have to download would be enormous.

                          NewestTrader 1 Reply Last reply Reply Quote 1
                          • NewestTrader
                            NewestTrader @backtrader last edited by

                            @backtrader said in Best Approach for Live-Trading With Cheat on Open:

                            So it seems that I have to supply the --replay parameter in oandav20test.py.

                            I don't know. What you need is a data source which is tick based. You said you wanted to be notified of each price change. There should be no need to replay anything for that data feed.

                            Hi,

                            with samples/ibtest/ibtest.py I did some tests with Interactive Brokers livetrading. These are the results:

                            ibtest.py --data0 EUR.USD-CASH-IDEALPRO --timeframe Seconds --compression 30 --port 7497 --no-rightedge

                            ***** DATA NOTIF: LIVE
                            LIVE, Data0, 0962, 736801.8864360515, 2018-04-17T17:16:28.074845, 1.23699, 1.23699, 1.23699, 1.23699, 0, 0, 1.23703
                            LIVE, Data0, 0963, 736801.8866241798, 2018-04-17T17:16:44.329133, 1.237, 1.237, 1.237, 1.237, 0, 0, 1.237046
                            LIVE, Data0, 0964, 736801.8866485074, 2018-04-17T17:16:46.431042, 1.2371, 1.2371, 1.2371, 1.2371, 0, 0, 1.237034
                            LIVE, Data0, 0965, 736801.8866486517, 2018-04-17T17:16:46.443504, 1.237, 1.237, 1.237, 1.237, 0, 0, 1.237002
                            LIVE, Data0, 0966, 736801.886811497, 2018-04-17T17:17:00.513344, 1.23694, 1.23694, 1.23694, 1.23694, 0, 0, 1.237006
                            LIVE, Data0, 0967, 736801.8868541777, 2018-04-17T17:17:04.200952, 1.23693, 1.23693, 1.23693, 1.23693, 0, 0, 1.236994
                            LIVE, Data0, 0968, 736801.8869536915, 2018-04-17T17:17:12.798944, 1.23694, 1.23694, 1.23694, 1.23694, 0, 0, 1.236982
                            LIVE, Data0, 0969, 736801.8871321745, 2018-04-17T17:17:28.219872, 1.23691, 1.23691, 1.23691, 1.23691, 0, 0, 1.236944
                            LIVE, Data0, 0970, 736801.8871946137, 2018-04-17T17:17:33.614623, 1.23699, 1.23699, 1.23699, 1.23699, 0, 0, 1.236942
                            LIVE, Data0, 0971, 736801.8871946996, 2018-04-17T17:17:33.622046, 1.23698, 1.23698, 1.23698, 1.23698, 0, 0, 1.23695
                            LIVE, Data0, 0972, 736801.8871947962, 2018-04-17T17:17:33.630394, 1.23699, 1.23699, 1.23699, 1.23699, 0, 0, 1.236962
                            LIVE, Data0, 0973, 736801.8872731669, 2018-04-17T17:17:40.401621, 1.23698, 1.23698, 1.23698, 1.23698, 0, 0, 1.23697
                            LIVE, Data0, 0974, 736801.8872752264, 2018-04-17T17:17:40.579562, 1.23699, 1.23699, 1.23699, 1.23699, 0, 0, 1.236986
                            LIVE, Data0, 0975, 736801.8874047493, 2018-04-17T17:17:51.770338, 1.237, 1.237, 1.237, 1.237, 0, 0, 1.236988
                            

                            ibtest.py --data0 EUR.USD-CASH-IDEALPRO --timeframe Seconds --compression 30 --port 7497 --resample

                            ***** DATA NOTIF: LIVE
                            LIVE, Data0, 0962, 736801.8892361111, 2018-04-17T17:20:30.000000, 1.23689, 1.23706, 1.23689, 1.23701, 0.0, 0, 1.2369620000000001
                            LIVE, Data0, 0963, 736801.8895833333, 2018-04-17T17:21:00.000000, 1.23702, 1.23703, 1.237, 1.23702, 0.0, 0, 1.23696
                            LIVE, Data0, 0964, 736801.8899305556, 2018-04-17T17:21:30.000000, 1.23701, 1.23707, 1.23699, 1.23707, 0.0, 0, 1.236974
                            LIVE, Data0, 0965, 736801.8902777778, 2018-04-17T17:22:00.000000, 1.23708, 1.23708, 1.23696, 1.23702, 0.0, 0, 1.237004
                            

                            ibtest.py --data0 EUR.USD-CASH-IDEALPRO --timeframe Seconds --compression 30 --port 7497 --replay

                            ***** DATA NOTIF: LIVE
                            LIVE, Data0, 0962, 736801.8905911663, 2018-04-17T17:22:27.076771, 1.23694, 1.23694, 1.23694, 1.23694, 0.0, 0, 1.2369999999999999
                            LIVE, Data0, 0962, 736801.890625, 2018-04-17T17:22:30.000000, 1.23694, 1.23694, 1.23694, 1.23694, 0.0, 0, 1.2369999999999999
                            LIVE, Data0, 0963, 736801.8908331305, 2018-04-17T17:22:47.982471, 1.23693, 1.23693, 1.23693, 1.23693, 0.0, 0, 1.236982
                            LIVE, Data0, 0963, 736801.8908331448, 2018-04-17T17:22:47.983708, 1.23693, 1.23696, 1.23693, 1.23696, 0.0, 0, 1.236988
                            LIVE, Data0, 0963, 736801.8908638399, 2018-04-17T17:22:50.635766, 1.23693, 1.23698, 1.23693, 1.23698, 0.0, 0, 1.236992
                            LIVE, Data0, 0963, 736801.8908640771, 2018-04-17T17:22:50.656264, 1.23693, 1.23699, 1.23693, 1.23699, 0.0, 0, 1.236994
                            LIVE, Data0, 0963, 736801.8908658416, 2018-04-17T17:22:50.808718, 1.23693, 1.237, 1.23693, 1.237, 0.0, 0, 1.236996
                            LIVE, Data0, 0963, 736801.8908685311, 2018-04-17T17:22:51.041084, 1.23693, 1.23701, 1.23693, 1.23701, 0.0, 0, 1.236998
                            LIVE, Data0, 0963, 736801.8908700076, 2018-04-17T17:22:51.168654, 1.23693, 1.23702, 1.23693, 1.23702, 0.0, 0, 1.2369999999999999
                            LIVE, Data0, 0963, 736801.8908825091, 2018-04-17T17:22:52.248782, 1.23693, 1.23702, 1.23693, 1.23701, 0.0, 0, 1.236998
                            LIVE, Data0, 0963, 736801.890961202, 2018-04-17T17:22:59.047850, 1.23693, 1.23702, 1.23693, 1.23702, 0.0, 0, 1.2369999999999999
                            LIVE, Data0, 0963, 736801.8909623256, 2018-04-17T17:22:59.144933, 1.23693, 1.23704, 1.23693, 1.23704, 0.0, 0, 1.237004
                            LIVE, Data0, 0963, 736801.8909629615, 2018-04-17T17:22:59.199871, 1.23693, 1.23705, 1.23693, 1.23705, 0.0, 0, 1.2370059999999998
                            LIVE, Data0, 0963, 736801.890965801, 2018-04-17T17:22:59.445203, 1.23693, 1.23705, 1.23693, 1.23704, 0.0, 0, 1.237004
                            LIVE, Data0, 0963, 736801.8909722222, 2018-04-17T17:23:00.000000, 1.23693, 1.23705, 1.23693, 1.23704, 0.0, 0, 1.237004
                            LIVE, Data0, 0964, 736801.8909756911, 2018-04-17T17:23:00.299714, 1.23705, 1.23705, 1.23705, 1.23705, 0, 0, 1.2369999999999999
                            LIVE, Data0, 0964, 736801.8909989573, 2018-04-17T17:23:02.309913, 1.23705, 1.23705, 1.23704, 1.23704, 0.0, 0, 1.236998
                            LIVE, Data0, 0964, 736801.8910004616, 2018-04-17T17:23:02.439886, 1.23705, 1.23705, 1.23703, 1.23703, 0.0, 0, 1.236996
                            

                            It seems to me, that the --replay parameter really delivers what I need:

                            • tick based during live streaming
                            • after each candlestick timeframe, len(self.data0) increases by one and also the last call to next() for that block seems to comprise consistent values for OHLC for the whole candlestick.
                            1 Reply Last reply Reply Quote 0
                            • 1 / 1
                            • First post
                              Last post
                            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors