Strategy · Pine Script v5 · On the chart

Trading Bot

by FedeHide

This strategy executes long entries during a user-defined backtest time window.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code29
Settings3inputs
LicenceMIT
Last update1 year ago18 Dec 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

FedeHide on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Scalping, Moving averages

Markets

Crypto

Timeframes

M1-M5, M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

pinescripttradingbot

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Fromtimetimestamp("07 Feb 2024 00:00 +0000")i_from
Thrutimetimestamp("11 Feb 2024 00:00 +0000")i_thru
Show Date Rangebooltruei_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.

Similar Pine Scripts

257 stars

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

Strategy v5 Volatility & bandsMoving averages
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint Fixed

5 Minute Scalp

by hasnocool
106 stars

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

Strategy v5 ScalpingMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 5 Minute Scalp
53 stars

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

Strategy v6 TrendMoving averages
Updated 2 months ago · MPL-2.0 GitHub repository of EUR/USD EMA9-21 + RSI Scalping Strategy
43 stars

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.

Strategy v5 Moving averagesSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m Strategy Candle Bar
13 stars

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

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Ruckard TradingZone ADX Gann

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers