-
Notifications
You must be signed in to change notification settings - Fork 2
/
wedges-indicator.mq4
659 lines (656 loc) · 45.3 KB
/
wedges-indicator.mq4
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//+------------------------------------------------------------------+
//| Wedges.mq4 |
//| Wedges v1.0 Copyright 2015, fxborg |
//| http://fxborg-labo.hateblo.jp/ |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property version "1.0"
#property strict
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_LINE
#property indicator_type4 DRAW_LINE
#property indicator_type5 DRAW_LINE
//---
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 DarkGray
#property indicator_color4 DarkGray
#property indicator_color5 Gold
//---
#property indicator_label1 "Wedge"
#property indicator_label2 "Wedge"
#property indicator_label3 "Upper Line"
#property indicator_label4 "Lower Line"
#property indicator_label5 "Trend Line"
//---
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
//---
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT
#property indicator_style5 STYLE_SOLID
//--- input parameters
input int InpCalcPeriod=100; // Calculation period
input int InpMaxKeepPeriod=60; // Maximum Keep period
input string _="1: line only, 2: set buffer ,3:both";
input int InpWedgeLineMode=3; // WedgeLineMode
input double InpDeviations=1.0; // High Low Bands Deviations
input double InpLineFilter=1.2; // Line Filter Deviations
input double InpReversalNoiseFilter=5; // NoiseFilter (Minimam Reversal Spread)
//---
double RevNoiseFilter=InpReversalNoiseFilter*Point;
int ReversalPeriod=6;
int CalcPeriod=InpCalcPeriod*3;
//---
int min_rates_total;
//--- indicator buffers
double WedgeH_Buffer[];
double WedgeL_Buffer[];
double TopBuffer[];
double BtmBuffer[];
double HighBuffer[];
double LowBuffer[];
double TrendBuffer[];
//---- for calc
double StdDevBuffer[];
double ScoreH_Buffer[];
double ScoreL_Buffer[];
double SlopeA_Buffer[];
double SlopeB_Buffer[];
double CalcWedgeH_Buffer[];
double CalcWedgeL_Buffer[];
//+------------------------------------------------------------------+
//| Point Type |
//+------------------------------------------------------------------+
struct Point_Type
{
int pos;
double point;
};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- Initialization of variables of data calculation starting point
min_rates_total=1+CalcPeriod+ReversalPeriod+1;
//--- indicator buffers mapping
IndicatorBuffers(14);
//--- indicator buffers
SetIndexBuffer(0,WedgeH_Buffer);
SetIndexBuffer(1,WedgeL_Buffer);
SetIndexBuffer(2,HighBuffer);
SetIndexBuffer(3,LowBuffer);
SetIndexBuffer(4,TrendBuffer);
SetIndexBuffer(5,TopBuffer);
SetIndexBuffer(6,BtmBuffer);
SetIndexBuffer(7,SlopeA_Buffer);
SetIndexBuffer(8,SlopeB_Buffer);
SetIndexBuffer(9,StdDevBuffer);
SetIndexBuffer(10,ScoreH_Buffer);
SetIndexBuffer(11,ScoreL_Buffer);
SetIndexBuffer(12,CalcWedgeH_Buffer);
SetIndexBuffer(13,CalcWedgeL_Buffer);
// SetIndexArrow(5,159);
// SetIndexArrow(6,159);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
SetIndexEmptyValue(3,0);
SetIndexEmptyValue(4,0);
SetIndexEmptyValue(5,0);
SetIndexEmptyValue(6,0);
SetIndexEmptyValue(7,EMPTY_VALUE);
SetIndexEmptyValue(8,EMPTY_VALUE);
SetIndexEmptyValue(9,EMPTY_VALUE);
SetIndexEmptyValue(10,EMPTY_VALUE);
SetIndexEmptyValue(11,EMPTY_VALUE);
SetIndexEmptyValue(12,0);
SetIndexEmptyValue(13,0);
//---
SetIndexDrawBegin(0,min_rates_total);
SetIndexDrawBegin(1,min_rates_total);
SetIndexDrawBegin(2,min_rates_total);
SetIndexDrawBegin(3,min_rates_total);
SetIndexDrawBegin(4,min_rates_total);
SetIndexDrawBegin(5,min_rates_total);
SetIndexDrawBegin(6,min_rates_total);
//---
string short_name="Wedges v1.0("+IntegerToString(InpCalcPeriod)+")";
IndicatorShortName(short_name);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int i,j,k,first;
//--- check for bars count
if(rates_total<=min_rates_total)
return(0);
//--- indicator buffers
ArraySetAsSeries(WedgeH_Buffer,false);
ArraySetAsSeries(WedgeL_Buffer,false);
ArraySetAsSeries(HighBuffer,false);
ArraySetAsSeries(LowBuffer,false);
ArraySetAsSeries(TrendBuffer,false);
//--- calc buffers
ArraySetAsSeries(TopBuffer,false);
ArraySetAsSeries(BtmBuffer,false);
ArraySetAsSeries(SlopeA_Buffer,false);
ArraySetAsSeries(SlopeB_Buffer,false);
ArraySetAsSeries(ScoreH_Buffer,false);
ArraySetAsSeries(ScoreL_Buffer,false);
ArraySetAsSeries(StdDevBuffer,false);
ArraySetAsSeries(CalcWedgeH_Buffer,false);
ArraySetAsSeries(CalcWedgeL_Buffer,false);
//--- rate data
ArraySetAsSeries(high,false);
ArraySetAsSeries(low,false);
ArraySetAsSeries(close,false);
ArraySetAsSeries(time,false);
//+----------------------------------------------------+
//|Init Buffeer |
//+----------------------------------------------------+
first=rates_total-InpCalcPeriod+2-1;
if(first+1<prev_calculated)
first=prev_calculated-2;
else
{
for(i=0; i<first; i++)
{
BtmBuffer[i]=0;
TopBuffer[i]=0;
}
}
//+----------------------------------------------------+
//|Set Top Btm |
//+----------------------------------------------------+
for(i=first; i<rates_total-1 && !IsStopped(); i++)
{
//--- find top and bottom point
if(low[i-2]<MathMin(MathMax(low[i-5],low[i-4]),low[i-1]) && low[i-2]<=low[i-3] && low[i-2]+RevNoiseFilter<close[i-1])
BtmBuffer[i-2]=low[i-2];
if(high[i-2]>MathMax(MathMin(high[i-5],high[i-4]),high[i-1]) && high[i-2]>=high[i-3] && high[i-2]-RevNoiseFilter>close[i-1])
TopBuffer[i-2]=high[i-2];
}
//+----------------------------------------------------+
//|Init |
//+----------------------------------------------------+
first=rates_total-InpCalcPeriod+2-1;
if(first+1<prev_calculated)
first=prev_calculated-2;
else
{
for(i=0; i<first; i++)
{
TrendBuffer[i]=0.0;
HighBuffer[i]=0.0;
LowBuffer[i]=0.0;
WedgeH_Buffer[i]=0;
WedgeL_Buffer[i]=0;
}
}
//+----------------------------------------------------+
//|Main loop |
//+----------------------------------------------------+
for(i=first; i<rates_total-1 && !IsStopped(); i++)
{
TrendBuffer[i]=0;
SlopeA_Buffer[i]=EMPTY_VALUE;
SlopeB_Buffer[i]=EMPTY_VALUE;
StdDevBuffer[i]=EMPTY_VALUE;
//--- calc trend line
double price[];
ArrayResize(price,InpCalcPeriod);
int sz=0;
double sum=0.0;
//--- set HLC/3 data
for(j=InpCalcPeriod-1;j>=0;j--)
{
price[sz]=(high[i-j]+low[i-j]+close[i-j])/3;
sz++;
}
//---
double slope_price,slope_height;
calc_regression(slope_price,slope_height,InpCalcPeriod,price);
SlopeA_Buffer[i]=slope_price;
SlopeB_Buffer[i]=slope_height;
//--- draw line , calc deviation
for(j=InpCalcPeriod-1;j>=0;j--)
{
TrendBuffer[i-j]=slope_price-(slope_height*j);
sum+=MathPow(high[i-j]-TrendBuffer[i-j],2);
sum+=MathPow(low[i-j]-TrendBuffer[i-j],2);
}
//---
TrendBuffer[i-InpCalcPeriod]=0;
StdDevBuffer[i]=MathSqrt(sum/InpCalcPeriod*2);
//---
bool cancel=false;
Point_Type UpPoints[];
Point_Type DnPoints[];
int top_i=-1;
int btm_i=-1;
double new_top,new_btm,top_angle,btm_angle;
//---
int upcnt=0,dncnt=0;
int maxcnt=InpCalcPeriod;
ArrayResize(UpPoints,0,maxcnt);
//--- set top points
for(j=(i-maxcnt)+1;j<i;j++)
{
if(TopBuffer[j]>0)
{
upcnt++;
ArrayResize(UpPoints,upcnt,maxcnt);
UpPoints[upcnt-1].point=TopBuffer[j]/_Point;
UpPoints[upcnt-1].pos=j;
}
}
ArrayResize(DnPoints,0,maxcnt);
//--- set bottom points
for(j=(i-maxcnt)+1;j<i;j++)
{
if(BtmBuffer[j]>0)
{
dncnt++;
ArrayResize(DnPoints,dncnt,maxcnt);
DnPoints[dncnt-1].point=BtmBuffer[j]/_Point;
DnPoints[dncnt-1].pos=j;
}
}
//--- draw high low line
for(j=InpCalcPeriod-1;j>=0;j--)
{
HighBuffer[i-j]=TrendBuffer[i-j]+StdDevBuffer[i]*InpDeviations;
LowBuffer[i-j]=TrendBuffer[i-j]-StdDevBuffer[i]*InpDeviations;
}
HighBuffer[i-InpCalcPeriod]=0;
LowBuffer[i-InpCalcPeriod]=0;
//--- check atr filter
cancel=atr_filter(14,25,50,rates_total-i);
//---
if(!cancel)
{
//---
if(upcnt>0)
{
//--- calc wedges line (upper)
if(better_line(top_i,new_top,top_angle,UpPoints,SlopeA_Buffer[i],SlopeB_Buffer[i],StdDevBuffer[i],i,1))
{
double score;
bool best_score=true;
//--- check deviation filter
if(CalcWedgeH_Buffer[i-1]!=0 &&
(CalcWedgeH_Buffer[i-1]<HighBuffer[i-1]) &&
(CalcWedgeH_Buffer[i-1]>LowBuffer[i-1]))
{
//--- check high score
if(calc_score(score,UpPoints,top_i,high[top_i]/_Point,top_angle/_Point))
{
ScoreH_Buffer[i]=score;
for(k=1;k<InpMaxKeepPeriod;k++)
{
//--- if not best score then
if((ScoreH_Buffer[i-k]!=EMPTY_VALUE) && score>ScoreH_Buffer[i-k])
{
best_score=false;
break;
}
}
}
}
if(best_score)
{
//--- best score then update
for(j=top_i;j<=i;j++) CalcWedgeH_Buffer[j]=new_top-(top_angle*(i-j));
CalcWedgeH_Buffer[top_i-1]=0;
//--- set buffer by setting
if(InpWedgeLineMode==2 || InpWedgeLineMode==3)
for(j=top_i-1;j<=i;j++) WedgeH_Buffer[j]=CalcWedgeH_Buffer[j];
//--- draw line by setting
if(InpWedgeLineMode==1 || InpWedgeLineMode==3)
{
cleaningObj("Wedge_H");
ObjectCreate("Wedge_H"+IntegerToString(1),OBJ_TREND,0,time[top_i],high[top_i],time[i],new_top);
ObjectSet("Wedge_H"+IntegerToString(1),OBJPROP_COLOR,LightSeaGreen);
ObjectSet("Wedge_H"+IntegerToString(1),OBJPROP_WIDTH,2);
}
}
}
}
//---
if(dncnt>0)
{
//--- calc wedges line (upper)
if(better_line(btm_i,new_btm,btm_angle,DnPoints,SlopeA_Buffer[i],SlopeB_Buffer[i],StdDevBuffer[i],i,-1))
{
double score;
bool best_score=true;
//--- check deviation filter
if(CalcWedgeL_Buffer[i-1]!=0 &&
(CalcWedgeL_Buffer[i-1]>LowBuffer[i-1]) &&
(CalcWedgeL_Buffer[i-1]<HighBuffer[i-1]))
{
//--- check high score
if(calc_score(score,DnPoints,btm_i,low[btm_i]/_Point,btm_angle/_Point))
{
ScoreL_Buffer[i]=score;
for(k=1;k<InpMaxKeepPeriod;k++)
{
//--- if not best score then
if((ScoreL_Buffer[i-k]!=EMPTY_VALUE) && score>ScoreL_Buffer[i-k])
{
best_score=false;
break;
}
}
}
}
if(best_score)
{
//--- best score then update
for(j=btm_i;j<=i;j++)CalcWedgeL_Buffer[j]=new_btm-(btm_angle*(i-j));
CalcWedgeL_Buffer[btm_i-1]=0;
//--- set buffer by setting
if(InpWedgeLineMode==2 || InpWedgeLineMode==3)
for(j=btm_i-1;j<=i;j++) WedgeL_Buffer[j]=CalcWedgeL_Buffer[j];
//--- draw line by setting
if(InpWedgeLineMode==1 || InpWedgeLineMode==3)
{
cleaningObj("Wedge_L");
ObjectCreate("Wedge_L"+IntegerToString(1),OBJ_TREND,0,time[btm_i],low[btm_i],time[i],new_btm);
ObjectSet("Wedge_L"+IntegerToString(1),OBJPROP_COLOR,LightSeaGreen);
ObjectSet("Wedge_L"+IntegerToString(1),OBJPROP_WIDTH,2);
}
}
}
}
}
//--- Keep Wedges Line
if(CalcWedgeH_Buffer[i-2]>0 && CalcWedgeH_Buffer[i-1]>0)
{
CalcWedgeH_Buffer[i]=CalcWedgeH_Buffer[i-1]+(CalcWedgeH_Buffer[i-1]-CalcWedgeH_Buffer[i-2]);
if(InpWedgeLineMode==2 || InpWedgeLineMode==3)
WedgeH_Buffer[i]=CalcWedgeH_Buffer[i];
}
//--- Keep Wedges Line
if(CalcWedgeL_Buffer[i-2]>0 && CalcWedgeL_Buffer[i-1]>0)
{
CalcWedgeL_Buffer[i]=CalcWedgeL_Buffer[i-1]+(CalcWedgeL_Buffer[i-1]-CalcWedgeL_Buffer[i-2]);
if(InpWedgeLineMode==2 || InpWedgeLineMode==3)
WedgeL_Buffer[i]=CalcWedgeL_Buffer[i];
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+----------------------------------------------------+
//| random func |
//+----------------------------------------------------+
bool random(int x)
{
int ran=MathRand();
bool res=(MathMod(ran,x)==0);
return(res);
}
//+----------------------------------------------------+
//| Regression |
//+----------------------------------------------------+
void calc_regression(double &a,double &b,int span,double &price[])
{
//---
double sumy=0.0; double sumx=0.0; double sumxy=0.0; double sumx2=0.0;
int x;
int cnt=0;
//---
for(x=1; x<=span; x++)
{
//---
if(price[x-1]==0)continue;
sumx+=x;
sumx2+= x*x;
sumy += price[x-1];
sumxy+= price[x-1]*x;
cnt++;
}
//---
double c=sumx2*cnt-sumx*sumx;
if(c==0.0)
{
b=0.0;
a=sumy/cnt;
}
else
{
b=(sumxy*cnt-sumx*sumy)/c;
a=(sumy-sumx*b)/cnt;
a+=b*span;
}
}
//+----------------------------------------------------+
//| angle_line |
//+----------------------------------------------------+
bool angle_line(int &from_pos,double &a,
double &b,
const Point_Type &points[],
int test_pos,
double test_price,
int last_pos,
double limit_high,double limit_low,int dir)
{
//--- init
int p_sz=ArraySize(points);
if(p_sz < 5) return (false);
int maxcnt=0;
double angles[][2];
//--- calc angles
int cnt=calc_angles(angles,points,p_sz,test_pos,test_price);
if(cnt==0)return (false);
//--- sort data
if(dir==1) ArraySort(angles,WHOLE_ARRAY,0,MODE_DESCEND);
else ArraySort(angles);
//--- calc mean
double sum=0.0;
for(int j=0; j<cnt; j++)sum+=angles[j][0];
double mean=sum/cnt;
//--- calc deviation
sum=0.0;
for(int j=0; j<cnt; j++)sum+=MathPow(angles[j][0]-mean,2);
double StdDev=MathSqrt(sum/cnt)*InpLineFilter;
//--- check filter
int idx=0;
bool ok=false;
for(int j=0;j<cnt;j++)
{
//---
idx=j;
//--- check deviation
if((dir==1 && angles[j][0]<mean+StdDev) || (dir==-1 && angles[j][0]>mean-StdDev))
{
//--- check high low limit
double chk_a=(test_price+(last_pos-test_pos)*angles[j][0])*_Point;
if((chk_a<limit_high) && (chk_a>limit_low))
{
ok=true;
break;
}
}
}
if(!ok) return (false);
//--- set result
a=(test_price+(last_pos-test_pos)*angles[idx][0])*_Point;
b=angles[idx][0] * _Point;
from_pos=(int)MathMin(test_pos,angles[idx][1]);
return(true);
//---
}
//+------------------------------------------------------------------+
//| calculating the slope angle of to all vertex from starting points|
//+------------------------------------------------------------------+
int calc_angles(double &angles[][2],const Point_Type &points[],int p_sz,int pos,double price)
{
string s="";
ArrayResize(angles,0,p_sz);
int cnt=0;
for(int j=0;j<p_sz;j++)
{
int x=points[j].pos-pos;
if(x==0)continue;
double y=points[j].point-price;
cnt++;
ArrayResize(angles,cnt,p_sz);
angles[cnt-1][0]=y/x;
angles[cnt-1][1]=points[j].pos;
}
return (cnt);
}
//+------------------------------------------------------------------+
//| better_line |
//+------------------------------------------------------------------+
bool better_line(int &from_pos,double &a,
double &b,
const Point_Type &points[],
double slope_price,
double slope_height,
double slope_dev,
int last_pos,
int dir)
{
//--- init
int p_sz=ArraySize(points);
if(p_sz < 5) return (false);
double distance[][2];
ArrayResize(distance,0,p_sz);
int cnt=0;
int j;
//---
for(j=0;j<p_sz;j++)
{
//---
int x=last_pos-points[j].pos;
if(x==0)continue;
//--- base price
double base_price=(slope_price -(x*slope_height))/_Point;
//--- distance
double dist=(points[j].point-base_price);
//--- check distance by StdDev
if((dist*dir)>slope_dev*0.5/_Point)
{
cnt++;
ArrayResize(distance,cnt,p_sz);
distance[cnt-1][0]= dist;
distance[cnt-1][1]= j;
}
}
//---
if(cnt==0)return(false);
if(dir>0)ArraySort(distance,WHOLE_ARRAY,0,MODE_DESCEND);
else ArraySort(distance);
//---
for(j=0;j<MathMin(cnt,5);j++)
{
//---
int test_pos;
int pos=(int)distance[j][1];
double test_a,test_b;
double limit_high,limit_low;
//---
if(dir==1)
{
limit_high=slope_price+slope_dev*InpDeviations;
limit_low=slope_price-slope_dev*2;
}
else
{
limit_high=slope_price+slope_dev*2;
limit_low=slope_price-slope_dev*InpDeviations;
}
//---
if(angle_line(test_pos,test_a,test_b,points,points[pos].pos,points[pos].point,last_pos,limit_high,limit_low,dir))
{
from_pos=test_pos;
a=test_a;
b=test_b;
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Delete all objects with given prefix |
//+------------------------------------------------------------------+
void cleaningObj(string Prefix)
{
int L = StringLen(Prefix);
int i = 0;
while(i<ObjectsTotal())
{
string ObjName=ObjectName(i);
if(StringSubstr(ObjName,0,L)!=Prefix)
{
i++;
continue;
}
ObjectDelete(ObjName);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool calc_score(double &score,const Point_Type &points[],int test_pos,double test_price,double mean)
{
int p_sz=ArraySize(points);
if(p_sz < 5) return (false);
int maxcnt=0;
double angles[][2];
int cnt=calc_angles(angles,points,p_sz,test_pos,test_price);
if(cnt<4)return (false);
double sum=0.0;
for(int j=0; j<cnt; j++)
{
sum+=MathPow(angles[j][0]-mean,2);
}
//---
score=MathSqrt(sum/cnt);
//---
return (true);
}
//+------------------------------------------------------------------+
//| atr_filter |
//+------------------------------------------------------------------+
bool atr_filter(int sig,int fast,int slow,int pos)
{
double atr1sig=iCustom(Symbol(),PERIOD_CURRENT,"ATR_3LWMA",sig,fast,slow,0,pos+1);
double atr1fast=iCustom(Symbol(),PERIOD_CURRENT,"ATR_3LWMA",sig,fast,slow,1,pos+1);
double atr0sig=iCustom(Symbol(),PERIOD_CURRENT,"ATR_3LWMA",sig,fast,slow,0,pos);
double atr0fast=iCustom(Symbol(),PERIOD_CURRENT,"ATR_3LWMA",sig,fast,slow,1,pos);
double atr0slow=iCustom(Symbol(),PERIOD_CURRENT,"ATR_3LWMA",sig,fast,slow,2,pos);
if(atr0slow<atr0fast && atr0fast<atr0sig && atr1fast<atr0fast)
return(true);
else
return(false);
}
//+------------------------------------------------------------------+