Skip to content

Commit 842a34d

Browse files
committed
Merge branch 'master' into development
2 parents e79404a + 209988d commit 842a34d

9 files changed

Lines changed: 67 additions & 3 deletions

File tree

backtrader/btrun/btrun.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
vchartcsv=bt.feeds.VChartCSVData,
3838
vcfile=bt.feeds.VChartFile,
3939
sierracsv=bt.feeds.SierraChartCSVData,
40+
mt4csv=bt.feeds.MT4CSVData,
4041
yahoocsv=bt.feeds.YahooFinanceCSVData,
4142
yahoocsv_unreversed=bt.feeds.YahooFinanceCSVData,
4243
yahoo=bt.feeds.YahooFinanceData,

backtrader/cerebro.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ def getbroker(self):
865865
broker = property(getbroker, setbroker)
866866

867867
def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
868+
savefig=False, figfilename='backtrader-plot-%i.png',
868869
**kwargs):
869870
'''
870871
Plots the strategies inside cerebro
@@ -912,7 +913,10 @@ def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
912913

913914
figs.append(rfig)
914915

915-
plotter.show()
916+
if savefig:
917+
plotter.savefig(figfilename % len(figs))
918+
else:
919+
plotter.show()
916920
return figs
917921

918922
def __call__(self, iterstrat):

backtrader/feeds/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .vchart import *
2929
from .yahoo import *
3030
from .sierrachart import *
31+
from .mt4csv import *
3132
from .pandafeed import *
3233
from .influxfeed import *
3334
try:

backtrader/feeds/mt4csv.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8; py-indent-offset:4 -*-
3+
###############################################################################
4+
#
5+
# Copyright (C) 2015, 2016, 2017 Daniel Rodriguez
6+
# Copyright (C) 2017 Dimitri John Ledkov
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
#
21+
###############################################################################
22+
from __future__ import (absolute_import, division, print_function,
23+
unicode_literals)
24+
25+
26+
from . import GenericCSVData
27+
28+
29+
class MT4CSVData(GenericCSVData):
30+
'''
31+
Parses a `Metatrader4 <https://www.metaquotes.net/en/metatrader4>`_ History
32+
center CSV exported file.
33+
34+
Specific parameters (or specific meaning):
35+
36+
- ``dataname``: The filename to parse or a file-like object
37+
38+
- Uses GenericCSVData and simply modifies the params
39+
'''
40+
41+
params = (
42+
('dtformat', '%Y.%m.%d'),
43+
('tmformat', '%H:%M'),
44+
('datetime', 0),
45+
('time', 1),
46+
('open', 2),
47+
('high', 3),
48+
('low', 4),
49+
('close', 5),
50+
('volume', 6),
51+
('openinterest', -1),
52+
)

backtrader/plot/plot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,11 @@ def plotdata(self, data, indicators):
757757
def show(self):
758758
self.mpyplot.show()
759759

760+
def savefig(self, filename='backtrader-plot.png'):
761+
fig = self.mpyplot.gcf()
762+
fig.set_size_inches(16, 9)
763+
self.mpyplot.savefig(filename, dpi=300, bbox_inches='tight')
764+
760765
def sortdataindicators(self, strategy):
761766
# These lists/dictionaries hold the subplots that go above each data
762767
self.dplotstop = list()

docs2/automated-bt-run/automated-bt-run.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Directly from the script::
420420

421421
$ btrun --help
422422
usage: btrun-script.py [-h] --data DATA [--cerebro [kwargs]] [--nostdstats]
423-
[--format {yahoocsv_unreversed,vchart,vchartcsv,yahoo,ibdata,sierracsv,yahoocsv,btcsv,vcdata}]
423+
[--format {yahoocsv_unreversed,vchart,vchartcsv,yahoo,mt4csv,ibdata,sierracsv,yahoocsv,btcsv,vcdata}]
424424
[--fromdate FROMDATE] [--todate TODATE]
425425
[--timeframe {microseconds,seconds,weeks,months,minutes,days,years}]
426426
[--compression COMPRESSION]
@@ -483,7 +483,7 @@ Directly from the script::
483483
- oldbuysell (default False)
484484
- tradehistory (default False)
485485
--nostdstats Disable the standard statistics observers
486-
--format {yahoocsv_unreversed,vchart,vchartcsv,yahoo,ibdata,sierracsv,yahoocsv,btcsv,vcdata}, --csvformat {yahoocsv_unreversed,vchart,vchartcsv,yahoo,ibdata,sierracsv,yahoocsv,btcsv,vcdata}, -c {yahoocsv_unreversed,vchart,vchartcsv,yahoo,ibdata,sierracsv,yahoocsv,btcsv,vcdata}
486+
--format {yahoocsv_unreversed,vchart,vchartcsv,yahoo,mt4csv,ibdata,sierracsv,yahoocsv,btcsv,vcdata}, --csvformat {yahoocsv_unreversed,vchart,vchartcsv,yahoo,mt4csv,ibdata,sierracsv,yahoocsv,btcsv,vcdata}, -c {yahoocsv_unreversed,vchart,vchartcsv,yahoo,mt4csv,ibdata,sierracsv,yahoocsv,btcsv,vcdata}
487487
CSV Format
488488
--fromdate FROMDATE, -f FROMDATE
489489
Starting date in YYYY-MM-DD[THH:MM:SS] format

tools/bt-run.py

100644100755
File mode changed.

tools/rewrite-data.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
vcfile=bt.feeds.VChartFile,
4040
ibdata=bt.feeds.IBData,
4141
sierracsv=bt.feeds.SierraChartCSVData,
42+
mt4csv=bt.feeds.MT4CSVData,
4243
yahoocsv=bt.feeds.YahooFinanceCSVData,
4344
yahoocsv_unreversed=bt.feeds.YahooFinanceCSVData,
4445
yahoo=bt.feeds.YahooFinanceData,

tools/yahoodownload.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)