1 //+------------------------------------------------------------------+
2 //| Meta COT cotlib.mq4 |
3 //| Copyright 2009, C-4 (Vasiliy Sokolov, Russia, St.-Petersburg,|
4 //| 2009), All Rights Reserved. |
6 //+------------------------------------------------------------------+
7 #property copyright "Copyright 2009, C-4 (Vasiliy Sokolov, SPb), All Rights Reserved."
8 #property link "vs-box@mail.ru"
12 #define NONCOMM_LONG 1
13 #define NONCOMM_SHORT 2
14 #define OPERATORS_LONG 3
15 #define OPERATORS_SHORT 4
17 #define NONREP_SHORT 6
19 #define NET_OPERATORS 8
21 #define OI_NONCOMM_LONG 10
22 #define OI_NONCOMM_SHORT 11
23 #define OI_OPERATORS_LONG 12
24 #define OI_OPERATORS_SHORT 13
25 #define OI_NONREP_LONG 14
26 #define OI_NONREP_SHORT 15
27 #define WILLCO_NONCOMM 16
28 #define WILLCO_OPERATORS 17
29 #define WILLCO_NONREP 18
31 #define INDEX_NONCOMM 20
32 #define INDEX_OPERATORS 21
33 #define INDEX_NONREP 22
34 #define MOVEMENT_NONCOMM 23
35 #define MOVEMENT_OPERATORS 24
36 #define MOVEMENT_NONREP 25
37 #define MOVEMENT_OI 26
38 #define OI_NET_NONCOMM 27
39 #define OI_NET_OPERATORS 28
40 #define OI_NET_NONREP 29
43 extern bool load_cot_file=false;
44 extern string cot_file="COT - U.S. DOLLAR CONCATENATE.csv";
45 extern string settings="settings.ini";
53 //***************************************************************************************************************
58 datetime realize_data[];
60 double open_interest[]; //
61 double noncomm_long[]; //
62 double noncomm_short[]; //
63 double noncomm_spread[]; //
64 double operators_long[]; // ()
65 double operators_short[]; // ()
66 double nonrep_long[]; // ()
67 double nonrep_short[]; // ()
70 double oi_noncomm_long[]; // /
71 double oi_noncomm_short[]; // /
72 double oi_operators_long[]; // / ()
73 double oi_operators_short[]; // / ()
74 double oi_nonrep_long[]; // / ()
75 double oi_nonrep_short[]; // / ()
79 double oi_net_noncomm[];
80 double oi_net_operators[];
81 double oi_net_nonrep[];
84 double net_noncomm[]; //
85 double net_operators[]; //
86 double net_nonrep[]; //
90 double index_ncomm[]; //
91 double index_operators[]; // ()
92 double index_nonrep[]; // ()
95 // Stohastic(OI/NET_POSITION)
96 double willco_ncomm[]; //
97 double willco_operators[]; //
98 double willco_nonrep[]; //
101 double movement_oi[];
102 double movement_ncomm[];
103 double movement_operators[];
104 double movement_nonrep[];
105 //***********************************************************************************************************************************
115 handle_cotfile=FileOpen(cot_file,FILE_READ|FILE_CSV);
116 //handle_cotfile=FileOpen("COT - U.S. DOLLAR CONCATENATE.csv",FILE_READ|FILE_CSV);
117 if(handle_cotfile==-1){
118 Print(" . ", cot_file);
119 Print(GetLastError());
122 while(FileIsEnding(handle_cotfile)==false){
123 data=FileReadString(handle_cotfile);
124 if(FileIsLineEnding(handle_cotfile)&&data!="")str++;
126 ArrayResize(realize_data,str);
128 ArrayResize(open_interest,str);
129 ArrayResize(noncomm_long,str);
130 ArrayResize(noncomm_short,str);
131 ArrayResize(noncomm_spread,str);
132 ArrayResize(operators_long,str);
133 ArrayResize(operators_short,str);
134 ArrayResize(nonrep_long,str);
135 ArrayResize(nonrep_short,str);
137 ArrayResize(oi_noncomm_long,str);
138 ArrayResize(oi_noncomm_short,str);
139 ArrayResize(oi_operators_long,str);
140 ArrayResize(oi_operators_short,str);
141 ArrayResize(oi_nonrep_long,str);
142 ArrayResize(oi_nonrep_short,str);
144 ArrayResize(oi_net_noncomm,str);
145 ArrayResize(oi_net_operators,str);
146 ArrayResize(oi_net_nonrep,str);
148 ArrayResize(net_noncomm,str);
149 ArrayResize(net_operators,str);
150 ArrayResize(net_nonrep,str);
152 ArrayResize(index_oi,str);
153 ArrayResize(index_ncomm,str);
154 ArrayResize(index_operators,str);
155 ArrayResize(index_nonrep,str);
157 ArrayResize(willco_ncomm,str);
158 ArrayResize(willco_operators,str);
159 ArrayResize(willco_nonrep,str);
161 ArrayResize(movement_oi,str);
162 ArrayResize(movement_ncomm,str);
163 ArrayResize(movement_operators,str);
164 ArrayResize(movement_nonrep,str);
166 FileClose(handle_cotfile);
171 /*void settings_load()
175 if(load_cot_file==true)return;
176 h_set=FileOpen(settings,FILE_READ|FILE_CSV,";");
177 //FileOpen("\Temp\Cot_file.txt",FILE_WRITE,FILE_CSV);
179 while(FileIsEnding(h_set)==false){
180 set=FileReadString(h_set);
182 if(set==Symbol()&&_column!=1){cot_file=sname;return;}
183 if(_column==2&&set!="")name=set; // -
184 if(FileIsLineEnding(h_set)==true)_column=0;
185 if(_column==1)sname=set;
199 if(load_cot_file==true)return;
200 h_set=FileOpen(settings,FILE_READ|FILE_CSV,";");
201 //FileOpen("\Temp\Cot_file.txt",FILE_WRITE,FILE_CSV);
203 while(FileIsEnding(h_set)==false){
204 set=FileReadString(h_set);
206 if(_column==1&&set!="")sname=set;
207 if(_column==2&&set!="")name=set; // -
208 if(_column>2&&set!=""&&StringFind(Symbol(),set)==0){cot_file=sname;return;}
209 if(FileIsLineEnding(h_set)==true)_column=0;
215 datetime data_realize;
218 handle_cotfile=FileOpen(cot_file,FILE_READ|FILE_CSV, ";");
220 while(FileIsEnding(handle_cotfile)==false){
221 data=FileReadString(handle_cotfile);
223 if(FileIsLineEnding(handle_cotfile)==true||FileIsEnding(handle_cotfile)==true){//column=12 -
225 nonrep_short[n_str]=StrToDouble(data);
232 realize_data[n_str]=StrToTime(data);
235 open_interest[n_str]=StrToDouble(data);
236 //Print(open_interest[n_str]);
239 noncomm_long[n_str]=StrToDouble(data);
242 noncomm_short[n_str]=StrToDouble(data);
245 noncomm_spread[n_str]=StrToDouble(data);
248 operators_long[n_str]=StrToDouble(data);
251 operators_short[n_str]=StrToDouble(data);
254 nonrep_long[n_str]=StrToDouble(data);
259 FileClose(handle_cotfile);
269 for(int i=0;i<n_str;i++){
270 index_oi[i]=EMPTY_VALUE;
271 index_ncomm[i]=EMPTY_VALUE;
272 index_operators[i]=EMPTY_VALUE;
273 index_nonrep[i]=EMPTY_VALUE;
274 willco_ncomm[i]=EMPTY_VALUE;
275 willco_operators[i]=EMPTY_VALUE;
276 willco_nonrep[i]=EMPTY_VALUE;
277 movement_ncomm[i]=EMPTY_VALUE;
278 movement_operators[i]=EMPTY_VALUE;
279 movement_nonrep[i]=EMPTY_VALUE;
281 for(i=0;i<n_str;i++){
282 if(open_interest[i]==0){
283 oi_noncomm_long[i]=0;
284 oi_noncomm_short[i]=0;
285 oi_operators_long[i]=0;
286 oi_operators_short[i]=0;
288 oi_nonrep_short[i]=0;
291 oi_noncomm_long[i]=noncomm_long[i]/open_interest[i];
292 oi_noncomm_short[i]=noncomm_short[i]/open_interest[i];
293 oi_operators_long[i]=operators_long[i]/open_interest[i];
294 oi_operators_short[i]=operators_short[i]/open_interest[i];
295 oi_nonrep_long[i]=nonrep_long[i]/open_interest[i];
296 oi_nonrep_short[i]=nonrep_short[i]/open_interest[i];
299 net_noncomm[i]=noncomm_long[i]-noncomm_short[i];
300 net_operators[i]=operators_long[i]-operators_short[i];
301 net_nonrep[i]=nonrep_long[i]-nonrep_short[i];
303 if(open_interest[i]==0){
305 oi_net_operators[i]=0;
309 oi_net_noncomm[i]=net_noncomm[i]/open_interest[i];
310 oi_net_operators[i]=net_operators[i]/open_interest[i];
311 oi_net_nonrep[i]=net_nonrep[i]/open_interest[i];
315 for(i=0;i<n_str-period;i++){
317 max=ArrayMaximum(open_interest,period,i);
318 min=ArrayMinimum(open_interest,period,i);
319 delta=open_interest[max]-open_interest[min];
321 index_oi[i]=(open_interest[i]-open_interest[min])/delta*100;
323 max=ArrayMaximum(net_noncomm,period,i);
324 min=ArrayMinimum(net_noncomm,period,i);
325 delta=net_noncomm[max]-net_noncomm[min];
327 index_ncomm[i]=(net_noncomm[i]-net_noncomm[min])/delta*100;
329 max=ArrayMaximum(net_operators,period,i);
330 min=ArrayMinimum(net_operators,period,i);
331 delta=net_operators[max]-net_operators[min];
333 index_operators[i]=(net_operators[i]-net_operators[min])/delta*100;
335 max=ArrayMaximum(net_nonrep,period,i);
336 min=ArrayMinimum(net_nonrep,period,i);
337 delta=net_nonrep[max]-net_nonrep[min];
339 index_nonrep[i]=(net_nonrep[i]-net_nonrep[min])/delta*100;
341 max=ArrayMaximum(oi_net_noncomm,period,i);
342 min=ArrayMinimum(oi_net_noncomm,period,i);
343 delta=oi_net_noncomm[max]-oi_net_noncomm[min];
345 willco_ncomm[i]=(oi_net_noncomm[i]-oi_net_noncomm[min])/delta*100;
347 max=ArrayMaximum(oi_net_operators,period,i);
348 min=ArrayMinimum(oi_net_operators,period,i);
349 delta=oi_net_operators[max]-oi_net_operators[min];
351 willco_operators[i]=(oi_net_operators[i]-oi_net_operators[min])/delta*100;
353 max=ArrayMaximum(oi_net_nonrep,period,i);
354 min=ArrayMinimum(oi_net_nonrep,period,i);
355 delta=oi_net_nonrep[max]-oi_net_nonrep[min];
357 willco_nonrep[i]=(oi_net_nonrep[i]-oi_net_nonrep[min])/delta*100;
359 for(i=0;i<n_str-period-movement_index;i++){
360 movement_oi[i]=index_oi[i]-index_oi[i-movement_index];
361 movement_ncomm[i]=index_ncomm[i]-index_ncomm[i-movement_index];
362 movement_operators[i]=index_operators[i]-index_operators[i-movement_index];
363 movement_nonrep[i]=index_nonrep[i]-index_nonrep[i-movement_index];
368 double get_data(int type, int bar)
371 int i_data=get_cot(bar);
372 if(i_data==EMPTY_VALUE)return(EMPTY_VALUE);
375 return(open_interest[i_data]);
377 return(noncomm_long[i_data]+noncomm_spread[i_data]);
378 //return(noncomm_long[i_data]);
380 return(noncomm_short[i_data]+noncomm_spread[i_data]);
381 //return(noncomm_short[i_data]);
383 return(operators_long[i_data]);
384 case OPERATORS_SHORT:
385 return(operators_short[i_data]);
387 return(nonrep_long[i_data]);
389 return(nonrep_short[i_data]);
391 return(net_noncomm[i_data]);
393 return(net_operators[i_data]);
395 return(net_nonrep[i_data]);
397 return(index_oi[i_data]);
399 return(index_ncomm[i_data]);
400 case INDEX_OPERATORS:
401 return(index_operators[i_data]);
403 return(index_nonrep[i_data]);
404 case OI_NONCOMM_LONG:
405 return(oi_noncomm_long[i_data]);
406 case OI_NONCOMM_SHORT:
407 return(oi_noncomm_short[i_data]);
408 case OI_OPERATORS_LONG:
409 return(oi_operators_long[i_data]);
410 case OI_OPERATORS_SHORT:
411 return(oi_operators_short[i_data]);
413 return(oi_nonrep_long[i_data]);
414 case OI_NONREP_SHORT:
415 return(oi_nonrep_short[i_data]);
417 return(willco_ncomm[i_data]);
418 case WILLCO_OPERATORS:
419 return(willco_operators[i_data]);
421 return(willco_nonrep[i_data]);
423 return(oi_net_nonrep[i_data]);
424 case OI_NET_OPERATORS:
425 return(oi_net_operators[i_data]);
427 return(oi_net_nonrep[i_data]);
428 case MOVEMENT_NONCOMM:
429 return(movement_ncomm[i_data]);
430 case MOVEMENT_OPERATORS:
431 return(movement_operators[i_data]);
432 case MOVEMENT_NONREP:
433 return(movement_nonrep[i_data]);
435 return(movement_oi[i_data]);
443 datetime tbar=iTime(Symbol(),0,i);
444 for(int k=0;k<n_str;k++)
445 if(realize_data[k]<tbar)return(k);
452 return(iBarShift(Symbol(),0,realize_data[n_str-1],false));
455 // 6 ( "COT - FileName.csv" "FileName")
456 string str_trim(string fname)
458 int strlen=StringLen(fname)-1;
461 for(int i=strlen;i>0;i--){
462 char=StringGetChar(fname,i);
464 for(int b=6;b<i;b++)// b=0 6
465 str=str+CharToStr(StringGetChar(fname,b));