-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathkantu_loadsymbol.pas
More file actions
207 lines (155 loc) · 6.49 KB
/
kantu_loadsymbol.pas
File metadata and controls
207 lines (155 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
unit kantu_loadSymbol;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, FileUtil, Forms, Controls, Graphics, Dialogs, CheckLst,
StdCtrls, DbCtrls, DBGrids, ZMConnection, ZMQueryDataSet, kantu_definitions, kantu_simulation, kantu_singleSystem;
type
{ TloadSymbol }
TloadSymbol = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
OpenDialog1: TOpenDialog;
updateLoadedButton: TButton;
SymbolsList: TCheckListBox;
Datasource1: TDatasource;
SymbolsGrid: TDBGrid;
DBNavigator1: TDBNavigator;
Label1: TLabel;
ZMConnection1: TZMConnection;
ZMQueryDataSet1: TZMQueryDataSet;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure DBNavigator1BeforeAction(Sender: TObject; Button: TDBNavButtonType
);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
private
{ private declarations }
public
{ public declarations }
procedure updateIndicatorLoadedSymbols;
end;
var
loadSymbol: TloadSymbol;
implementation
{$R *.lfm}
{ TloadSymbol }
uses kantu_main, kantu_indicators;
procedure TloadSymbol.updateIndicatorLoadedSymbols;
var
i: integer;
begin
LoadedIndiHistoryData := nil ;
SingleSystem.SymbolsCombo.Clear;
for i:= 0 to SymbolsList.Count -1 do
begin
if SymbolsList.Checked[i] then
begin
loadSymbol.ZMQueryDataSet1.SQL.Clear;
loadSymbol.ZMQueryDataSet1.SQL.Add('SELECT * FROM symbols');
loadSymbol.ZMQueryDataSet1.SQL.Add('WHERE Symbol = ' + SymbolsList.Items[i]);
loadSymbol.ZMQueryDataSet1.QueryExecute;
if FileExists(SymbolsGrid.DataSource.DataSet.Fields[1].AsString) = false then
begin
ShowMessage('Selected history file does not exist. Please check path to be valid.');
Exit;
end;
LoadIndicatorsAndHistory(SymbolsGrid.DataSource.DataSet.Fields[1].AsString);
SingleSystem.SymbolsCombo.Items.Add(SymbolsGrid.DataSource.DataSet.Fields[0].AsString);
end;
end;
if Length(LoadedIndiHistoryData) = 0 then
ShowMessage('No instruments were selected for loading. Make sure you check the checkbox for the instruments you wish to load');
loadSymbol.ZMQueryDataSet1.SQL.Clear;
loadSymbol.ZMQueryDataSet1.SQL.Add('SELECT * FROM symbols');
loadSymbol.ZMQueryDataSet1.QueryExecute;
end;
procedure TloadSymbol.Button1Click(Sender: TObject);
begin
ZMQueryDataset1.TableName:='symbols';
ShowMessage('Dataset is going to be saved to: '+ ZMQueryDataset1.ZMConnection.DatabasePathFull+ZMQueryDataset1.TableName+'.csv');
ZMQueryDataset1.SaveToTable(';');
loadSymbol.SymbolsList.Clear;
loadSymbol.Datasource1.Enabled:=False; //Manual refresh of linked DBGrid
loadSymbol.Datasource1.Enabled:=True;
loadSymbol.ZMQueryDataSet1.SQL.Clear;
loadSymbol.ZMQueryDataSet1.SQL.Add('SELECT * FROM symbols');
loadSymbol.ZMQueryDataSet1.QueryExecute;
with loadSymbol.SymbolsGrid.DataSource.DataSet do
// begin
// first;
while not loadSymbol.SymbolsGrid.DataSource.DataSet.EOF do
begin
loadSymbol.SymbolsList.Items.Add(loadSymbol.SymbolsGrid.Columns[0].Field.AsString) ;
loadSymbol.SymbolsGrid.DataSource.DataSet.Next;
end ;
end;
procedure TloadSymbol.Button2Click(Sender: TObject);
var
symbol,datafile,timeframe,minStop,slippage,spread,contractSize,commission,isVolume,pointConversion,roundLots: string;
database: TStringList;
begin
symbol := InputBox('Symbol', 'Please enter the desired symbol name', '') ;
ShowMessage('Please now select the data file that you want to use.');
datafile := '';
If OpenDialog1.Execute then
datafile := OpenDialog1.FileName;
if datafile = '' then
begin
ShowMessage('No valid data file selected. Aborting new instrument addition');
Exit;
end;
timeframe := InputBox('Timeframe', 'Please enter the time frame for the data in minutes', '') ;
slippage := InputBox('Slippage', 'Please enter the maximum slippage desired', '') ;
spread := InputBox('Spread', 'Please enter the spread used', '') ;
contractSize := InputBox('Contract size', 'Please enter the dollar values per pip when trading the standard contract size (1 lot)', '') ;
commission := InputBox('Commission', 'Please enter the commission charger per trade in USD', '') ;
isVolume := InputBox('Volume', 'Does the data contain volume information ? (0=no, 1=yes))', '') ;
pointConversion := InputBox('Point Conversion', 'Please enter the multiplication factor to convert from absolute price value to pips', '') ;
roundLots := InputBox('Lot size rounding', 'To how many decimal places do you want to round lot sizes?', '') ;
minStop := InputBox('Min stop size', 'How many price units do you want to have as a minimum SL/TP distance? (Should be number with decimal, if you want 0 type 0.0)', '') ;
database := TStringList.Create;
{$IFDEF DARWIN}
database.LoadFromFile(GetCurrentDir + '/kantu.app/Contents/MacOS/symbols/symbols.csv');
{$ELSE}
database.LoadFromFile(GetCurrentDir + '/symbols/symbols.csv');
{$ENDIF}
database.Add(symbol+';'+datafile+';'+timeframe+';'+slippage+';'+spread+';'+contractSize+';'+commission+';'+isVolume+';'+pointConversion+';'+roundLots+';'+minStop);
{$IFDEF DARWIN}
database.SaveToFile(GetCurrentDir + '/kantu.app/Contents/MacOS/symbols/symbols.csv');
{$ELSE}
database.SaveToFile(GetCurrentDir + '/symbols/symbols.csv');
{$ENDIF}
database.Free;
loadSymbol.SymbolsList.Clear;
loadSymbol.Datasource1.Enabled:=False; //Manual refresh of linked DBGrid
loadSymbol.Datasource1.Enabled:=True;
loadSymbol.ZMQueryDataSet1.SQL.Clear;
loadSymbol.ZMQueryDataSet1.SQL.Add('SELECT * FROM symbols');
loadSymbol.ZMQueryDataSet1.QueryExecute;
with loadSymbol.SymbolsGrid.DataSource.DataSet do
// begin
// first;
while not loadSymbol.SymbolsGrid.DataSource.DataSet.EOF do
begin
loadSymbol.SymbolsList.Items.Add(loadSymbol.SymbolsGrid.Columns[0].Field.AsString) ;
loadSymbol.SymbolsGrid.DataSource.DataSet.Next;
end ;
end;
procedure TloadSymbol.Button3Click(Sender: TObject);
begin
updateIndicatorLoadedSymbols;
MainForm.simulationTime := 0;
MainForm.simulationRuns := 0;
MainForm.simulationType := SIMULATION_TYPE_INDICATORS;
end;
procedure TloadSymbol.DBNavigator1BeforeAction(Sender: TObject;
Button: TDBNavButtonType);
begin
end;
procedure TloadSymbol.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
end;
end.