1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
29 lines of Pine Script v5 from trading-bot.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
trading-bot.pine
//@version=5
strategy(title = "trading-bot", shorttitle = "trading-bot", overlay = true, format = format.price,
default_qty_type = strategy.cash, default_qty_value = 10000, initial_capital = 10000, currency = currency.USDT,
slippage = 0, commission_type = strategy.commission.percent, commission_value = 0)
// INPUT BACKTEST RANGE
i_from = input.time(defval = timestamp("07 Feb 2024 00:00 +0000"), title = "From")
i_thru = input.time(defval = timestamp("11 Feb 2024 00:00 +0000"), title = "Thru")
// INPUT SHOW PLOT
i_show = input(defval = true, title = "Show Date Range")
date() => time >= i_from and time <= i_thru // create date function "within window of time"
ema_value = ta.ema(close, 1) // calculate EMA
// EXECUTION
if date()
strategy.entry("Long", strategy.long)
profit = strategy.position_avg_price * 1.001
if strategy.position_size > 0 // If position is long
if ema_value > profit// exit if price is 0.1% above entry price
strategy.close("Long") // Close long position
// PLOTTING
bgcolor(color = i_show and date() ? color.new(color.gray, 90) : na) // plot if "Show Date Range" and "within window of time"
Overview
Trading Bot calculates a 1-period Exponential Moving Average (EMA) and enters long trades automatically within the specified dates. Positions exit when the calculated EMA exceeds the position's average entry price by 0.1 percent. The script highlights the active date range directly on the main price chart. Key input settings control the start date, end date, and background visibility. A notable limitation is the total absence of a stop-loss mechanism.
Configurable backtest date range window
Automated long entry execution within date window
0.1 percent profit target exit logic using 1-period EMA
Background chart highlighting for active trading range
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
From
time
timestamp("07 Feb 2024 00:00 +0000")
i_from
Thru
time
timestamp("11 Feb 2024 00:00 +0000")
i_thru
Show Date Range
bool
true
i_show
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy is designed for 1-minute S&P 500 futures trading using multi-timeframe data and Fibonacci-weighted standard deviation bands around volume-weighted moving averages. It requests data from multiple higher timeframes without lookahead to prevent repa
This strategy overlays three exponential moving averages on the price chart, with periods of 9, 50, and 200. It calculates a MACD histogram from a 1-minute timeframe, applies Bollinger Bands to the histogram, and tracks two RSI oscillators of different lengths
This strategy trades EUR/USD on the price chart using a fast and slow exponential moving average crossover filtered by RSI. It enters long when the fast EMA crosses above the slow EMA while RSI is above 50 and below the overbought level, and enters short on th
Gold Scalping BOS & CHoCH with MA Filter is a strategy that identifies market structure shifts using Break of Structure (BOS) and Change of Character (CHoCH) signals alongside exponential moving average trend filters. Long trades enter when bullish BOS, bullis
This strategy trades SOL perpetual candles on the price chart. It tracks confirmed pivot highs and lows as support and resistance circles, then compares close with a smoothed filter and a three-period EMA to mark long and short conditions after the bar closes.
This strategy plots on the price chart and enters from a moving-average filter, ADX and Gann colours. Price above a 200-period EMA allows only longs; price below allows only shorts. A Gann aqua colour with ADX above a key level opens a long, and a Gann brown c