Created
April 5, 2019 12:05
-
-
Save Schellinkhoutkamp/9c5c1a4aa48f50e73ff38b1bac36c56f to your computer and use it in GitHub Desktop.
Jared algos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func rc(t int, x []float64) float64 { | |
if len(x)-2 < t { | |
return 0 | |
} | |
s := float64(0) | |
for j := 0; j < t; j++ { | |
s += x[j] - x[j+1] | |
} | |
return (s / float64(t)) | |
} | |
func sign(x float64) float64 { | |
if x > 0 { | |
return 1 | |
} else if x < 0 { | |
return -1 | |
} else { | |
return 0 | |
} | |
} | |
func dirChange(f []float64, s []float64) bool { | |
if sign(f[0]-s[0]) != sign(f[1]-s[1]) { | |
return true | |
} | |
return false | |
} | |
func sma(t int, xc []float64) float64 { | |
som := float64(0) | |
if len(xc) > t { | |
xc = xc[0:t] | |
} | |
for i := 0; i < len(xc); i++ { | |
som += xc[i] | |
} | |
return som / float64(len(xc)) | |
} | |
func (indicator AlgoIndicators) algo(symbol map[string][]float64) { | |
index := symbol["BNCE_XBTUSD"] | |
magnTresh := index[0] / 500 // start trading from this drop magnitude | |
magnSpeed := magnTresh / 100 // minimal consistent change per second | |
indicator["FAST"][0] = sma(10, index) | |
indicator["SLOW"][0] = sma(30, index) | |
indicator["FASTRC"][0] = rc(30, indicator["FAST"]) | |
indicator["FASTRCF"][0] = rc(10, indicator["FAST"]) | |
indicator["FASTRCFF"][0] = rc(3, indicator["FAST"]) | |
indicator["RCDIFF"][0] = indicator["FASTRCF"][0] - indicator["FASTRC"][0] | |
indicator["FASTRCFFRC"][0] = rc(3, indicator["FASTRCFF"]) | |
if dirChange(indicator["FAST"], indicator["SLOW"]) || len(indicator["FAST"]) < 2 { | |
indicator["DIRTIME"][0] = 0 | |
indicator["DIRMAGN"][0] = 0 | |
//mark("hoi") | |
} else { | |
indicator["DIRTIME"][0] = indicator["DIRTIME"][1] + 1 | |
indicator["DIRMAGN"][0] = indicator["DIRMAGN"][1] + indicator["FAST"][0] - indicator["FAST"][1] | |
} | |
//log(indicator["FAST"][0], indicator["FAST"][1]) | |
func() { | |
if len(indicator["SLOW"]) > int(indicator["DIRTIME"][0]*2) { | |
if indicator["FAST"][0] < indicator["SLOW"][int(indicator["DIRTIME"][0]*2)]+(indicator["DIRTIME"][0]*magnSpeed)/2 { //// should really be a long term drop, not a peak | |
if indicator["DIRMAGN"][0] < (-magnTresh) && indicator["DIRMAGN"][0] < (-indicator["DIRTIME"][0])*magnSpeed { | |
mark("m") | |
if indicator["RCDIFF"][0] > 0 && indicator["FASTRCF"][0] > 0 && indicator["FASTRCFFRC"][0] > 0 && indicator["FAST"][0] < indicator["SLOW"][0] { | |
trade("DROPREBOUND", "BNCE", "XBTUSD", false, 1, 1) | |
} | |
} | |
} | |
} | |
if indicator["RCDIFF"][0] < 0 && indicator["FASTRCFF"][0] < 0 { | |
trade("DROPREBOUND", "BNCE", "XBTUSD", false, -1, 1) | |
} // over the top | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment