Skip to main content
All CollectionsTrading BotsSignal Bot
Sample TradingView Bot (Indicator script)
Sample TradingView Bot (Indicator script)

Guide: Code for the free sample TradingView Bot (based on the Indicator script)

Ben Ross avatar
Written by Ben Ross
Updated over 4 months ago

This sample code is built for you so you can check the automation of your first trading bot on TradingView.

TradingView Bot Indicator includes both Long and Short positions.

This strategy enters the long position if the price of the asset increased during the previous candle (the close price was higher than the open price) and exits the long position if the price of the asset decreased during the previous candle (close price was lower than the open price). The opposite is true for the Short position. Therefore, when the exit long signal is executed it will automatically trigger the entry into the short position. This code can be applied to any timeframe and any asset.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Wunderbit Trading (WBT)

//@version=5
indicator("Signal Tester", overlay=true)

///////////////// LONG //////////////////
isEntry_Long = false
isEntry_Long := nz(isEntry_Long[1], false)

isExit_Long = false
isExit_Long := nz(isExit_Long[1], false)

entry_long = not isEntry_Long and close>open
exit_long = not isExit_Long and open>close

if (entry_long)
isEntry_Long := true
isExit_Long := false

if (exit_long)
isEntry_Long := false
isExit_Long := true

///////////// SHORT //////////////

isEntry_Short = false
isEntry_Short := nz(isEntry_Short[1], false)

isExit_Short = false
isExit_Short := nz(isExit_Short[1], false)


entry_short=not isEntry_Short and open>close
exit_short= not isExit_Short and close>open

if (entry_short)
isEntry_Short := true
isExit_Short := false

if (exit_short)
isEntry_Short := false
isExit_Short := true

alertcondition(entry_long, title="Enter Long")
alertcondition(exit_long, title="Exit Long")
alertcondition(entry_short, title="Enter Short")
alertcondition(exit_short, title="Exit Short")

plotshape(series=entry_long, text="Long", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(series=exit_long, text="EXIT Long",style=shape.triangledown, location=location.abovebar, color=color.purple, size=size.small)
plotshape(series=entry_short, text="Short", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
plotshape(series=exit_short, text="EXIT Short",style=shape.triangleup, location=location.belowbar, color=color.purple, size=size.small)

Note

You need a TradingView Pro subscription to be able to receive Webhook notifications on WunderTrading.

Did this answer your question?