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.
This is a step by step guide on how to create an Algo Trading Bot, that CAN make you money while you sleep.
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..
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)
4. Now Click (1) “Save”
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
Now lets enter our own parameters to check this strategy suits are needs and its profitability
4. The settings page will vary dependent on the underlying strategy
The settings we want to focus on
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
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
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
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
If this is not exact then the bot will not function as required…
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.
// STRATEGY
if (buySignal)
strategy.entry("Long", strategy.long)
if (sellSignal)
strategy.entry("Short", strategy.short)
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