Buy/sell and P&L indicators plotted incorrectly
-
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:
1 data feed version:
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())
-
-
@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
andbardist
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
-
@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
andbardist
parameters Docs - Observers Refs- BuySellThanks for the response.
I have tried changing the
barplot
andbardist
to different values (ex:barplot = False
,bardist = 0.00
, etc). Changingbarplot
andbardist
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?
-
@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.
-
@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?
-
@backtrader any advice you may have?
-
@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
-
@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?
-
Try
oldbuysell=True
withcerebro
. 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.
-
@ab_trader Hey I tried this as well, but no luck... any other advice you may have? thanks again :)
-
@backtrader wondering if you had any advice as well? thanks!
-
@genkisushijai +1 , I have the exact same issue
-
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/ -
@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?