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/

    Change BuySell to "trade arrows" in charts #213

    General Code/Help
    2
    7
    5104
    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.
    • B
      backtrader administrators last edited by

      From Issue #213


      Example

      This style of buy/sell annotation is much more common in literature then the current one implemented, which often gets overlapped by candlesticks and become difficult to see.

      So basically it's just a matter of moving the arrows "out of the way" to not get overlapped by the candle bars.

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

        https://www.backtrader.com/docu/observers-reference.html?highlight=buysell#backtrader.observers.BuySell

        Adjust the bardist parameter to move the arrows further away.

        You can also change the matplotlib markers to draw any arrow you like.

            plotlines = dict(
                buy=dict(marker='^', markersize=8.0, color='lime',
                         fillstyle='full', ls=''),
                sell=dict(marker='v', markersize=8.0, color='red',
                          fillstyle='full', ls='')
            )
        
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          An example here: https://www.backtrader.com/blog/posts/2016-12-10-buysellarrows/buysellarrows.html

          0_1481363074095_upload-a4ed598c-a608-4f3d-b417-013942a3a937

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

            As far as I can see the arrows do not appear when working with tick data (at least not in my figures). Is that intended behaviour or possibly a bug?

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

              Tick Data is a definition which seem to be controversial. Are you referring to:

              • OHLC bars in which the 4 components have the same value?

              • A bid/ask pair?

              • A single tick value?

              With no reference code/information, any statement would be a simple guess.

              1 Reply Last reply Reply Quote 0
              • hans
                hans last edited by backtrader

                I created a simple csv with: datetime, price and volume (from a csv with bid/sell info). High, low, open and close point to the same price field:

                data = bt.feeds.GenericCSVData(
                        dataname='datafile.csv',
                        fromdate=datetime.datetime(2010, 1, 1),
                        todate=datetime.datetime(2010, 12, 31),
                        nullvalue=0.0,
                        dtformat=('%Y-%m-%d %H:%M:%S.%f'),
                        datetime=0, 
                        high=1, low=1, open=1, close=1, 
                        volume=2,
                        openinterest=-1
                    )
                
                1 Reply Last reply Reply Quote 0
                • B
                  backtrader administrators last edited by

                  They are plotted. The problem arises because matplotlib makes assumptions about situations where the difference between the top and bottom of a plot is too small and could lead to problems.

                  The plot below plots the BuySell observer on a different axis to make it clear: I am here. But cannot be seen with the data. The right axis ticks (Y) show values like 3.5 and the top of the axis (already inside the observer) indicates that everything has to be multiplied by 1000 (3.065e3)

                  The scale is wrong obviously because it goes from 0 to 3.065

                  Probably your case too.

                  0_1482755765918_upload-8b6b42a3-d34f-4f90-94df-55dc163bf2ad

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