Strategy · Pine Script v6 · On the chart

MTF probe 11 - HTF bracket manual trail

by pineforge-4pass· code credited to PineForge contributors 2026

This Pine Script strategy identifies trend changes by checking for crossovers between fast and slow EMAs on the current timeframe.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code77
Settings8inputs
LicenceApache-2.0
Last update5 days ago23 Oct 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

77 lines of Pine Script v6 from validation/mtf-htf-confluence-manual-trail-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// MTF probe 11 — HTF confluence gate with MANUAL TRAILING stop
//
// Purpose: companion to mtf-probe-10. Keeps the exact same HTF confluence
// gate so any drift between probe 10 and probe 11 isolates the manual
// trailing-stop / per-bar strategy.exit re-issue pattern that VCP uses.
//
// The trailing implementation matches VCP's:
//   * a ``var float`` trail slot is updated each bar to the higher of
//     (close - atr * trailMult) and the previous trail (so it only
//     ratchets up for longs);
//   * ``strategy.exit("LX", "L", stop=trail, limit=tp)`` is called every
//     bar while in position with the freshly-updated trail.
// The engine must recognize that a strategy.exit re-issue with the same
// id+from_entry replaces the previous pending order rather than fanning
// out into multiple sibling exits — and the consumed-partial-id guard
// must NOT spuriously cancel valid full exits when the same id re-issues
// with a different stop.
//
// Trade shape: long-only, pyramiding=1. Same entry signal as probe 10.
// Exit via a static TP and a per-bar manual trail.
//
// TV setup: 15m chart, ETH-USDT-USDT, same window as
// data/ohlcv_ETH-USDT-USDT_15m.csv. Export the trade list to trades.csv
// in this folder.
//@version=6
strategy("MTF probe 11 - HTF bracket manual trail", shorttitle="MTF_p11",
     overlay=true, initial_capital=1000000,
     commission_type=strategy.commission.percent, commission_value=0,
     slippage=0, default_qty_type=strategy.fixed, default_qty_value=1,
     pyramiding=1, process_orders_on_close=false)

// ---- inputs ---------------------------------------------------------
string i_htf         = input.timeframe("60", "Higher Timeframe")
int    i_htf_ema     = input.int(20,         "HTF EMA Length",     minval=2, maxval=200)
int    i_fast_ema    = input.int(9,          "Fast EMA Length",    minval=2, maxval=50)
int    i_slow_ema    = input.int(21,         "Slow EMA Length",    minval=3, maxval=100)
int    i_atr_len     = input.int(14,         "ATR Length",         minval=2, maxval=50)
float  i_stop_mult   = input.float(2.0,      "Initial Stop ATR mult",   minval=0.5, maxval=5.0, step=0.1)
float  i_tp_mult     = input.float(4.0,      "Take-profit ATR mult",    minval=0.5, maxval=10.0, step=0.1)
float  i_trail_mult  = input.float(2.0,      "Manual Trail ATR mult",   minval=0.5, maxval=5.0, step=0.1)

// ---- 15m series -----------------------------------------------------
float emaFast = ta.ema(close, i_fast_ema)
float emaSlow = ta.ema(close, i_slow_ema)
float atrVal  = ta.atr(i_atr_len)

// ---- HTF confluence (identical to probe 10) ------------------------
float _htfEmaSeries = ta.ema(close, i_htf_ema)
float htfClose = request.security(syminfo.tickerid, i_htf,
     close, barmerge.gaps_off, barmerge.lookahead_off)
float htfEma   = request.security(syminfo.tickerid, i_htf,
     _htfEmaSeries, barmerge.gaps_off, barmerge.lookahead_off)
bool  htfBull  = not na(htfClose) and not na(htfEma) and htfClose > htfEma

// ---- entry + per-bar manual trailing ------------------------------
bool longSig = ta.crossover(emaFast, emaSlow) and htfBull

var float entryTP   = na
var float trailStop = na

if longSig and strategy.position_size == 0 and not na(atrVal)
    entryTP   := close + atrVal * i_tp_mult
    trailStop := close - atrVal * i_stop_mult
    strategy.entry("L", strategy.long, qty=1, comment="entry long")

// Manual trailing — ratchet trailStop higher each bar and re-issue
// the strategy.exit so the engine pending-order replaces in place.
if strategy.position_size > 0 and not na(atrVal)
    float candidate = close - atrVal * i_trail_mult
    if not na(trailStop) and candidate > trailStop
        trailStop := candidate
    strategy.exit("LX", "L", stop=trailStop, limit=entryTP,
         comment="manual trail")

Overview

MTF probe 11 - HTF bracket manual trail confirms the trend with a higher timeframe EMA confluence gate set to 60 minutes. The strategy draws its signals directly on the price chart. Entry occurs on bullish crossovers when the higher timeframe is also bullish. Once in position, it sets a take-profit level using ATR multiplied by 4.0 and a manual trailing stop using ATR multiplied by 2.0. The trailing stop is updated every bar to ratchet upwards for long positions. Inputs control all EMA lengths, ATR period, and the stop, take-profit, and trail multipliers.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands

Markets

Crypto

Timeframes

M15-H1

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

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
Higher Timeframetimeframe60i_htf
HTF EMA Lengthint20i_htf_ema
Fast EMA Lengthint9i_fast_ema
Slow EMA Lengthint21i_slow_ema
ATR Lengthint14i_atr_len
Initial Stop ATR multfloat2.0i_stop_mult
Take-profit ATR multfloat4.0i_tp_mult
Manual Trail ATR multfloat2.0i_trail_mult
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 mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

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
104 stars

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of Chandelier Exit & ZLSMA Strategy

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