forked from zonquan/TradeStation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfgf.butterfly.txt
133 lines (125 loc) · 3.73 KB
/
sfgf.butterfly.txt
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
[LegacyColorValue = true];
{
Function : sfgf.butterfly
Description : Identify the Butterfly Pattern
Copyright 2016 Scottfree Gains LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}
Inputs:
Pivots(NumericSimple),
PM[MaxSize1, MaxSize2](NumericArrayRef),
Strength(NumericSimple),
Pattern[MaxSize3, MaxSize4](NumericArrayRef),
F1(NumericSimple);
Variables:
PatternPivots(4),
p1(0),
p2(0),
p3(0),
p4(0),
v1(0.0),
v2(0.0),
v3(0.0),
v4(0.0),
s1(0.0),
s2(0.0),
s3(0.0),
s4(0.0),
s5(0.0);
sfgf.butterfly = 0;
If Pivots >= PatternPivots and Strength >= 1 Then Begin
{Bullish Butterfly}
p2 = sfgf.pivothigh(Pivots, PM, 0, Pivots-1, Strength);
p1 = sfgf.pivotlow(Pivots, PM, 0, Pivots-1, Strength);
If p2 >= 0 and p1 >= 0 and
p2 < p1 Then Begin
v2 = High[PM[p2, 0]];
v1 = Low[PM[p1, 0]];
p3 = sfgf.pivotlow(Pivots, PM, 0, p2-1, Strength);
If p3 >= 0 and v2 > v1 Then Begin
v3 = Low[PM[p3, 0]];
p4 = sfgf.pivothigh(Pivots, PM, 0, p3-1, Strength);
If p4 >= 0 and v3 > v1 and v3 < v2 Then Begin
v4 = High[PM[p4, 0]];
If v4 > v3 and v4 < v2 Then Begin
s1 = v2 - v1;
s2 = v2 - v3;
s3 = v4 - v3;
s4 = v4 - Close;
s5 = v2 - Close;
If s2 < s1 and s3 < s2 and s4 > s2 and s5 >= F1 * s1 and
Low < v1 Then Begin
Pattern[1, 0] = PM[p1, 0];
Pattern[1, 1] = PM[p1, 1];
Pattern[1, 2] = PM[p1, 2];
Pattern[1, 3] = PM[p1, 3];
Pattern[2, 0] = PM[p2, 0];
Pattern[2, 1] = PM[p2, 1];
Pattern[2, 2] = PM[p2, 2];
Pattern[2, 3] = PM[p2, 3];
Pattern[3, 0] = PM[p3, 0];
Pattern[3, 1] = PM[p3, 1];
Pattern[3, 2] = PM[p3, 2];
Pattern[3, 3] = PM[p3, 3];
Pattern[4, 0] = PM[p4, 0];
Pattern[4, 1] = PM[p4, 1];
Pattern[4, 2] = PM[p4, 2];
Pattern[4, 3] = PM[p4, 3];
sfgf.butterfly = PatternPivots;
End;
End;
End;
End;
End;
{Bearish Butterfly}
p1 = sfgf.pivothigh(Pivots, PM, 0, Pivots-1, Strength);
p2 = sfgf.pivotlow(Pivots, PM, 0, Pivots-1, Strength);
If p1 >= 0 and p2 >= 0 and
p2 < p1 Then Begin
v1 = High[PM[p1, 0]];
v2 = Low[PM[p2, 0]];
p3 = sfgf.pivothigh(Pivots, PM, 0, p2-1, Strength);
If p3 >= 0 and v1 > v2 Then Begin
v3 = High[PM[p3, 0]];
p4 = sfgf.pivotlow(Pivots, PM, 0, p3-1, Strength);
If p4 >= 0 and v3 < v1 and v3 > v2 Then Begin
v4 = Low[PM[p4, 0]];
If v4 < v3 and v4 > v2 Then Begin
s1 = v1 - v2;
s2 = v3 - v2;
s3 = v3 - v4;
s4 = Close - v4;
s5 = Close - v2;
If s2 < s1 and s3 < s2 and s4 > s2 and s5 >= F1 * s1 and
High > v1 Then Begin
Pattern[1, 0] = PM[p1, 0];
Pattern[1, 1] = PM[p1, 1];
Pattern[1, 2] = PM[p1, 2];
Pattern[1, 3] = PM[p1, 3];
Pattern[2, 0] = PM[p2, 0];
Pattern[2, 1] = PM[p2, 1];
Pattern[2, 2] = PM[p2, 2];
Pattern[2, 3] = PM[p2, 3];
Pattern[3, 0] = PM[p3, 0];
Pattern[3, 1] = PM[p3, 1];
Pattern[3, 2] = PM[p3, 2];
Pattern[3, 3] = PM[p3, 3];
Pattern[4, 0] = PM[p4, 0];
Pattern[4, 1] = PM[p4, 1];
Pattern[4, 2] = PM[p4, 2];
Pattern[4, 3] = PM[p4, 3];
sfgf.butterfly = -PatternPivots;
End;
End;
End;
End;
End;
End;