Strategy · Pine Script v5 · On the chart

Advanced Crypto Trading Strategy

by mercyplaisir· code credited to mercy2466

A long-only strategy hard-coded to the BTCUSDT 5-minute series through a security request.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code42
Settings0inputs
LicenceMIT
Last update3 years ago1 Feb 2023

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

42 lines of Pine Script v5 from btcusdt_5min/code.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

code.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mercy2466

//@version=5
strategy("Advanced Crypto Trading Strategy",default_qty_value = 0.0042, overlay=true)

// Define Variables
symbol = "BTCUSDT"
timeframe = "5"
smaLength = 9
atrLength = 14
rsiLength = 14
profit_percent = 1.0/100.0
stop_loss = 5.0/100.0

// Get data
price = request.security(symbol, timeframe, close)
sma = ta.sma(price, smaLength)
atr = request.security(symbol,timeframe,ta.atr(atrLength))
rsi = ta.rsi(price, rsiLength)

// Buy signal
buySignal = ta.cross(price, sma) and rsi < 50

// Sell signal
sellSignal = price > (strategy.position_avg_price + (strategy.position_avg_price * profit_percent))

// Trailing Stop
stopPrice = strategy.position_avg_price * (1 - (atr * stop_loss))

// Trade management
if (buySignal)
    strategy.entry("Long", strategy.long, stop = stopPrice, comment = "Buy")

if (sellSignal)
    strategy.close_all(comment = "Sell")

// Plot Indicators
plot(price, color = color.blue, linewidth = 2, title = "Price")
plot(sma, color = color.red, linewidth = 2, title = "SMA")
plot(atr, color = color.green, linewidth = 2, title = "ATR")
plot(rsi, color = color.orange, linewidth = 2, title = "RSI", style = plot.style_areabr)

Overview

Advanced Crypto Trading Strategy enters long when price crosses a 9-period simple moving average while RSI is below 50. It closes all positions when price is one percent above the average entry price. The only protective level is a stop order price derived from the entry price and ATR, used as the entry stop, so it is not a true stop loss. There are no inputs. It plots price, SMA, ATR and RSI values together on the chart.

Details

Published by

mercyplaisir on GitHub

Code credit

mercy2466, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Moving averages, Mean reversion

Markets

Crypto

Timeframes

M1-M5

Risk Notes

  • The strategy enters trades without a stop loss
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

218 stars

The Mean Reversion Strategy Template calculates a baseline mean using SMA, EMA, or VWAP alongside upper and lower deviation bands based on standard deviation, ATR, or percentage offsets. It generates long and short entries when price touches, bounces from, or

Strategy v6 Mean reversionMoving averages
Updated 3 months ago · None stated GitHub repository of Mean Reversion Strategy Template

This strategy draws on the price chart and combines Stochastic RSI, the Money Flow Index, and an exponential moving average to open long or short trades. Longs use the lower oscillator thresholds and shorts use the upper ones, with direction limited to longs,

Strategy v5 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
53 stars

This strategy identifies long entry opportunities based on short-term price pullbacks below a major trend filter. It enters long when three consecutive lower closes occur below the 200-period simple moving average, followed by the current bar closing back abov

Strategy v6 TrendMoving averages
Updated 2 months ago · MPL-2.0 GitHub repository of Ivan Scherman Pattern - TP/SL

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