Strategy · Pine Script v5 · On the chart

MicroQuant Trend Strat

by g-moe· code credited to goodgains

MicroQuant Trend Strat is a trend-following strategy overlaid on the price chart that utilizes a modified Supertrend calculation built with EMA bands and Average True Range volatility bounds.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code89
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

89 lines of Pine Script v5 from Tradingview/microquant-trend-strat.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

microquant-trend-strat.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
strategy("MicroQuant Trend Strat", overlay = true, max_labels_count = 500)

// @keywords: custom-supertrend-strategy, ema-atr-bands, long-short-entries, take-profit-stop-loss, position-exit-levels, trend-flip-signals, stepline-trend-plot, atr-factor-settings, entry-fill-zones, strategy-backtest, dual-direction-trend, band-trailing-stop, microquant-algorithm, price-source-input, trend-direction-plot, exit-on-flip, fixed-tp-sl-points, position-average-line, green-red-trend-lines, strategy-entry-exit


price = input.source(close, title = 'Price')
length = input.int(21, title = 'Length')
atrPeriod = input.int(21, "ATR Length")
factor = input.float(4.0, "Factor", step = 0.1)


// strategy settings
use_tp = input.bool(true, title = 'TP', group = 'Trade Settings', inline = 'tp')
tp_amount = input.float(20.00, title = '', group = 'Trade Settings', inline = 'tp')

use_sl = input.bool(true, title = 'SL', group = 'Trade Settings', inline = 'sl')
sl_amount = input.float(10.00, title = '', group = 'Trade Settings', inline = 'sl')


// The same on Pine Script™
pine_supertrend() =>
    atr = ta.sma(ta.tr, atrPeriod)
    lowerBand = ta.highest(ta.ema(high, length), length) - atr * factor
    upperBand = ta.lowest(ta.ema(low, length), length) + atr * factor
    prevLowerBand = nz(lowerBand[1])
    prevUpperBand = nz(upperBand[1])

    lowerBand := lowerBand > prevLowerBand or price[1] < prevLowerBand ? lowerBand : prevLowerBand
    upperBand := upperBand < prevUpperBand or price[1] > prevUpperBand ? upperBand : prevUpperBand
    int direction = na
    float superTrend = na
    prevSuperTrend = superTrend[1]
    if na(atr[1])
        direction := 1
    else if prevSuperTrend == prevUpperBand
        direction := price > upperBand ? -1 : 1
    else
        direction := price < lowerBand ? 1 : -1
    superTrend := direction == -1 ? lowerBand : upperBand
    [superTrend, direction]

[pineSupertrend, pineDirection] = pine_supertrend()
plot(pineDirection < 0 ? pineSupertrend : na, "Up direction", color = color.green, style=plot.style_steplinebr)
plot(pineDirection > 0 ? pineSupertrend : na, "Down direction", color = color.red, style=plot.style_steplinebr)


var bool tradersPostBuy = na
var bool tradersPostSell = na
tradersPostBuy := pineDirection < 0 and pineDirection[1] >= 0
tradersPostSell := pineDirection > 0 and pineDirection[1] <= 0


// entry signals
if tradersPostBuy
    strategy.entry("LE", strategy.long)
if tradersPostSell
    strategy.entry("SS_E", strategy.short)



// position management
var float tp_lvl = 0.00
var float sl_lvl = 0.00

tp_lvl := strategy.position_size > 0 ? strategy.position_avg_price + tp_amount
 : strategy.position_size < 0 ? strategy.position_avg_price - tp_amount
 : na

sl_lvl := strategy.position_size > 0 ? strategy.position_avg_price - sl_amount
 : strategy.position_size < 0 ? strategy.position_avg_price + sl_amount
 : na

if strategy.position_size > 0
    strategy.exit('LX', from_entry = 'LE', limit = tp_lvl, stop = sl_lvl, comment_profit = 'L_TP', comment_loss = 'L_SL')
if strategy.position_size < 0
    strategy.exit('SS_X', from_entry = 'SS_E', limit = tp_lvl, stop = sl_lvl, comment_profit = 'SS_TP', comment_loss = 'SS_SL')
    

p_entry = plot(strategy.position_avg_price, title = 'Entry', color = color.blue, style = plot.style_circles)
p_tp = plot(tp_lvl, title = 'TP', color = color.green, style = plot.style_circles)
p_sl = plot(sl_lvl, title = 'SL', color = color.red, style = plot.style_circles)

fill(p_entry, p_tp, color = color.new(color.green,90))
fill(p_entry, p_sl, color = color.new(color.red,90))

Overview

MicroQuant Trend Strat opens long positions when the trend direction turns bullish and short positions when it turns bearish. Position management relies on customizable fixed-point take profit and stop loss exit targets measured from the execution average price. Parameters let users fine-tune the EMA smoothing length, ATR calculation period, multiplier factor, and risk target distances.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

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.

Settings

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

SettingTypeDefaultVariable
Pricesourcecloseprice
Lengthint21length
ATR Lengthint21atrPeriod
Factorfloat4.0factor
TPbooltrueuse_tp
tp_amountfloat20.00tp_amount
SLbooltrueuse_sl
sl_amountfloat10.00sl_amount
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 7 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
220 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 Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers