- Build Functions and Call Libraries
- Store Variables
- Trading Loop Executes
- Automating the Script Using Windows Task Scheduler
We’ll be using Windows task scheduler for code execution and the Coinbase exchange, so Bisley you’re going to need a CoinbasePro account. This shouldn’t be any kind of hardship though because it’s an excellent platform with an excellent interface. You will also use a Gmail account to send orders and pickup notifications of trades.
Build Functions and Call Libraries
Call libraries are the first thing you going to need, and here are some of the main ones we will use:
The GDAX interface comes from the rgdax package and mailR handles the email updates. Stringi assists with passing numbers from JSON, and TTR helps with calculating technical indicators. Here are a few of the functions that you will need:
RSI - RSI stands for Relative Strength Index and it’s a prime indicator with this strategy.
Bid & ask - This one tells you the present bid and ask prices.
Usd_hold, eth_hold & cancel_orders - Both the usd_hold and eth_hold functions are there to assist with obtaining the present status of placed orders, and they’ll be doing this a lot. The cancel_order function has the job of scratching orders that have shifted too low in the order book.
Buy_exe - This one has a number of steps. The order_size function works out how much crypto you can purchase. The WHILE function sets limit orders while you still have no crypto. When an order has been placed at a particular bid price, the system waits until the order has been filled. If this doesn’t happen then the process simply runs through again.
Trading Loop Executes
We’ll get started with the loop when the balance of the account is above 25 GBP. If the present RSI is greater than or equal to 35 and the previous RSI was lower than 35 on at least one occasion, then we buy as much ETH as we can using the present GBP balance, then we save the price in a spreadsheet file.
Once this is done, we receive an email from ourselves as a reminder of the buy action. The loop then prints “buy” for tracking in the log file. The system will then sleep for approximately three seconds, then we enter a total of three sell orders with different limits to realize the profits. The first one takes profit at 1% gain, the second at 4% and the third at 7%. So that’s what the script does.
Automating the Script Using Windows Task Scheduler
schedule script with Rstudio add-in
alter scheduled task with task scheduler
use log file so you know what’s going on