This sample code is built for you so you can play with the automation of 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 exit 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=4study("Signal Tester", overlay=true)///////////////// LONG //////////////////isEntry_Long = falseisEntry_Long := nz(isEntry_Long, false)isExit_Long = falseisExit_Long := nz(isExit_Long, false)entry_long = not isEntry_Long and close>openexit_long = not isExit_Long and open>closeif (entry_long)isEntry_Long := trueisExit_Long := falseif (exit_long)isEntry_Long := falseisExit_Long := true///////////// SHORT //////////////isEntry_Short = falseisEntry_Short := nz(isEntry_Short, false)isExit_Short = falseisExit_Short := nz(isExit_Short, false)entry_short=not isEntry_Short and open>closeexit_short= not isExit_Short and close>openif (entry_short)isEntry_Short := trueisExit_Short := falseif (exit_short)isEntry_Short := falseisExit_Short := truealertcondition(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)
You need a TradingView Pro subscription to be able to receive Webhook notifications on Wunderbit. Sign up to TradingView now.