Skip to content

Instantly share code, notes, and snippets.

@ivank2139
Created April 5, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivank2139/878ac3eb82bef308a3adeb4e667a0794 to your computer and use it in GitHub Desktop.
Save ivank2139/878ac3eb82bef308a3adeb4e667a0794 to your computer and use it in GitHub Desktop.
The logic for determining if a buy or sell trade is recommended.
func Analyzer() {
readCsvFile()
macd := NewMacd()
rsi := NewRsi()
trend := NewTrend()
obv := NewObv()
priceClose, err := decimal.NewFromString("0")
volume, err := decimal.NewFromString("0")
check(err)
rsiB := false
rsiS := false
bldr.WriteString("\nInitial Cash $" + cash.RoundBank(2).String() + ", Initial Eth " +
eth.RoundBank(2).String() + ", Initial Portfolio value $" + (cash.Add(eth.Mul(priceClose)).RoundBank(2).String()))
tradeworthy := false
for i, snap := range ethSnaps {
priceClose, err = decimal.NewFromString(snap.price)
check(err)
volume, err = decimal.NewFromString(snap.volume)
check(err)
if strings.Contains(snap.date, "2020-04-01") {
testComplate(priceClose, snap.date)
portfolioAdjustment()
}
macd.Update(priceClose)
trend.Update(priceClose)
rsi.Update(priceClose)
obv.Update(priceClose, volume)
rsiB = rsi.IsOverBought()
rsiS = rsi.IsOverSold()
if i > 26 {
if rsiB && macd.Hdn {
sell(snap)
tradeworthy = true
}
if rsiS && macd.Hup {
buy(snap)
tradeworthy = true
}
}
if tradeworthy {
bldr.WriteString("\nAfter trade, cash available $" + cash.RoundBank(2).String() + ", ETH available " +
eth.RoundBank(2).String() + ", portfolio total $" + cash.Add(eth.Mul(priceClose)).RoundBank(2).String() + "\n")
tradeworthy = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment