NEWCard payments are live · from $18/month, USDT also acceptedSee plans
COINPRED / STRATEGY LIBRARY

BTC Price Z-Trend: Enter When the Z-Score Crosses a Volatility Threshold

An open-source (MPL 2.0) trend strategy from PresentTrading. The Z-score is price minus a 100-period EMA, divided by a 100-period standard deviation. The default long is a cross above +1; the default short is a cross below −1. The publication text mentions mean reversion, but the source follows the threshold break. The author chart is Bitfinex BTCUSD, 6-hour. No invented backtest figures.

Illustrated guidesPine Script®Included with monthly & annual plans
← All strategies
PresentTrading · 1.0 · 2026-11-21 · Trend following
BTC Price Z-Trend: Enter When the Z-Score Crosses a Volatility Threshold

The idea

This open-source script from PresentTrading turns the distance between price and a moving average into a standardized Z-score, then trades crosses of a set threshold. The math is short: subtract an EMA from price, and divide by the standard deviation over the same lookback. The script is drawn in a separate pane (overlay=false); on the main chart it can only tint the candles, and that tint can be switched off.

One mismatch with the publication page should be stated up front. The write-up talks about price often returning to its mean, which sounds like mean reversion. In the source, a long is opened when the Z-score crosses above the positive threshold, and a short when it crosses below the negative threshold — after price has already stretched, the trade goes with that stretch. The rules below follow the source, not that introductory wording.

The chart on the publication page is BITFINEX:BTCUSD on the 6-hour timeframe, so this page is filed under BTC. The script is not hard-coded to one symbol and will load elsewhere, but the walkthrough and the image stay with the author’s chart.

Author chart of the price-based Z-trend strategy on BITFINEX:BTCUSD 6-hour
Author chart: BITFINEX:BTCUSD, 6-hour timeframe, taken from the publication page. The image shows the Z-score pane, threshold lines, and trade marks; it only illustrates appearance and is not a Coinpred backtest.

Indicators

  • The price source defaults to the close and can be changed with the Source input.
  • Z-score: priceZScore = (priceSource − ta.ema(priceSource, priceAverageLength)) / ta.stdev(priceSource, priceDeviationLength). Both lengths default to 100.
  • Threshold defaults to 1. The pane plots +Threshold and −Threshold, plus a dotted zero line.
  • The Z-score plot is colored by zone: green above the upper threshold, red below the lower one, and blue in between.

Entry rules

  • The default side is Both; it can be set to long only or short only.
  • Long: priceZScore crosses above Threshold (default +1), and longs are allowed. The tester name is Long.
  • Short: priceZScore crosses below −Threshold (default −1), and shorts are allowed. The tester name is Short.
  • The tester defaults to 10% of equity, 0.1% commission, slippage 1, 10,000 initial capital, and USD as the currency.

Exits and position sizing

  • A long is closed when the Z-score crosses below −Threshold. A short is closed when it crosses above +Threshold. There is no separate stop or take-profit input.
  • In the default Both mode, a long entry and a short exit are the same event, and so are a short entry and a long exit. A cross above +1 covers a short and opens a long; a cross below −1 covers a long and opens a short. The book stays in the market and flips at the two thresholds.
  • In long-only mode, a cross above +1 enters and a cross below −1 exits, so the strategy can sit flat between those events. Short-only is the mirror of that.
  • Optional bar coloring is on by default. The color branches in the source are loosely written: after the “greater than the threshold” case, the next test is priceZScore < Threshold, which is almost always true, so the later red branch is hard to reach. Do not treat the candle colors as a strict map of all four zones.

Inputs (source defaults)

InputDefaultPurpose
Trading DirectionBothLong, short, or both sides
Standard Deviation Length100Lookback for the standard deviation
Average Length100Lookback for the EMA
Threshold1Z-score multiple used for entries and exits
Bar ColortrueTint price bars from the Z-score
SourceclosePrice series used in the Z-score

Things to know before using it

  • The publication text leans toward mean reversion; the source follows a threshold break in the same direction. Trust the source.
  • Standard deviation sits in the denominator. When realized volatility suddenly contracts, the Z-score can jump and cross the thresholds more often. That is inherent to the formula, not an extra filter.
  • The script lives in a pane. The main chart, by default, only shows candle tint. To see the EMA itself you have to add one, or just read the Z-score in the pane.
  • priceLongCondition and priceExitLongCondition are assigned the same tests as the later long and short conditions; they do not add a second rule set.
  • Coinpred already lists two PresentTrading strategies (liquidity breakout and dual RSI differential). This one is a price Z-score cross, with a different rule set.

Installing it on TradingView

  1. Download the .pine file from Coinpred (active membership required, see below), or check the original page for a newer version.
  2. Open the Pine Editor, create a blank script, paste the full source, and save.
  3. Click Add to chart. To match the author image, start with Bitfinex BTCUSD on the 6-hour timeframe. The script will appear in a separate pane.
  4. Set the direction and threshold first, then review the flip points in the Strategy Tester.
  5. Past tester results do not guarantee future returns.

About backtest figures

Source, license and version

  • Source: https://www.tradingview.com/script/IrnAzTAU-Price-Based-Z-Trend-Strategy-presentTrading/
  • Author: PresentTrading. Source version 1.0 (Pine v5), scriptAccess=open_no_auth.
  • License: Mozilla Public License 2.0. Redistribution must keep the copyright and license notices; modified files must remain under MPL 2.0. Coinpred ships the unmodified full source.
  • Members can download the .pine file on this page to study the rules. Judge the risk yourself, and follow your venue’s rules.

Source, license and version

Mozilla Public License 2.0 (MPL 2.0),© PresentTrading,依据源码头部许可声明。再分发须保留原版权与许可声明;如修改源码文件,修改后的文件仍须按 MPL 2.0 提供。Coinpred 未修改源码。 / Licensed under MPL 2.0 per the source header, © PresentTrading. Redistribution must keep the copyright and license notices; modified files must remain under MPL 2.0. Coinpred ships the unmodified source.

View original source ↗

Check the script license and your TradingView account features. Historical results do not guarantee future performance.