forked from zonquan/TradeStation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfgf.pivotmap.txt
95 lines (87 loc) · 2.25 KB
/
sfgf.pivotmap.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
[LegacyColorValue = true];
{
Function : sfgf.pivotmap
Description : Find the pivots in a given window
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:
Window(NumericSimple),
Pivots(NumericSimple),
PM[MaxSize1, MaxSize2](NumericArrayRef);
Variables:
pc(0),
ib(0),
ip(0),
TheHigh(False),
TheLow(False),
offset(0),
p(0),
s(0);
sfgf.pivotmap = 0;
If Window >= 3 and Pivots >= 1 Then Begin
{Find pivots}
pc = 0;
ib = 1;
While ib < Window and pc < Pivots Begin
If High[ib] >= High[ib-1] and High[ib] > High[ib+1] Then Begin
PM[pc, 0] = ib;
PM[pc, 1] = 1; {High Pivot}
PM[pc, 3] = BarNumber - ib;
pc = pc + 1;
End;
If Low[ib] <= Low[ib-1] and Low[ib] < Low[ib+1] Then Begin
PM[pc, 0] = ib;
PM[pc, 1] = -1; {Low Pivot}
PM[pc, 3] = BarNumber - ib;
pc = pc + 1;
End;
ib = ib + 1;
End;
{Calculate strength for each pivot}
For ip = 0 to pc-1 Begin
{Initialize}
p = PM[ip, 0];
offset = 1;
s = 0;
{High Pivot}
If PM[ip, 1] = 1 Then Begin
TheHigh = True;
While TheHigh Begin
If p-offset >= 0 and p+offset <= Window Then Begin
If High[p] >= High[p-offset] and High[p] >= High[p+offset] Then
s = s + 1
Else
TheHigh = False;
End Else
TheHigh = False;
offset = offset + 1;
End;
End;
{Low Pivot}
If PM[ip, 1] = -1 Then Begin
TheLow = True;
While TheLow Begin
If p-offset >= 0 and p+offset <= Window Then Begin
If Low[p] <= Low[p-offset] and Low[p] <= Low[p+offset] Then
s = s + 1
Else
TheLow = False;
End Else
TheLow = False;
offset = offset + 1;
End;
End;
{Assign strength}
PM[ip, 2] = s;
End;
sfgf.pivotmap = pc;
End;