For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
find bugs when using the DemarkPivotPoint indicator
-
when I try to run the example code with "DemarkPivotPoint " in the ppsample.py in the folder of \backtrader\backtrader-master\samples\pivot-point, the pic could not show the three lines. I think there is something wrong with CmpEx function. please fix the bug.
#!/usr/bin/env python # -*- coding: utf-8; py-indent-offset:4 -*- ############################################################################### # # Copyright (C) 2015-2020 Daniel Rodriguez # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################### from __future__ import (absolute_import, division, print_function, unicode_literals) import argparse import backtrader as bt import backtrader.feeds as btfeeds import backtrader.utils.flushfile class St(bt.Strategy): params = (('usepp1', False), ('plot_on_daily', 1)) def __init__(self): autoplot = self.p.plot_on_daily self.pp = pp = bt.ind.DemarkPivotPoint(self.data1, _autoplot=autoplot) def next(self): txt = ','.join( ['%04d' % len(self), '%04d' % len(self.data0), '%04d' % len(self.data1), self.data.datetime.date(0).isoformat(), '%04d' % len(self.pp), '%.2f' % self.pp[0]]) print(txt) def runstrat(): args = parse_args() cerebro = bt.Cerebro() data = btfeeds.BacktraderCSVData(dataname=args.data) cerebro.adddata(data) cerebro.resampledata(data, timeframe=bt.TimeFrame.Months) cerebro.addstrategy(St) # cerebro.addstrategy(St, # usepp1=args.usepp1, # plot_on_daily=args.plot_on_daily) cerebro.run(runonce=False) if args.plot: cerebro.plot(**eval('dict(' + args.plot + ')')) def parse_args(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Sample for pivot point and cross plotting') parser.add_argument('--data', required=False, default='......ktrader/backtrader-master/datas/2005-2006-day-001.txt', help='Data to be read in') parser.add_argument('--plot', required=False, default='', nargs='?', const='{}', metavar='kwargs', help='kwargs in key=value format') parser.add_argument('--plot-on-daily', required=False, action='store_true', help=('Plot the indicator on the daily data')) return parser.parse_args() if __name__ == '__main__': runstrat()
-
@da-zhang said in find bugs when using the DemarkPivotPoint indicator:
DemarkPivotPoint
Please include the error message/faulty pic or chart so we can help you.
-
It seems there is indeed a bug in CmpEx function as you correctly noticed.
when the
CmpEx.next()
method is changed to:def next(self): if self.a[0] < self.b[0]: self[0] = self.r1[0] elif self.a[0] > self.b[0]: self[0] = self.r3[0] else: self[0] = self.r2[0]
the resulted plot seems to be ok:
I've submitted the issue: https://github.com/backtrader2/backtrader/issues/42
-
@vladisld good job, many thanks.
-
@vladisld nice, indeed a bug, the p r1 s1 is not correct.