Strategy · Pine Script v6 · On the chart

BTCUSD 5M Optimized Strategy

by Ahmed-GoCode· code credited to Ahmed - Quant-Edge Indicators

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low.

View on GitHub

GitHub stars53on the repository
Pine versionv6current
Lines of code71
Settings18inputs
LicenceMPL-2.0
Last update2 months ago17 Aug 2026

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

71 lines of Pine Script v6 from Quant-Edge-Indicators/Trend & Breakout/BTCUSD 5M Strategy.pinescript, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

BTCUSD 5M Strategy.pinescript
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ahmed - Quant-Edge Indicators
//@version=6
strategy("BTCUSD 5M Optimized Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === INPUTS ===
emaLen = input.int(200, title="EMA Length")
macdFast = input.int(12, title="MACD Fast")
macdSólow = input.int(26, title="MACD Sólow")
macdSignal = input.int(9, title="MACD Signal")
rsiLen = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought")
rsiOversold = input.int(30, title="RSI Oversold")
atrLen = input.int(14, title="ATR Length")
atrMult = input.float(1.5, title="ATR Stop Loss Multiplier")
tpMult = input.float(2.0, title="Take Profit Multiplier")
adxLen = input.int(14, title="ADX Length")
adxThresh = input.float(20, title="ADX Threshold")
trailATRMult = input.float(1.0, title="Trailing Stop ATR Multiplier")
volMultiplier = input.float(1.0, title="Volume Multiplier for Entry")
breakoutLookback = input.int(10, title="Breakout Lookback Bars")
// === TIME FILTER ===
useTimeFilter = input.bool(true, title="Use Time Filter")
startHour = input.int(8, title="Start Hour")
endHour = input.int(20, title="End Hour")
isInTime = not useTimeFilter or (hour >= startHour and hour < endHour)
// === INDICATORS ===
ema = ta.ema(close, emaLen)
[macdLine, signalLine, _] = ta.macd(close, macdFast, macdSólow, macdSignal)
rsi = ta.rsi(close, rsiLen)
atr = ta.atr(atrLen)
// Manual ADX Calculation
upMove = high - high[1]
downMove = low[1] - low
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0
trur = ta.rma(ta.tr(true), adxLen)
plusDI = 100 * ta.rma(plusDM, adxLen) / trur
minusDI = 100 * ta.rma(minusDM, adxLen) / trur
dx = 100 * math.abs(plusDI - minusDI) / (plusDI + minusDI)
adx = ta.rma(dx, adxLen)
avgVol = ta.sma(volume, 20)
// === CONDITIONS ===
trendUp = close > ema
trendDown = close < ema
macdBull = macdLine > signalLine
macdBear = macdLine < signalLine
rsiLong = rsi < rsiOverbought
rsiShort = rsi > rsiOversold
adxStrong = adx > adxThresh
volOk = volume > avgVol * volMultiplier
breakoutLong = close > ta.highest(close[1], breakoutLookback)
breakoutShort = close < ta.lowest(close[1], breakoutLookback)
longCondition = trendUp and macdBull and rsiLong and adxStrong and volOk and breakoutLong and isInTime
shortCondition = trendDown and macdBear and rsiShort and adxStrong and volOk and breakoutShort and isInTime
// === ENTRY ===
if (longCondition)
    strategy.entry("Long", strategy.long)
if (shortCondition)
    strategy.entry("Short", strategy.short)
// === ATR-based TARGETS ===
longSL = close - atr * atrMult
longTP = close + atr * atrMult * tpMult
shortSL = close + atr * atrMult
shortTP = close - atr * atrMult * tpMult
// === TRAILING STOP ===
trailingLong = atr * trailATRMult
trailingShort = atr * trailATRMult
strategy.exit("Long Exit", from_entry="Long", stop=longSL, limit=longTP, trail_points=trailingLong, trail_offset=trailingLong)
strategy.exit("Short Exit", from_entry="Short", stop=shortSL, limit=shortTP, trail_points=trailingShort, trail_offset=trailingShort)
// === PLOTS ===
plot(ema, color=color.orange, title="200 EMA")

Overview

A time window can limit entries. Exits use an ATR stop, an ATR multiple take profit, and an ATR trailing stop. Position size defaults to ten percent of equity. It plots the EMA.

Details

Published by

Ahmed-GoCode on GitHub

Code credit

Ahmed - Quant-Edge Indicators, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Oscillators & momentum, Breakout, Sessions & time

Markets

Crypto

Timeframes

M1-M5

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

fair-value-gapfibonaccimarket-structurepine-scriptrsi-strategysmart-money-conceptstechnical-analysistradingviewalgorithmic-tradingcrypto-trading

Settings

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

SettingTypeDefaultVariable
EMA Lengthint200emaLen
MACD Fastint12macdFast
MACD Sólowint26low
MACD Signalint9macdSignal
RSI Lengthint14rsiLen
RSI Overboughtint70rsiOverbought
RSI Oversoldint30rsiOversold
ATR Lengthint14atrLen
ATR Stop Loss Multiplierfloat1.5atrMult
Take Profit Multiplierfloat2.0tpMult
ADX Lengthint14adxLen
ADX Thresholdfloat20adxThresh
Show all 18 settings
SettingTypeDefaultVariable
Trailing Stop ATR Multiplierfloat1.0trailATRMult
Volume Multiplier for Entryfloat1.0volMultiplier
Breakout Lookback Barsint10breakoutLookback
Use Time FilterbooltrueuseTimeFilter
Start Hourint8startHour
End Hourint20endHour
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

106 stars

This strategy enters long positions during a specified trading session when multiple technical indicators align. It executes a buy order when the low drops below the lower Bollinger Band while RSI and ADX exceed configurable threshold values, price closes abov

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of Bollinger Band + RSI + ADX + MACD

ADA4H Optuna Strategy

by skywalker0803r
42 stars

This strategy trades longs and shorts on the price chart. Long entries require a close above the prior Donchian high, a close above a long-term SMA, and RSI above a threshold, with size set as a percentage of equity. Long exits use a stop at the prior Donchian

Strategy v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of ADA4H Optuna Strategy

Morning Scalp

by benso87
24 stars

This strategy tracks an opening session time range to establish directional bias and triggers pullback trades using Stochastic RSI. Once price breaks out of the initial range, it establishes a directional bias and enters when the Stochastic RSI crosses over in

Strategy v5 Sessions & timeBreakout
Updated 4 years ago · MPL-2.0 GitHub repository of Morning Scalp
23 stars

This strategy evaluates breakout and trend opportunities on the price chart using a weighted composite score of volume, trend, and candlestick structure. It tracks volume spikes, fast and slow EMAs, higher-timeframe EMA trend alignment, opening ranges, and ses

Strategy v6 TrendVolume Repaints
Updated 3 weeks ago · Custom licence GitHub repository of TradingAlpha Point-Clip Strategy
16 stars

This strategy trades Donchian channel breakouts on the price chart and exits on a shorter Donchian channel. It sizes each unit from a percentage of equity and an ATR-based initial stop, then adds units as price moves a set ATR distance, up to a maximum unit co

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 16: Anti-Chop Filters

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