img

Learn how to Create a Crypto Algorithmic Trading bot for beginners

img
valuezone 26 July 2023

Learn how to Create a Crypto Algorithmic Trading bot for beginners

In this tutorial I’m going to show you how to replicate any trading strategy using Trading View and turn it into your own trading bot.

Outcome = An Automatic Algorithmic Trading Bot 24/7

This is a step by step guide on how to create an Algo Trading Bot, that CAN make you money while you sleep.

Step 1

In this tutorial I will show you only how to setup the bot and how to perform your backtest. (DYOR into which strategy you want to use)

Look around and find something that interests you!

We are going to use..


Step 2

Now you have found your strategy, scroll to the bottom of the page until you find the code


Im going to paste the code here, so that you can follow along with me

//@version=5
strategy(title='[SMT] Buy & Sell Renko Based - Strategy', shorttitle='[SMT] B&S Renko', overlay=true)

//INPUTS
renkoATRLength = input.int(10, minval=1, title='ATR Length')

//CALCULATION
param = ticker.renko(syminfo.tickerid, 'ATR', renkoATRLength)

renkoClose = request.security(param, timeframe.period, close)
renkoOpen = request.security(param, timeframe.period, open)

buySignal = ta.crossunder(renkoOpen, renkoClose)
sellSignal = ta.crossover(renkoOpen, renkoClose)

col = renkoClose < renkoOpen ? #F23645 : #089981

//PLOTS
plot(renkoOpen, title="Renko Open", style=plot.style_line, linewidth=2, color=col)
plotshape(buySignal, "Buy", shape.labelup, location.belowbar, #089981, 0, "Buy", color.white)
plotshape(sellSignal, "Sell", shape.labeldown, location.abovebar, #F23645, 0, "Sell", color.white)

// STRATEGY
if (buySignal)
strategy.entry("Long", strategy.long)
if (sellSignal)
strategy.entry("Short", strategy.short)
  1. Click “copy code”
  2. Next we are going to implement this strategy onto the charts, so for tutorial sake let use BTC/USDT on the OKX Futures
  3. Once the chart is open, Click “Pine Editor” and paste the Strategy code

4. Now Click (1) “Save”

  • (2) Add to chart

Your strategy is now implemented on to your chart

that was easy right…


Trading view offers a easy user interface to test any given Strategy

Step 3

Backtest and Parameters

Now lets enter our own parameters to check this strategy suits are needs and its profitability

  1. Click “Settings”

4. The settings page will vary dependent on the underlying strategy

The settings we want to focus on

  • Initial Capital — The capital you want to trade
  • Order Size — The size of the trade vs our initial capital
  • Commission — The trading fees charged from your respective exchange

Note — you can play around with these settings to see how it effects the profitability

5. Now the parameters are set we can see the results of past trades

note — these parameters will effect the entry / exit signals evidently altering the backtest

  • These results are from Jan 2022 — Current
  • Total Trades = 1490

Im not going to get into the technicalities of the results as I want to focus this tutorial towards getting the bot operational.

Im trying keep this post as short as possible!

6. Now we are happy with our strategy and ready to deploy

Step 4

Wunder Trading Integration

So for this next part we need to create the bot that will perform the trades for us.

For this next step you will require the following details from the trading view chart

Chart timeframe — 1hr

Pair — BTC/USDT

Exchange — OKX

  1. Open WunderTrader
  2. Click “My Bots” , “Add New”

Your Page now look like this..

3. Lets fill in the details of the bot — It is Essential to match all setting from trading view here

  • Time Frame
  • Available Pair
  • Exchange
  • API to which exchange you want to trade

If this is not exact then the bot will not function as required…

  • Important to note — As the buy / Sell position will be placed simultaneously, we must not set the position amount to 100%. There needs to be excess funds in the account to place both positions.
  • Set to 10% while configuring
  • Next Click “Swing Trade” —This option, once a signal is received in either direction, the current position will be closed and re opened in the opposite direction.

Stop Loss — Yes it is important to have a backup in place and you can set this to your own desires — remember that the trading view strategy tester did not take into account a stop loss. Meaning your results will vary drastically.

  • It is possible to rewrite the strategy to take into account a stop loss

Your page should look similar to this..

5. Next this is where the fun begins, we need to utilise these “comments”


6. Take note of the “Enter Long” and “Enter Short”, we must now place this in the strategy buy/sell operation of the code.

  • Open Trading View back up and scroll down to where you see this
// STRATEGY
if (buySignal)
strategy.entry("Long", strategy.long)
if (sellSignal)
strategy.entry("Short", strategy.short)
  • we need to modify the “if statement” to include the “Enter Long” & “Enter Short” Statements

Copy the below and replace with your “Enter Long” & “Enter Short” comments

comment="ENTER-LONG_OKEX-SWAP_BTC-USDT-SWAP_BTC-Example-bot_1H_ce208ab4a240ce"
comment= "ENTER-SHORT_OKEX-SWAP_BTC-USDT-SWAP_BTC-Example-bot_1H_ce208ab4a240ce"

Now place here,

// STRATEGY
if (buySignal)
strategy.entry("Long", strategy.long, comment="ENTER-LONG_OKEX-SWAP_BTC-USDT-SWAP_BTC-Example-bot_1H_ce208ab4a240ce")
if (sellSignal)
strategy.entry("Short", strategy.short, comment= "ENTER-SHORT_OKEX-SWAP_BTC-USDT-SWAP_BTC-Example-bot_1H_ce208ab4a240ce")

We are getting close, Good job

Final Outcome

//@version=5
strategy(title='[SMT] Buy & Sell Renko Based - Strategy', shorttitle='[SMT] B&S Renko', overlay=true)

//INPUTS
renkoATRLength = input.int(10, minval=1, title='ATR Length')

//CALCULATION
param = ticker.renko(syminfo.tickerid, 'ATR', renkoATRLength)

renkoClose = request.security(param, timeframe.period, close)
renkoOpen = request.security(param, timeframe.period, open)

buySignal = ta.crossunder(renkoOpen, renkoClose)
sellSignal = ta.crossover(renkoOpen, renkoClose)

col = renkoClose < renkoOpen ? #F23645 : #089981

//PLOTS
plot(renkoOpen, title="Renko Open", style=plot.style_line, linewidth=2, color=col)
plotshape(buySignal, "Buy", shape.labelup, location.belowbar, #089981, 0, "Buy", color.white)
plotshape(sellSignal, "Sell", shape.labeldown, location.abovebar, #F23645, 0, "Sell", color.white)

// STRATEGY
if (buySignal)
strategy.entry("Long", strategy.long, comment="ENTER-LONG_OKEX-SWAP_BTC-USDT-SWAP_BTC-BLLGNRSI_1M_9396f9641adefe83")
if (sellSignal)
strategy.entry("Short", strategy.short, comment="ENTER-LONG_OKEX-SWAP_BTC-USDT-SWAP_BTC-BLLGNRSI_1M_9396f9641adefe83")

Once your code is updated in trading view with the new comments, click “Save” & “Add to chart”

Your chart should look like this