File tree 5 files changed +45
-12
lines changed 5 files changed +45
-12
lines changed Original file line number Diff line number Diff line change 19
19
import sys
20
20
import backtrader as bt
21
21
22
+ import metaStrategy as mt
23
+
22
24
# Create a subclass of Strategy to define the indicators and logic
23
- class ichimokuStrat1 (bt . Strategy ):
25
+ class ichimokuStrat1 (mt . MetaStrategy ):
24
26
25
27
params = (
26
28
('atrperiod' , 14 ), # ATR Period (standard)
@@ -41,12 +43,10 @@ def notify_order(self, order):
41
43
if not order .alive ():
42
44
self .order = None # indicate no order is pending
43
45
44
- def __init__ (self , parameters = None ):
46
+ def __init__ (self , * argv ):
45
47
46
- # Set UI modified parameters
47
- if parameters != None :
48
- for parameterName , parameterValue in parameters .items ():
49
- setattr (self .params , parameterName , parameterValue )
48
+ # used to modify parameters
49
+ super ().__init__ (argv [0 ])
50
50
51
51
# Ichi indicator
52
52
self .ichi = bt .indicators .Ichimoku (self .datas [0 ],
Original file line number Diff line number Diff line change
1
+ ###############################################################################
2
+ #
3
+ # Copyright (C) 2021 - Skinok
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ ###############################################################################
19
+ import backtrader as bt
20
+
21
+ class MetaStrategy (bt .Strategy ):
22
+
23
+ def __init__ (self , parameters = None ):
24
+
25
+ # Set UI modified parameters
26
+ if parameters != None :
27
+ for parameterName , parameterValue in parameters .items ():
28
+ setattr (self .params , parameterName , parameterValue )
29
+
30
+ pass
Original file line number Diff line number Diff line change 25
25
import backtrader as bt
26
26
import backtrader .indicators as btind
27
27
28
+ import metaStrategy as mt
28
29
29
- class sma_crossover (bt . Strategy ):
30
+ class sma_crossover (mt . MetaStrategy ):
30
31
'''This is a long-only strategy which operates on a moving average cross
31
32
32
33
Note:
@@ -55,15 +56,17 @@ class sma_crossover(bt.Strategy):
55
56
('fast' , 15 ),
56
57
# period for the slow moving average
57
58
('slow' , 30 ),
58
- # moving average to use
59
- ('_movav' , btind .MovAv .SMA ),
60
59
# Trade size
61
60
('tradeSize' , 2000 )
62
61
)
63
62
64
- def __init__ (self ):
65
- sma_fast = self .p ._movav (period = self .p .fast )
66
- sma_slow = self .p ._movav (period = self .p .slow )
63
+ def __init__ (self , * argv ):
64
+
65
+ # used to modify parameters
66
+ super ().__init__ (argv [0 ])
67
+
68
+ sma_fast = btind .MovAv .SMA (period = self .p .fast )
69
+ sma_slow = btind .MovAv .SMA (period = self .p .slow )
67
70
68
71
self .buysig = btind .CrossOver (sma_fast , sma_slow )
69
72
You can’t perform that action at this time.
0 commit comments