“Buying the dip” – the R script

Free Bitcoins: FreeBitcoin | BonusBitcoin

Coins Kaufen: Bitcoin.deAnycoinDirektCoinbaseCoinMama (mit Kreditkarte)Paxfull

Handelsplätze / Börsen: Bitcoin.de | KuCoinBinanceBitMexBitpandaeToro

Lending / Zinsen erhalten: Celsius NetworkCoinlend (Bot)

Cloud Mining: HashflareGenesis MiningIQ Mining


So last night, I posted a very simple guide table that could help with buying the dip ([https://www.reddit.com/r/CryptoCurrency/comments/pdkxxh/buying_the_dip_suggestion_table/](https://www.reddit.com/r/CryptoCurrency/comments/pdkxxh/buying_the_dip_suggestion_table/)). Since then, I’ve had several requests for how I did it so I thought I’d just make a post about getting setup with coingecko API in RStudio.

1. Download Rstudio from here: [https://www.rstudio.com/](https://www.rstudio.com/).
2. Once setup, create a new .R or .Rmd file and install R packages, which are pre-written scripts that make R pretty fun. To install these packages, run install.packages(“package_name”). Coingecko API has an R package called “geckor” (documentation here: [https://cran.r-project.org/web/packages/geckor/index.html](https://cran.r-project.org/web/packages/geckor/index.html)). Yes R packages, especially those from CRAN, are safe to use. Other packages I frequently use are “dplyr”, “data.table”, “ggplot2”, “Hmisc”. Once packages are installed, you’ll have to use require(“package_name”) or library(“package_name”) at the top of your script to use them in your session. Packages names are case-sensitive – stackoverflow is your best friend.
3. Call coin price in the last 14 days with this code. It’s pretty easy.

geckor::coin_history(coin_id =”bitcoin”, vs_currency = “usd”, days = 14)

4. Once you have the data, you can calculate whatever you like, graph it using ggplot2 or export it as .csv. Possibilities are endless. Just keep in mind that coingecko API does have a call limit/delay so you might have to wait if you overdo it.

5. All together, to recreate the table I posted yesterday, just copy and paste this code and run it! I wrote it late last night and it is not my best work but it should run. I think lol… Stackoverflow should already have all the answers to any and all possible questions you can ask. If not, I’m already to answer any questions.

#####

`require(dplyr)`

`require(geckor)`

`require(Hmisc)`

`require(data.table)`

`cryptos = c(“bitcoin“,”ethereum“,”cardano”,”binancecoin”,”ripple”,”dogecoin”,”solana”,”polkadot”,”uniswap”,”monero”,”vechain”,”tezos”,”algorand”,”moon”)`

`coin_fetcher <- function(coin){return(rbind(geckor::coin_history(coin_id = coin, vs_currency = “usd”, days = 14) %>% mutate(d=14) %>% mutate(n=rev(1:n()))))}`

`tmp <- do.call(rbind, lapply(1:length(cryptos), function(x) coin_fetcher(cryptos[x])))`

`tmp2 <- tmp %>%`

`group_by(coin_id) %>%`

`mutate(current.price = price[which.max(timestamp)]) %>%`

`group_by(coin_id,current.price, d) %>%`

`mutate(volume_correction = total_volume/max(total_volume)) %>%`

`mutate(vol_adj_price = price*volume_correction) %>%`

`summarise(mkt.cap = mean(market_cap), vol.adj.14d.mean=Hmisc::wtd.mean(x=price, w=volume_correction), wtd.sd= sqrt(Hmisc::wtd.var(price)), .groups = ‘drop’) %>%`

`arrange(-mkt.cap) %>%`

`mutate(percent.difference = (current.price-vol.adj.14d.mean)/vol.adj.14d.mean*100, z.score = (current.price-vol.adj.14d.mean)/wtd.sd) %>%`

`mutate(level1.dip = vol.adj.14d.mean-(wtd.sd*1),`

`level2.dip = vol.adj.14d.mean-(wtd.sd*2),`

`level3.dip = vol.adj.14d.mean-(wtd.sd*3)) %>%`

`select(-d,-mkt.cap)`

`export <- data.frame(tmp2[,1],apply(tmp2[,2:ncol(tmp2)], 2, function(x) format(round(x, 4), nsmall = 4)))`

`data.table::fwrite(export, “~/Downloads/todays_table.csv”)`

####

View Reddit by Ahjustsea – View Source

Free Bitcoins: FreeBitcoin | BonusBitcoin

Coins Kaufen: Bitcoin.deAnycoinDirektCoinbaseCoinMama (mit Kreditkarte)Paxfull

Handelsplätze / Börsen: Bitcoin.de | KuCoinBinanceBitMexBitpandaeToro

Lending / Zinsen erhalten: Celsius NetworkCoinlend (Bot)

Cloud Mining: HashflareGenesis MiningIQ Mining

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close