@@ -99,13 +99,22 @@ def resetCerebro(self):
99
99
pass
100
100
101
101
102
+ # Return True if loading is successfull & the error string if False
102
103
def loadData (self , dataPath , datetimeFormat , separator ):
103
104
104
105
# Try importing data file
105
106
# We should code a widget that ask for options as : separators, date format, and so on...
106
107
try :
107
108
fileName = os .path .basename (dataPath )
108
- self .dataframes [fileName ] = pd .read_csv (dataPath , sep = separator , parse_dates = [0 ], date_parser = lambda x : pd .to_datetime (x , format = datetimeFormat ), skiprows = 0 , header = 0 , index_col = 0 )
109
+ self .dataframes [fileName ] = pd .read_csv (dataPath ,
110
+ sep = separator ,
111
+ parse_dates = [0 ],
112
+ date_parser = lambda x : pd .to_datetime (x , format = datetimeFormat ),
113
+ skiprows = 0 ,
114
+ header = 0 ,
115
+ names = ["Time" , "Open" , "High" , "Low" , "Close" , "Volume" ],
116
+ index_col = 0 )
117
+
109
118
except ValueError as err :
110
119
return False , "ValueError error:" + str (err )
111
120
except AttributeError as err :
@@ -131,14 +140,44 @@ def importData(self, fileNamesOrdered):
131
140
# Add data to cerebro : only add data when all files have been selected for multi-timeframes
132
141
self .cerebro .adddata (self .data ) # Add the data feed
133
142
143
+ # find the time frame
144
+ timeframe = self .findTimeFrame (df )
145
+
146
+ # Create the chart window for the good timeframe (if it does not already exists?)
147
+ self .interface .createChartDock (timeframe )
148
+
134
149
# Draw charts based on input data
135
- self .interface .drawChart (df )
150
+ self .interface .drawChart (df , timeframe )
136
151
137
152
# Enable run button
138
153
self .interface .strategyTesterUI .runBacktestPB .setEnabled (True )
139
154
140
155
pass
141
156
157
+ def findTimeFrame (self ,df ):
158
+
159
+ if len (df .index ) > 2 :
160
+ dtDiff = df .index [1 ] - df .index [0 ]
161
+
162
+ if dtDiff .seconds == 60 :
163
+ return "M1"
164
+ elif dtDiff .seconds == 300 :
165
+ return "M5"
166
+ elif dtDiff .seconds == 900 :
167
+ return "M15"
168
+ elif dtDiff .seconds == 1800 :
169
+ return "M30"
170
+ elif dtDiff .seconds == 3600 :
171
+ return "H1"
172
+ elif dtDiff .seconds == 14400 :
173
+ return "H4"
174
+ elif dtDiff .seconds == 86400 :
175
+ return "D"
176
+ elif dtDiff .seconds == 604800 :
177
+ return "W"
178
+
179
+ pass
180
+
142
181
143
182
def addStrategy (self , strategyName ):
144
183
@@ -254,4 +293,5 @@ def cashChanged(self, cashString):
254
293
self .startingcash = float (cashString )
255
294
self .cerebro .broker .setcash (self .startingcash )
256
295
257
- pass
296
+ pass
297
+
0 commit comments