I think the Chart functionality can be enhanced, for example, to visualize the process of back testing (just like the strategy tester in MT5), instead of show the chart only after the testing is done, so that it is easier to watch how the strategy works in each step from the chat.

Latest posts made by Meng Xiaofeng
-
RE: Backtrader 2.0?
-
RE: How to know the first index in the next function of indicator?
many thanks for anwser!
but still the question: is it possible to get the first index and use the index explicitly? -
How to know the first index in the next function of indicator?
Hi,
I am trying to make my own indicator in which i want to find which bar in the history is higher than current high.
how do I know which one is the first bar( -1, -2, -3 ....) so that the loop can have a end point?class MyInd(bt.Indicator): lines = ('example',) def next(self): for (i = -1; i > ?; i--) if self.data.high[i] > self.data.high[0]: distance = -i; break;
Thanks!
-
RE: Sell/Buy signal labels are missing in the plotting of forex data
Now I got your idea! didn't realise there is such buy/sell observer.
now i know that the backtrader has a very flexilbe design and love it more.Just a remark: can't the Sell/buy observer be a bit smarter so that it can always plot properly?
Thanks!
-
RE: Sell/Buy signal labels are missing in the plotting of forex data
it seems that it is because of the data in forex csv file: the number is too small,
it will work if i change the price to bigger values, such as from "000000;1.123210;1.123240;1.123200;1.123240;0"
to "000000;3210;3240;3200;3240;0".so it looks a bug in backtrader when handling precision of the price.
-
RE: Sell/Buy signal labels are missing in the plotting of forex data
@backtrader Hi sorry for the format issue, it's my first post and I have fixed it.
Could you have a look again?Thanks!
-
RE: Sell/Buy signal labels are missing in the plotting of forex data
@backtrader said in Sell/Buy signal icons are missing in the plot:
position as this
Wow, thanks for your quick reply!
The "buy/sell Icons" i meant is as following (in the black circle that i drew):
but they are missing in first picture (1 minutes csv data).
any idea? -
Sell/Buy signal labels are missing in the plotting of forex data
Hello!
I am using the 1-minutes forex csv data for backtesting, odd thing observed is that the buy/sell icons are missing in the plotting.
using daily csv data from yahoo is fine, so looks there is some tricky issue in the csv part.
Could anybody please help me with the issue?the code is
from datetime import datetime import backtrader as bt class SmaCross(bt.SignalStrategy): def __init__(self): sma1, sma2 = bt.ind.SMA(period=1), bt.ind.SMA(period=60) crossover = bt.ind.CrossOver(sma1, sma2) self.signal_add(bt.SIGNAL_LONG, crossover) if __name__ == '__main__': # Create a cerebro entity cerebro = bt.Cerebro() # Add a strategy #cerebro.addstrategy(MyStrategy, period=15) cerebro.addstrategy(SmaCross) # sh: 000001.SS # BT: BTC-USD # SP500: ^GSPC #data0 = bt.feeds.YahooFinanceData(dataname='BTC-USD', fromdate=datetime(2018, 1, 1), # todate=datetime(2019, 6, 1), decimals=5) data0 = bt.feeds.GenericCSVData( dataname='./eurusd-1m/DAT_ASCII_EURUSD_M1_201904.csv', fromdate=datetime(2019, 4, 1), todate=datetime(2019, 4, 10), nullvalue=0.0, dtformat=('%Y%m%d %H%M%S'), #tmformat=('%H:%M:%S'), datetime=0, time=-1, high=2, low=3, open=1, close=4, volume=-1, openinterest=-1, timeframe=bt.TimeFrame.Minutes, compression = 1, separator=';', decimals=5, headers=False ) cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes, compression=30) # Set our desired cash start cerebro.broker.setcash(1000000.0) # Add a FixedSize sizer according to the stake #cerebro.addsizer(bt.sizers.FixedSize, stake=2) cerebro.addsizer(bt.sizers.PercentSizer, percents=90) # Set the commission - 0.1% ... divide by 100 to remove the % cerebro.broker.setcommission(commission=0.0005) # Print out the starting conditions print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) # Run over everything cerebro.run() # Print out the final result print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.plot(style='bar')
The CSV data looks as following:
20190401 000000;1.123210;1.123240;1.123200;1.123240;0 20190401 000100;1.123230;1.123230;1.123140;1.123190;0 20190401 000200;1.123210;1.123310;1.123200;1.123310;0 20190401 000300;1.123330;1.123360;1.123310;1.123340;0 20190401 000400;1.123330;1.123330;1.123250;1.123250;0
The plotting: