Skip to content
← Indicator library
tradingviewdivergenceindicatorpinescript-v6

MacHidden.AlgoNexta

EMA trend direction with MACD-based hidden-divergence pivot markers for TradingView charts.

Published by AlgoNexta. AlgoNexta builds and documents evidence-first trading tools so you can inspect the logic before using it.About AlgoNextaIndicator libraryAlgoNexta Research
Published Oct 12, 2026#hidden-divergence#macd#ema#pivot#overlay#indicator#pinescript-v6#tradingview

Overview

What this indicator does

MacHidden.AlgoNexta is an overlay indicator that uses the relationship between a fast and slow EMA to define the active trend direction, then evaluates price pivots against the MACD line. It plots buy and sell arrows; it does not submit orders, manage a position, or calculate a stop-loss or target.

Type
indicator
Category
divergence
Available in
Pine Script
Source
Open — copy or download

How it works

Read the logic before you use it.

Diagram: When trend direction changes
1

When trend direction changes

The indicator calculates EMA 60 and EMA 240 from `Source` (default `close`). A bullish crossover sets the active direction to 1 and a bearish cross sets it to -1; when no cross has yet been stored, the current EMA ordering supplies the direction. `Show cross labels` is enabled by default, while the EMA lines themselves are hidden unless `Show EMA lines` is enabled.

Diagram: How pivots become buy or sell signals
2

How pivots become buy or sell signals

MACD uses defaults of 12, 26, and 9. A strict bullish condition is a higher pivot low with a lower MACD line value; a strict bearish condition is a lower pivot high with a higher MACD line value. However, `More signals / trend pivots` defaults to true, so its soft tests and the broad `trendPivotBull` or `trendPivotBear` alternatives can also produce a signal after a prior same-side pivot exists.

Diagram: Confirmation timing and visual output
3

Confirmation timing and visual output

With `Pivot left bars` and `Pivot right bars` both set to 1 by default, a pivot is associated with the prior bar but the large arrow is created on the current confirmation bar. A lime ▲ denotes `hiddenBull`; a red ▼ denotes `hiddenBear`. Alerts use these same booleans. ATR(14) only offsets labels above or below the bar; it does not define a stop or target.

Walkthrough

Watch how it reads the chart.

Live market chart

The logic on real candles.

Backtest evidence

What the numbers actually show.

This script's logic could not be confidently reconstructed into an automated reference backtest, so no performance figures are shown rather than estimated ones.

Verify it in TradingView's Strategy Tester (or the equivalent tool for tradingview) before relying on it.

Vision Grade

What was measured, and how confident we are in it.

Vision Grade requires a reference backtest with enough reconstructed entries to measure — not available for this script yet.

Full breakdown

How the script behaves.

About AlgoNexta

Published by AlgoNexta, an evidence-first platform for building, reviewing, and documenting algorithmic trading tools. This page explains the script's actual logic and intended use; it does not promise profitability or replace verification in TradingView.

MacHidden.AlgoNexta is an overlay indicator that uses the relationship between a fast and slow EMA to define the active trend direction, then evaluates price pivots against the MACD line. It plots buy and sell arrows; it does not submit orders, manage a position, or calculate a stop-loss or target.

What it watches

  • Trend state: Fast EMA defaults to 60 and Slow EMA defaults to 240, calculated from Source (default: close). A bullish EMA crossover sets trendDirection to up; a bearish cross sets it to down. Before a crossover is recorded, the script derives direction from which EMA is currently higher.
  • Pivots: Pivot left bars and Pivot right bars both default to 1. A pivot high or low is therefore evaluated with one bar on each side. The pivot is associated with bar_index - pivotRight, while the large signal arrow is drawn on the later confirmation bar.
  • MACD comparison: MACD uses MACD fast 12, MACD slow 26, and MACD signal 9. A strict hidden bearish condition compares a lower price pivot high with a higher MACD value. A strict hidden bullish condition compares a higher price pivot low with a lower MACD value.
  • Default signal expansion: More signals / trend pivots is true by default. With it enabled, the code also accepts softer comparisons and, notably, any later pivot of the relevant type after a prior stored pivot in the active trend. This means default arrows are not limited to strict hidden divergences.
  • Optional EMA-side filter: Require price on EMA side is false by default. If enabled, a sell-side pivot must close below both EMAs and a buy-side pivot must close above both EMAs, measured at the pivot bar.

Reading the chart

  • A large lime ▲ is a bullish signal plotted on the pivot-confirmation bar.
  • A large red ▼ is a bearish signal plotted on the pivot-confirmation bar.
  • When Show pivot dot (where the turn happened) is enabled (default: true), a smaller, faded lime or red ● is back-plotted on the actual pivot bar. It is a reference marker, not the moment the condition became available.
  • Show cross labels is true by default and places a blue Cross label when EMA 60 crosses EMA 240 in either direction. The label itself does not distinguish bullish from bearish direction.
  • Show EMA lines is false by default. If enabled, EMA 60 is red and EMA 240 is blue.
  • Previous signals to show defaults to 20 and limits both arrows and pivot dots. Previous cross labels to show also defaults to 20. Older labels are deleted as new ones are added.

Timing, alerts, and use

The script has no market or timeframe restriction. Its default EMA 60/240 and MACD 12/26/9 settings can be used on any chart, but the chosen timeframe changes the meaning and frequency of pivots. Start by using the chart timeframe you intend to analyse and adjust the EMA, MACD, and pivot inputs only if that changes your intended sensitivity.

Create TradingView alerts from MacIce Buy Hidden and MacIce Sell Hidden. The alert conditions are tied to hiddenBull and hiddenBear, the same booleans that create arrows. The source does not use barstate.isconfirmed; alert behavior on a still-forming realtime bar depends on the alert frequency selected in TradingView. For close-only notification behavior, configure the TradingView alert accordingly.

A no-signal example: during an active uptrend, a pivot low alone does not produce a bullish arrow until there is a previously stored low pivot and the enabled bullish tests pass. If Require price on EMA side is enabled, that pivot's close must additionally be above both EMAs. With More signals / trend pivots disabled, only the strict hidden-divergence comparison can qualify.

Limitations

  • This is an indicator, not a TradingView strategy. It contains no strategy.entry, strategy.exit, orders, position sizing, stop-loss, take-profit, or Strategy Tester results.
  • Pivot recognition is delayed by Pivot right bars; with the default of 1, the visual pivot dot appears one bar back while the arrow is plotted on the later bar. Increasing this input increases confirmation delay.
  • The script uses ATR(14) only to vertically offset labels; ATR is not a risk-control calculation.
  • With More signals / trend pivots enabled by default, many trend-aligned pivots can qualify even without a strict hidden-divergence relationship. Disable it to restrict the logic to strict comparisons.
  • Reset pivot memory on each cross defaults to false. When left off, pivot memory can persist across EMA trend changes, although the signal still requires the current trendDirection and a pivot after the current recorded trend-start bar.
  • No higher-timeframe data, volume filter, support/resistance logic, or trade exit/invalidation logic is implemented.

Source

Full source code, in every platform.

machidden-algonexta-2.pine · 190 lines · 8.2 KB

Not yet verified on the native platform — test it before relying on it.

The original uploaded source.

Download .pine
// ============================================================================
// © algonexta
// This script is for education and research; it does not guarantee results.
// Verify this source in TradingView before use.
// ============================================================================

//@version=6
indicator("MacIce Hidden EMA Indicator", "MacIce", overlay = true, max_labels_count = 500)

// MacIce for TradingView
// 1) EMA60 / EMA240 cross sets the active direction.
// 2) In downturn, every confirmed hidden bearish divergence gets a sell arrow.
// 3) In upturn, every confirmed hidden bullish divergence gets a buy arrow.
// 4) Indicator only. No strategy orders, no trading functions.
//
// Signal timing: a pivot is only known after `pivotRight` more bars have closed.
// The big arrow is drawn on the confirmation bar, which is the bar where the
// alert fires, so the chart history matches what a live user would have seen.
// A small dot marks the pivot bar itself, so the turning point stays visible.

string GROUP_EMA = "EMA Cross"
string GROUP_HIDDEN = "Hidden Divergence"
string GROUP_DISPLAY = "Display"

float source = input.source(close, "Source", group = GROUP_EMA)
int fastEmaPeriod = input.int(60, "Fast EMA", minval = 2, group = GROUP_EMA)
int slowEmaPeriod = input.int(240, "Slow EMA", minval = 5, group = GROUP_EMA)
bool requireEmaSide = input.bool(false, "Require price on EMA side", group = GROUP_EMA)

int pivotLeft = input.int(1, "Pivot left bars", minval = 1, group = GROUP_HIDDEN)
int pivotRight = input.int(1, "Pivot right bars", minval = 1, group = GROUP_HIDDEN)
int macdFast = input.int(12, "MACD fast", minval = 1, group = GROUP_HIDDEN)
int macdSlow = input.int(26, "MACD slow", minval = 2, group = GROUP_HIDDEN)
int macdSignal = input.int(9, "MACD signal", minval = 1, group = GROUP_HIDDEN)
bool resetPivotsOnCross = input.bool(false, "Reset pivot memory on each cross", group = GROUP_HIDDEN)
bool moreSignals = input.bool(true, "More signals / trend pivots", group = GROUP_HIDDEN)

