@Jens-Halsberghe you lose some code ,they shold be imported from others. for example
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from . import Indicator, Max, Min, MovAv,Average
@Jens-Halsberghe you lose some code ,they shold be imported from others. for example
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from . import Indicator, Max, Min, MovAv,Average
@tianjixuetu I met this situation again ,and I find that the reason is that the first data may lose some bar,so,it should run many times to wait the some data to this datetime.
@Jens-Halsberghe I just met this question and solve it.
you should use this class and the ATR .
class AverageTrueRange(Indicator):
'''
Defined by J. Welles Wilder, Jr. in 1978 in hiMY_s book *"New Concepts in
Technical Trading Systems"*.
The idea is to take the close into account to calculate the range if it
yields a larger range than the daily range (High - Low)
Formula:
- SmoothedMovingAverage(TrueRange, period)
See:
- http://en.wikipedia.org/wiki/Average_true_range
# 修改了算法，使用我自己的方法
'''
alias = ('ATR',)
lines = ('atr',)
params = (('period', 14), ('Average', Average))
def _plotlabel(self):
plabels = [self.p.period]
plabels += [self.p.movav] * self.p.notdefault('movav')
return plabels
def __init__(self):
self.lines.atr = self.p.Average(TR(self.data), period=self.p.period)
super(AverageTrueRange, self).__init__()
@tianjixuetu If the underlying logic code has problems, we need to modify the underlying logic code first, then fix the bug, and develop new functions.anyone understand the backtrader's underlying logic and source code?
I'm curious that,how many people have read backtrader's source code more than once. How much do you understand the underlying logic of backtrader? I wonder if the underlying logic of backtrader has some problems.
@Ignasius-Wahyudi there is something(maybe wrong) when you calculate the net value when it is a future when you have a position,but after you close the position,the results is same. so , it is not a big question.
@vladisld my github is https://github.com/tianjixuetu ,thank you very much.
@vladisld @run-out ‘s idea is very good。I has uesd backtrder since 2018-04, and read the sorce code at least three times, but unfortunately,I cannot totally understand the every detail, and I have fork the backtrader's code and develop it by myself,but I met many questions,it needs a lot of time to solve it.
I agree with @vladisld's idea, we can develop a new packages,for example backtrader2,based on backtrader。
I would like to make it better ！
@ab_trader thank you. but,what you say and try,is not my example. just as I said before, all my datas is the same timeframe,there is no daily bar,they all 15 min bar. anyway,thank you very much.
@ab_trader said in why the prenext and next can run many times in one bar?:
2020-05-04T12:00:00, C: 35.00, data0: 16, data1: 0
2020-05-04T12:00:00, C: 35.00, data0: 16, data1: 1
this is the question. when you run strategy,if you use multi data,if some day,you run two time next,is it right for your strategy logical?
when you use more data,you may meet more stranger question.
do you know,why the next run two times at the end day? we may fix this bug!