Strategy · Pine Script v5 · On the chart

Buy/Sell Signal Template/Boilerplate Strategy [ExoMaven]

by hasnocool· code credited to ExoMaven

This boilerplate strategy script acts as a customizable template for generating buy and sell signals based on price or source crossovers relative to defined fixed values.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code20
Settings5inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 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

20 lines of Pine Script v5 from Buy-Sell Signal Template-Boilerplate Strategy [JacobMagleby].pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Buy-Sell Signal Template-Boilerplate Strategy [JacobMagleby].pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ExoMaven
//@version=5
strategy(title = "Buy/Sell Signal Template/Boilerplate Strategy[ExoMaven]", shorttitle = "Buy/Sell Signal Template Strategy[V1]", overlay = true)
source = input.source(title = "Source", defval = ohlc4, group = "Source Settings")
buy_type = input.string(title = "Buy Type", defval = "Greater Than", options = ["Greater Than", "Less Than"], group = "Signal Settings")
buy_value  = input.float(title = "Buy Value", defval = 50, group = "Signal Settings")
sell_type = input.string(title = "Sell Type", defval = "Less Than", options = ["Less Than", "Greater Than"], group = "Signal Settings")
sell_value = input.float(title = "Sell Value", defval = 50, group = "Signal Settings")
buy_above_or_below = buy_type == "Greater Than" ? source > buy_value and source[1] < buy_value : source < buy_value and source[1] > buy_value
sell_above_or_below = sell_type == "Less Than" ? source < sell_value and source[1] > sell_value : source > sell_value and source[1] < sell_value
buy = buy_above_or_below and barstate.isconfirmed
sell = sell_above_or_below and barstate.isconfirmed
if buy
    strategy.close_all()
    strategy.entry(id = "Buy", direction = strategy.long)
if sell
    strategy.close_all()
    strategy.entry(id = "Sell", direction = strategy.short)
Expand (27 lines)

Overview

Users can select an input source, set threshold values, and specify whether to trigger entries when the source moves greater than or less than those values. When a buy or sell condition is met on a confirmed bar, the strategy closes existing positions and opens new long or short entries directly on the chart. Note that this basic template does not include stop-loss or take-profit rules.

Details

Published by

hasnocool on GitHub

Code credit

ExoMaven, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Sourcesourceohlc4source
Buy TypestringGreater Thanbuy_type
Buy Valuefloat50buy_value
Sell TypestringLess Thansell_type
Sell Valuefloat50sell_value
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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
330 stars

This strategy divides a fixed price range between an upper and a lower limit into equally spaced grid levels and plots them on the price chart. It marks a buy when price crosses down through a grid and a sell when price crosses up through a grid, using either

Strategy v5 Support & resistanceMean reversion Repaints
Updated 2 months ago · None stated GitHub repository of Grid Bot Simulator [Alorse]
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

STRG-HOLP

by harryguiacorn
219 stars

STRG-HOLP is a trading strategy that identifies High of Low Period (HOLP) and Low of High Period (LOHP) breakout setups. It tracks the lowest low or highest high over a user-defined lookback window. A long trade opens when the close breaks above the high of th

Strategy v5 BreakoutSupport & resistance
Updated 1 year ago · None stated GitHub repository of STRG-HOLP
105 stars

Gold Scalping BOS & CHoCH is an overlay strategy designed for detecting market structure shifts. It calculates rolling swing highs and lows to identify Break of Structure (BOS) and Change of Character (CHoCH) events. Long signals trigger when bullish BOS and C

Strategy v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of Gold Scalping BOS & CHoCH

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