bool showEmaLines = input.bool(false, "Show EMA lines", group = GROUP_DISPLAY)
bool showCrossLabels = input.bool(true, "Show cross labels", group = GROUP_DISPLAY)
bool showPivotMarkers = input.bool(true, "Show pivot dot (where the turn happened)", group = GROUP_DISPLAY)
int signalsToKeep = input.int(20, "Previous signals to show", minval = 20, maxval = 90, group = GROUP_DISPLAY)
int crossLabelsToKeep = input.int(20, "Previous cross labels to show", minval = 1, maxval = 90, group = GROUP_DISPLAY)

float emaFast = ta.ema(source, fastEmaPeriod)
float emaSlow = ta.ema(source, slowEmaPeriod)
float atrValue = ta.atr(14)
bool bullCross = ta.crossover(emaFast, emaSlow)
bool bearCross = ta.crossunder(emaFast, emaSlow)

var int trendDirection = 0
var int trendStartBar = na

if bullCross
    trendDirection := 1
    trendStartBar := bar_index
else if bearCross
    trendDirection := -1
    trendStartBar := bar_index

if trendDirection == 0
    trendDirection := emaFast > emaSlow ? 1 : emaFast < emaSlow ? -1 : 0

[macdLine, signalLine, histLine] = ta.macd(source, macdFast, macdSlow, macdSignal)

float pivotHigh = ta.pivothigh(high, pivotLeft, pivotRight)
float pivotLow = ta.pivotlow(low, pivotLeft, pivotRight)
bool hasPivotHigh = not na(pivotHigh)
bool hasPivotLow = not na(pivotLow)
int pivotBar = bar_index - pivotRight

var float previousHighPrice = na
var float previousHighMacd = na
var int previousHighBar = na
var float previousLowPrice = na
var float previousLowMacd = na
var int previousLowBar = na

if resetPivotsOnCross and (bullCross or bearCross)
    previousHighPrice := na
    previousHighMacd := na
    previousHighBar := na
    previousLowPrice := na
    previousLowMacd := na
    previousLowBar := na

bool pivotAfterTrendStart = na(trendStartBar) ? true : pivotBar > trendStartBar
bool sellEmaOk = not requireEmaSide or (close[pivotRight] < emaFast[pivotRight] and close[pivotRight] < emaSlow[pivotRight])
bool buyEmaOk = not requireEmaSide or (close[pivotRight] > emaFast[pivotRight] and close[pivotRight] > emaSlow[pivotRight])

bool hiddenBear = false
bool hiddenBull = false

if hasPivotHigh
    float highMacd = macdLine[pivotRight]
    bool strictBear = not na(previousHighPrice) and pivotHigh < previousHighPrice and highMacd > previousHighMacd
    bool softBear = moreSignals and not na(previousHighPrice) and (pivotHigh < previousHighPrice or highMacd > previousHighMacd) and histLine[pivotRight] <= histLine[pivotRight + 1]
    bool trendPivotBear = moreSignals and not na(previousHighPrice)
    hiddenBear := trendDirection == -1 and pivotAfterTrendStart and sellEmaOk and (strictBear or softBear or trendPivotBear)
    previousHighPrice := pivotHigh
    previousHighMacd := highMacd
    previousHighBar := pivotBar

if hasPivotLow
    float lowMacd = macdLine[pivotRight]
    bool strictBull = not na(previousLowPrice) and pivotLow > previousLowPrice and lowMacd < previousLowMacd
    bool softBull = moreSignals and not na(previousLowPrice) and (pivotLow > previousLowPrice or lowMacd < previousLowMacd) and histLine[pivotRight] >= histLine[pivotRight + 1]
    bool trendPivotBull = moreSignals and not na(previousLowPrice)
    hiddenBull := trendDirection == 1 and pivotAfterTrendStart and buyEmaOk and (strictBull or softBull or trendPivotBull)
    previousLowPrice := pivotLow
    previousLowMacd := lowMacd
    previousLowBar := pivotBar

plot(showEmaLines ? emaFast : na, "EMA 60", color = color.red, linewidth = 2)
plot(showEmaLines ? emaSlow : na, "EMA 240", color = color.blue, linewidth = 2)

var label[] signalLabels = array.new_label()
var label[] pivotLabels = array.new_label()
var label[] crossLabels = array.new_label()

// Big arrow on the confirmation bar (the current bar), where the alert fires.
addSignalLabel(bool isBuy) =>
    float arrowPrice = isBuy ? low - atrValue * 0.25 : high + atrValue * 0.25
    label arrowLabel = label.new(
         bar_index,
         arrowPrice,
         isBuy ? "▲" : "▼",
         xloc = xloc.bar_index,
         yloc = yloc.price,
         style = label.style_none,
         color = color.new(color.white, 100),
         textcolor = isBuy ? color.lime : color.red,
         size = size.huge,
         tooltip = "Signal confirmed here (" + str.tostring(pivotRight) + " bar(s) after the pivot)")
    array.push(signalLabels, arrowLabel)
    while array.size(signalLabels) > signalsToKeep
        label.delete(array.shift(signalLabels))

// Small dot on the pivot bar itself, so the turning point stays visible.
addPivotMarker(bool isBuy) =>
    float dotPrice = isBuy ? low[pivotRight] - atrValue[pivotRight] * 0.25 : high[pivotRight] + atrValue[pivotRight] * 0.25
    label dotLabel = label.new(
         pivotBar,
         dotPrice,
         "●",
         xloc = xloc.bar_index,
         yloc = yloc.price,
         style = label.style_none,
         color = color.new(color.white, 100),
         textcolor = isBuy ? color.new(color.lime, 35) : color.new(color.red, 35),
         size = size.tiny,
         tooltip = "Pivot bar (known only " + str.tostring(pivotRight) + " bar(s) later)")
    array.push(pivotLabels, dotLabel)
    while array.size(pivotLabels) > signalsToKeep
        label.delete(array.shift(pivotLabels))

if hiddenBear
    addSignalLabel(false)
    if showPivotMarkers
        addPivotMarker(false)

if hiddenBull
    addSignalLabel(true)
    if showPivotMarkers
        addPivotMarker(true)

addCrossLabel(bool isBullCross) =>
    float crossPrice = (emaFast + emaSlow) * 0.5
    float labelPrice = isBullCross ? crossPrice - atrValue * 0.35 : crossPrice + atrValue * 0.35
    label crossLabel = label.new(
         bar_index,
         labelPrice,
         "Cross",
         xloc = xloc.bar_index,
         yloc = yloc.price,
         style = label.style_none,
         color = color.new(color.blue, 100),
         textcolor = color.rgb(41, 98, 255),
         size = size.normal)
    array.push(crossLabels, crossLabel)
    while array.size(crossLabels) > crossLabelsToKeep
        label.delete(array.shift(crossLabels))

if showCrossLabels and bullCross
    addCrossLabel(true)

if showCrossLabels and bearCross
    addCrossLabel(false)

alertcondition(hiddenBear, "MacIce Sell Hidden", "MacIce sell hidden divergence on {{ticker}} {{interval}}")
alertcondition(hiddenBull, "MacIce Buy Hidden", "MacIce buy hidden divergence on {{ticker}} {{interval}}")

FAQ

Common questions.

What does MacHidden.AlgoNexta detect?▾

It sets trend direction from the EMA 60 and EMA 240 relationship, then evaluates price pivot highs/lows against MACD 12/26/9 values. It plots bullish or bearish arrows when its enabled pivot conditions qualify in that trend direction.

Are the arrows strict hidden-divergence signals only?▾

Not with the default settings. `More signals / trend pivots` is true by default, and its additional conditions can allow trend-aligned pivots beyond the strict price/MACD hidden-divergence comparison.

Does the indicator repaint or signal after the pivot?▾

Pivot-based conditions require `Pivot right bars` of confirmation, which defaults to 1, so the pivot marker is shown back on the pivot bar while the large arrow is drawn later on the confirmation bar. The source has no `barstate.isconfirmed` gate, so realtime alert behavior also depends on the TradingView alert frequency you choose.

Does this script place trades or include stop-loss and take-profit levels?▾

No. It is an indicator with plotted labels and alert conditions only; it does not call TradingView strategy order functions and does not implement trade exits, stops, or targets.

Which timeframes and markets can I use?▾

The code does not restrict symbols or timeframes. The default EMA 60/240, MACD 12/26/9, and 1-bar pivots will behave differently as chart resolution changes, so evaluate settings on the specific market and timeframe you plan to analyse.

Is this financial advice or proof of live performance?▾

No. This indicator is not financial advice, and it contains no built-in performance test. TradingView Strategy Tester, where an independently defined strategy is applicable, plus paper and live execution records are the sources of truth for results.

Want a version tuned to your market?

Describe the change in plain English and AlgoNexta rebuilds it as a fresh Pine v6 script — with its own explanation, evidence, and walkthrough.

Build your own version

Educational content only — not financial advice. TradingView is the source of truth for live data, compilation, and Strategy Tester results.

We use cookies to understand how the site is used and improve it. We only load analytics after you accept. Privacy Policy