Skip to content

Commit 89488ec

Browse files
committed
Final retouching and integration of contributed fractal study and test case
1 parent 82c1ba7 commit 89488ec

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

backtrader/studies/contrib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
import backtrader as bt
2525

2626
from .import fractal as fractal
27-
for name in vortex.__all__:
27+
for name in fractal.__all__:
2828
setattr(bt.studies, name, getattr(fractal, name))

backtrader/studies/contrib/fractal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
import backtrader as bt
2525

2626

27-
class Fractal(bt.PeriodN):
27+
__all__ = ['Fractal']
28+
29+
30+
class Fractal(bt.ind.PeriodN):
2831
'''
2932
References:
3033
[Ref 1] http://www.investopedia.com/articles/trading/06/fractals.asp

tests/test_study_fractal.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8; py-indent-offset:4 -*-
3+
###############################################################################
4+
#
5+
# Copyright (C) 2015, 2016 Daniel Rodriguez
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
###############################################################################
21+
from __future__ import (absolute_import, division, print_function,
22+
unicode_literals)
23+
24+
import testcommon
25+
26+
import backtrader as bt
27+
28+
29+
chkdatas = 1
30+
chkvals = [
31+
['nan', 'nan', 'nan'],
32+
['nan', 'nan', '3553.692850']
33+
]
34+
35+
chkmin = 5
36+
chkind = bt.studies.Fractal
37+
38+
39+
def test_run(main=False):
40+
datas = [testcommon.getdata(i) for i in range(chkdatas)]
41+
testcommon.runtest(datas,
42+
testcommon.TestStrategy,
43+
main=main,
44+
plot=main,
45+
chkind=chkind,
46+
chkmin=chkmin,
47+
chkvals=chkvals)
48+
49+
50+
if __name__ == '__main__':
51+
test_run(main=True)

0 commit comments

Comments
 (0)