forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrule_increase_decrease.go
More file actions
33 lines (27 loc) · 931 Bytes
/
rule_increase_decrease.go
File metadata and controls
33 lines (27 loc) · 931 Bytes
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
package techan
// IncreaseRule is satisfied when the given Indicator at the given index is greater than the value at the previous
// index.
type IncreaseRule struct {
Indicator
}
// IsSatisfied returns true when the given Indicator at the given index is greater than the value at the previous
// index.
func (ir IncreaseRule) IsSatisfied(index int, record *TradingRecord) bool {
if index == 0 {
return false
}
return ir.Calculate(index).GT(ir.Calculate(index - 1))
}
// DecreaseRule is satisfied when the given Indicator at the given index is less than the value at the previous
// index.
type DecreaseRule struct {
Indicator
}
// IsSatisfied returns true when the given Indicator at the given index is less than the value at the previous
// index.
func (dr DecreaseRule) IsSatisfied(index int, record *TradingRecord) bool {
if index == 0 {
return false
}
return dr.Calculate(index).LT(dr.Calculate(index - 1))
}