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

Guide: Sample TradingView Bot (Strategy script)

Ben Ross avatar
Written by Ben Ross
Updated over 2 years ago

This sample code is built for you so you can test the strategy script in your first trading bot on TradingView.

TradingView Bot Study 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=4
strategy("Signal Tester", overlay=true)

///////////////// LONG //////////////////

entry_long = close>open
exit_long = open>close

///////////// SHORT //////////////
entry_short=open>close
exit_short=close>open

strategy.entry("long", strategy.long, when=entry_long, comment="Insert Enter Long Comment Here")
strategy.close("long", when=exit_long, comment="Insert Exit Long Comment Here")

strategy.entry("short", strategy.short, when=entry_short, comment="Insert Enter Short Comment Here")
strategy.close("short", when=exit_short, comment="Insert Exit Short Comment Here")

Note

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

Did this answer your question?