-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfisher.go
62 lines (59 loc) · 1.8 KB
/
fisher.go
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
package main
import (
"fmt"
"log"
)
func sell(target, currentClosedPrice float64) bool {
//Target reached
if currentClosedPrice >= target {
if previousClosedPrice == 0 {
log.Println("target reached ! Now wait the best price")
} else {
//Check IF SELL
if previousClosedPrice > currentClosedPrice {
//CHECK IF HOLD
if currentHoldCount >= maxHoldCount {
log.Println("Don't wait anymore, SELL !")
return true
} else {
currentHoldCount = currentHoldCount + 1
log.Println(fmt.Sprintf("Args ! The current price (%v) is lower than the previous one (%v), hold on...", currentClosedPrice, previousClosedPrice))
}
} else {
log.Println(fmt.Sprintf("Good, the current price (%v) is better than the previous one (%v), wait", currentClosedPrice, previousClosedPrice))
}
}
previousClosedPrice = currentClosedPrice
} else {
currentHoldCount = 0
previousClosedPrice = 0
}
return false
}
func buy(target, currentClosedPrice float64) bool {
//Target reached
if currentClosedPrice <= target {
if previousClosedPrice == 0 {
log.Println("target reached ! Now wait the best price")
} else {
//Check IF BUY
if previousClosedPrice < currentClosedPrice {
//CHECK IF HOLD
if currentHoldCount >= maxHoldCount {
log.Println("Don't wait anymore, BUY !")
return true
} else {
currentHoldCount = currentHoldCount + 1
log.Println(fmt.Sprintf("Args ! The current price (%v) is higher than the previous one (%v), hold on...", currentClosedPrice, previousClosedPrice))
}
} else {
log.Println(fmt.Sprintf("Good, the current price (%v) is better than the previous (%v), wait", currentClosedPrice, previousClosedPrice))
}
}
previousClosedPrice = currentClosedPrice
} else {
currentHoldCount = 0
previousClosedPrice = 0
}
return false
}