Last active
April 14, 2019 08:40
-
-
Save Schellinkhoutkamp/2e4c8c7c0c94549ceb7bba939145e910 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 testing(t int, xc[]float64)float64{ | |
//rs := float64(0) | |
totalGain := float64(0) | |
totalLoss := float64(0) | |
if len(xc) > t { | |
xc = xc[0:t] | |
} | |
for i := 1; i < len(xc); i++ { | |
previous := xc[i] | |
current := xc[i-1] | |
// convert string to float64 | |
previousClose := previous | |
currentClose := current | |
difference := currentClose - previousClose | |
if difference >= 0 { | |
totalGain += difference | |
} else { | |
totalLoss -= difference | |
} | |
} | |
rs := totalGain / totalLoss | |
return 100 - 100/(1+rs) | |
} | |
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)) | |
} | |
// hierboven declare je alleen functions die je later gaat aanroepen. | |
// ALGO | |
func (indicator AlgoIndicators) algo(symbol map[string][]float64) { // BEGIN VAN ALLE ACTIE | |
// hierbinnen voer je al je werk uit. eventueel met gebruikmaking van bovenaan gedeclarede functie | |
index := symbol["BNCE_XBTUSD"] | |
indicator["SMAFAST"][0] = sma(20, index) | |
indicator["SMASLOW"][0] = sma(45, index) | |
indicator["SMADIFF"][0] = indicator["SMAFAST"][0]-indicator["SMASLOW"][0] | |
indicator["RSIREMCO"][0] = testing(14, index) | |
// TRADE | |
func() { // dit is een anonieme functie. Dus die declare je niet, maar voer je meteen uit. Daarom hoort ie binnen de hoofdfunctie algo() | |
if /*indicator["SMAFAST"][0] > indicator["SMASLOW"][0] && */ indicator["SMADIFF"][0] > 3 && indicator["RSIREMCO"][0] < 20 && indicator["RSIREMCO"][0] > indicator["RSIREMCO"][1] { | |
trade("RISE", "BNCE", "XBTUSD", false, 1, 1) | |
} | |
if /*indicator["SMAFAST"][0] < indicator["SMASLOW"][0] && */indicator["SMADIFF"][0] < -3 && indicator["RSIREMCO"][0] > 80 && indicator["RSIREMCO"][0] < indicator["RSIREMCO"][1]{ | |
trade("RISE", "BNCE", "XBTUSD", false, -1, 1) // dit is een sell | |
// naam := "RISE"; exchange := "BNCE"; pair := "XBTUSD"; short:=true; quantity := -1; /* negatief is sell */ leverage := 1 | |
//ik noem hem nog steeds RISE, want als ze dezelfde naam hebben houdt de machine rekening met de om-en-om buy-sell-buy-sell | |
//trade(naam, exchange, pair, short, quantity, leverage) | |
// je kunt hem ook anders noemen, dan zijn ze volledig onafhankelijk. het is logisch om de naam in paren te gebruiken | |
} | |
}() | |
} // EINDE VAN ALLE ACTIE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment