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/

    Buy/sell and P&L indicators plotted incorrectly

    General Code/Help
    6
    14
    1157
    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.
    • G
      genkisushijai last edited by

      Hi all.

      I am running a backtest strategy on 2 data feeds in Cerebro, and have the following problems.

      • In the 2 data feed version, the default Buy/Sell indicators (i.e. the ones in stdstats) are NOT in the correct location, i.e. indicators are NOT on the price line. They are in right location for 1 data feed version.

      • In the 2 data feed version, the P&L dots are all blue (regardless if profit, or loss), whereas with 1 data feed, P&L dots are blue (if profit) and red (if loss)..

      • There are new dark green, downward-facing triangles in the 2 data feed version.

      2 data feed version:

      alt text

      1 data feed version:

      alt text

      Here is the relevant portions of my code. How could I fix these 3 issues? Thanks!!

      data = btfeeds.GenericCSVData(
        name='8545',
        dataname='csv/8545_20190801 to 20201009.csv',
        nullvalue=0.0,
        dtformat=('%m/%d/%y %H:%M'),
        datetime=0, # this, and the following correspond to which "column" datetime, open, etc appear in .csv file
        open=1,
        high=2,
        low=3,
        close=4,
        volume=5,
        openinterest=-1,
        headers=True,
        timeframe=bt.TimeFrame.Minutes #needed for intraday minute data, see https://community.backtrader.com/topic/1704/genericcsvdata-does-not-take-time-only-takes-date/8
        #tz=pytz.timezone('America/Toronto') # List of all timezones here: https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568
      )
      
      data2 = btfeeds.GenericCSVData(
        name='901',
        dataname='csv/901_20190801 to 20201009.csv',
        nullvalue=0.0,
        dtformat=('%m/%d/%y %H:%M'),
        datetime=0, # this, and the following correspond to which "column" datetime, open, etc appear in .csv file
        open=1,
        high=2,
        low=3,
        close=4,
        volume=5,
        openinterest=-1,
        headers=True,
        timeframe=bt.TimeFrame.Minutes #needed for intraday minute data, see https://community.backtrader.com/topic/1704/genericcsvdata-does-not-take-time-only-takes-date/8
        #tz=pytz.timezone('America/Toronto') # List of all timezones here: https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568
      )
      
      #===================================
      # Execute backtest and strategy
      #===================================
      # Load strategy .py files
      module = importlib.import_module('strategies.' + strategyName, strategyName) # Assuming the strategy .py files are put in the "strategies" folder
      strategy = getattr(module, strategyName)
      
      # Load commission .py files
      module = importlib.import_module('commission_schemes.' + commissionName, commissionName) # Assuming the commission .py files are put in the "commission_schemes" folder
      commissionScheme = getattr(module, commissionName)
      
      # To run strategy
      if __name__ == '__main__': 
      
        #===================================
        # Cerebro
        #===================================
      
        # Create a cerebro entity:
        # If you don't want the default 3 plots plotted (price, buy/sell P&L, capital), set stdstats=False. See: https://www.backtrader.com/docu/observers-and-statistics/observers-and-statistics/
        # cerebro = bt.Cerebro(stdstats=False)    
          cerebro = bt.Cerebro()
      
      
        # Add a strategy or Optimize a strategy.
          cerebro.addstrategy(strategy) 
          
          # Add the Data Feed to Cerebro:
          cerebro.adddata(data)
          cerebro.adddata(data2)
      
          # Calculate num of stocks to buy / sell every transaction
          cerebro.addsizer(bt.sizers.PercentSizer, percents=strategy.params.percents)
      
          # Set our desired cash start
          cerebro.broker.setcash(startingBalance)
      
          # Commissions:
          # commissions can be used in 2 ways: (1) importing a commission scheme, (2) using default commission scheme
          # 1. Importing:
          cerebro.broker.addcommissioninfo(commissionScheme())  
          # 2. default commission schemes:    
          # commissionPercentage: 0.1% ... divide by 100 to remove the %
          #cerebro.broker.setcommission(commission=commissionPercentage)
          #cerebro.broker.addcommission(commission=commissionPercentage)
      
      
          strategyResults = cerebro.run()
      
          # Plot graph
          cerebro.plot()
      
          # Store results in variable, export to CSV
          print(strategyResults[0].broker.getvalue())
      
      A 1 Reply Last reply Reply Quote 0
      • A
        ab_trader @genkisushijai last edited by

        @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

        In the 2 data feed version, the default Buy/Sell indicators (i.e. the ones in stdstats) are NOT in the correct location, i.e. indicators are NOT on the price line. They are in right location for 1 data feed version.

        it was number of topics on the forum with this issue. i can advice to play with barplot and bardist parameters Docs - Observers Refs- BuySell

        @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

        In the 2 data feed version, the P&L dots are all blue (regardless if profit, or loss), whereas with 1 data feed, P&L dots are blue (if profit) and red (if loss)..

        in case of several data feeds the color means the data feed, but not profit or loss. Blue markers are markers for 1st data feed.

        @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

        There are new dark green, downward-facing triangles in the 2 data feed version.

        this is second data feed markers

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        G 1 Reply Last reply Reply Quote 0
        • G
          genkisushijai @ab_trader last edited by

          @ab_trader said in Buy/sell and P&L indicators plotted incorrectly:

          @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

          In the 2 data feed version, the default Buy/Sell indicators (i.e. the ones in stdstats) are NOT in the correct location, i.e. indicators are NOT on the price line. They are in right location for 1 data feed version.

          it was number of topics on the forum with this issue. i can advice to play with barplot and bardist parameters Docs - Observers Refs- BuySell

          Thanks for the response.

          I have tried changing the barplot and bardist to different values (ex: barplot = False, bardist = 0.00, etc). Changing barplot and bardist doesn't fix my problem though (the Buy/Sell indicators are still in the wrong location for 2 data feed version).

          Do you know any other ways to fix this issue?

          @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

          In the 2 data feed version, the P&L dots are all blue (regardless if profit, or loss), whereas with 1 data feed, P&L dots are blue (if profit) and red (if loss)..

          in case of several data feeds the color means the data feed, but not profit or loss. Blue markers are markers for 1st data feed.

          @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

          There are new dark green, downward-facing triangles in the 2 data feed version.

          this is second data feed markers

          Not sure what you mean (what markers do those dark green triangles represent?), can you pls clarify?

          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

            @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

            Not sure what you mean (what markers do those dark green triangles represent?), can you pls clarify?

            Blue markers represent profits/losses for trades made on the 1st data feed, green markers represent profits/losses for trades made on the 2nd data feed. Markers located above zero line represent profits, markers located below zero line represent losses. Hope it is clear this time.

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            G 1 Reply Last reply Reply Quote 0
            • G
              genkisushijai @ab_trader last edited by

              @ab_trader Thanks ab_trader.

              Does anyone else know how to fix the Buy/Sell indicators in incorrect position, in the 2 data feed scenario?

              1 Reply Last reply Reply Quote 0
              • G
                genkisushijai last edited by

                @backtrader any advice you may have?

                1 Reply Last reply Reply Quote 0
                • hghhgghdf dfdf
                  hghhgghdf dfdf last edited by

                  @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

                  @ab_trader Thanks ab_trader.

                  Does anyone else know how to fix the Buy/Sell indicators in incorrect position, in the 2 data feed scenario?

                  pass oldtrades=True to cerebro

                  G 1 Reply Last reply Reply Quote 0
                  • G
                    genkisushijai @hghhgghdf dfdf last edited by

                    @hghhgghdf-dfdf said in Buy/sell and P&L indicators plotted incorrectly:

                    @genkisushijai said in Buy/sell and P&L indicators plotted incorrectly:

                    @ab_trader Thanks ab_trader.

                    Does anyone else know how to fix the Buy/Sell indicators in incorrect position, in the 2 data feed scenario?

                    pass oldtrades=True to cerebro

                    Hi, thanks for the suggestion. I tried this but same result, the Buy/Sell indicators are in incorrect position in 2 data feed scenario

                    Any other potential fixes?

                    1 Reply Last reply Reply Quote 0
                    • A
                      ab_trader last edited by

                      Try oldbuysell=True with cerebro. According to docs -

                      If stdstats is True and observers are getting automatically added, this switch controls the main behavior of the BuySell observer

                      • False: use the modern behavior in which the buy / sell signals are plotted below / above the low / high prices respectively to avoid cluttering the plot
                      • True: use the deprecated behavior in which the buy / sell signals are plotted where the average price of the order executions for the given moment in time is. This will of course be on top of an OHLC bar or on a Line on Cloe bar, difficulting the recognition of the plot.
                      • If my answer helped, hit reputation up arrow at lower right corner of the post.
                      • Python Debugging With Pdb
                      • New to python and bt - check this out
                      G 1 Reply Last reply Reply Quote 0
                      • G
                        genkisushijai @ab_trader last edited by

                        @ab_trader Hey I tried this as well, but no luck... any other advice you may have? thanks again :)

                        1 Reply Last reply Reply Quote 0
                        • G
                          genkisushijai last edited by

                          @backtrader wondering if you had any advice as well? thanks!

                          Derrick Karimi 1 Reply Last reply Reply Quote 0
                          • Derrick Karimi
                            Derrick Karimi @genkisushijai last edited by

                            @genkisushijai +1 , I have the exact same issue

                            M 1 Reply Last reply Reply Quote 0
                            • M
                              moles last edited by

                              We have years of experience in this industry and have built up the reputation as one of the most trusted suppliers in the UK, Europe and worldwide. We appreciate that there are many different options available to you for sourcing your Medication, so please take a minute to read what sets us apart from the rest.

                              We maintain the highest of standards, not only in the production of our own products, but also in the selection of all products we add to our range. We offer the most reliable operation and sell at very affordable prices. We ship worldwide and offer one of the best services discreet delivery to our customer's address. Please request a quote.

                              By emailing us via …… ordermcatonline@gmail.com
                              Whatsapp……. +31645084874
                              Or visit of websites either through one of the links below:

                              Buy research chemicals online: https://dmtforsale.us/

                              buy mephedrone,
                              Buy Mephedrone online,
                              Buy Mephedrone plant food,
                              Mephedrone for sale,
                              MKAT for sale,
                              4MMC for sale,

                              Buy research chemicals online: https://dmtforsale.us/

                              Amphetamine powder for sale: https://dmtforsale.us/product/amphetamine-powder-for-sale/

                              Buy fentanyl powder: https://dmtforsale.us/product/buy-fentanyl-powder/

                              Buy GHB online: https://dmtforsale.us/product/buy-ghb-online/

                              Buy JWH 250 online: https://dmtforsale.us/product/buy-jwh-250-online/

                              Buy Mephedrone online: https://dmtforsale.us/product/buy-mephedrone-4-mmc/

                              Buy butylone powder: https://dmtforsale.us/product/butylone/

                              https://dmtforsale.us/product/buy-6cladba-online/
                              https://dmtforsale.us/product/tabernanthe-iboga/
                              https://dmtforsale.us/product/amphetamine-powder-for-sale/
                              https://dmtforsale.us/product/buphedrone/
                              https://dmtforsale.us/product/butylone-bk-mbdb/
                              https://dmtforsale.us/product/butylone/
                              https://dmtforsale.us/product/buy-fentanyl-powder/
                              https://dmtforsale.us/product/buy-ghb-online/
                              https://dmtforsale.us/product/buy-jwh-250-online/
                              https://dmtforsale.us/product/buy-mephedrone-4-mmc/
                              https://dmtforsale.us/product/ephedrine-hcl-powder/
                              https://dmtforsale.us/product/buy-nembutal-pentobarbital-solution/
                              https://dmtforsale.us/product/nembutal-powder/‎
                              https://dmtforsale.us/product/buy-a-pvp-online/
                              https://dmtforsale.us/product/buy-adb-butinaca-online/
                              https://dmtforsale.us/product/buy-4f-adb-online/
                              https://dmtforsale.us/product/iboga-root-bark/
                              https://dmtforsale.us/product/iboga-seeds/
                              https://dmtforsale.us/product/ibogaine-hcl/
                              https://dmtforsale.us/product/mdma-ecstacy-molly/
                              https://dmtforsale.us/product/dmt-nn-dmt/
                              https://dmtforsale.us/product/5-meo-dmt/
                              https://dmtforsale.us/product/buy-4-aco-dmt/
                              https://dmtforsale.us/product/liquid-lsd/
                              https://dmtforsale.us/product/lsd-gel-tabs/
                              https://dmtforsale.us/product/dmt-vape-pen/
                              https://dmtforsale.us/product/albino-penis-envy/
                              https://dmtforsale.us/product/psilocybe-baeocystis/

                              1 Reply Last reply Reply Quote 0
                              • M
                                MildJoe @Derrick Karimi last edited by

                                @derrick-karimi Same issue here, anyone found a solution?
                                It seems that the dates for the trades are wrong when they are plotted. They are not wrong when printed from the strategy, so maybe something is wrong date-related in the trade- or buysell-observer?

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