Skip to content
← Indicator library
tradingviewrisk-managementindicatorpinescript-v6

EmaMacdIce Risk Manager

EMA-trend-filtered MACD cross signals with ATR-based stop, 1R–3R levels, and a chart-side position-size estimate.

Vision Grade

36.7

E · LOW confidence · E2

Published by AlgoNexa. AlgoNexa builds and documents evidence-first trading tools so you can inspect the logic before using it.About AlgoNexaIndicator library
Published Aug 22, 2026#ema#macd#atr#risk-management#position-sizing#indicator#tradingview#pinescript-v6

How it works

Read the logic before you use it.

1

When it signals

The default mode accepts a long when the 60-period EMA is above the 240-period EMA and MACD crosses above its signal line. A short requires the inverse conditions; the "Exact cTrader" mode additionally applies the MACD zero-line filter.

2

How levels are drawn

At the accepted signal bar's close, the script sets a stop one ATR-based risk distance away and plots targets at 1R, 2R, and 3R. The active lines extend rightward by the selected "Level Projection Bars" value.

3

How risk is framed

Suggested units equal account risk cash divided by stop distance and "Value of 1.0 Price Move per Unit." The setup status changes when the stop, TP3, or an accepted opposite signal closes the active setup.

Walkthrough

Watch how it reads the chart.

Live market chart

The logic on real candles.

Backtest evidence

What the numbers actually show.

E0 · Reconstructed reference

algonexta-reference · Yahoo Finance · EURUSD · 1h

Net profit

0.0143

Max drawdown

0.0120

Trades

72

Symbol · TF

EURUSD · 1h

Equity curve

Reference trades (144)
TimeSidePrice
Jun 26, 06:00 AMlong1.13792
Jun 26, 05:00 PMexit1.13895
Jun 26, 05:00 PMshort1.13895
Jun 29, 06:00 AMexit1.14051
Jun 29, 06:00 AMlong1.14181
Jun 29, 08:00 AMexit1.14011
Jun 30, 12:00 AMshort1.14194
Jun 30, 02:00 PMexit1.14364
Jun 30, 02:00 PMlong1.14364
Jun 30, 04:00 PMexit1.14157
Jul 1, 01:00 AMshort1.14077
Jul 2, 01:00 AMexit1.13843
Jul 2, 01:00 AMlong1.13843
Jul 2, 12:00 PMexit1.14709
Jul 2, 10:00 PMshort1.14312
Jul 3, 04:00 AMexit1.14458
Jul 3, 05:00 AMlong1.14508
Jul 3, 09:00 AMexit1.14443
Jul 3, 09:00 AMshort1.14443
Jul 3, 11:00 AMexit1.14589
Jul 6, 04:00 PMlong1.14338
Jul 7, 05:00 AMexit1.14351
Jul 7, 05:00 AMshort1.14351
Jul 8, 05:00 AMexit1.14233
Jul 8, 05:00 AMlong1.14233
Jul 8, 09:00 AMexit1.14072
Jul 8, 11:00 AMshort1.13999
Jul 8, 04:00 PMexit1.14168
Jul 8, 04:00 PMlong1.14168
Jul 9, 12:00 PMexit1.14273
Jul 9, 12:00 PMshort1.14273
Jul 9, 01:00 PMexit1.14416
Jul 9, 01:00 PMlong1.14416
Jul 9, 07:00 PMexit1.14312
Jul 9, 07:00 PMshort1.14312
Jul 10, 12:00 AMexit1.14429
Jul 10, 01:00 AMlong1.14521
Jul 10, 07:00 AMexit1.14403
Jul 10, 07:00 AMshort1.14403
Jul 13, 01:00 AMexit1.13963
Jul 13, 07:00 AMlong1.14273
Jul 13, 02:00 PMexit1.14082
Jul 13, 03:00 PMshort1.14064
Jul 14, 03:00 AMexit1.13973
Jul 14, 03:00 AMlong1.13973
Jul 14, 11:00 PMexit1.14273
Jul 14, 11:00 PMshort1.14273
Jul 15, 12:00 AMexit1.14377
Jul 15, 12:00 AMlong1.14377
Jul 15, 07:00 AMexit1.14236
Jul 15, 07:00 AMshort1.14260
Jul 15, 02:00 PMexit1.14416
Jul 15, 04:00 PMlong1.14456
Jul 16, 04:00 AMexit1.14692
Jul 16, 04:00 AMshort1.14692
Jul 17, 03:00 AMexit1.14404
Jul 17, 03:00 PMlong1.14430
Jul 19, 11:00 PMexit1.14308
Jul 20, 10:00 AMshort1.14351
Jul 21, 01:00 AMexit1.14181
Jul 21, 01:00 AMlong1.14181
Jul 21, 02:00 PMexit1.14065
Jul 21, 02:00 PMshort1.14090
Jul 22, 02:00 AMexit1.14090
Jul 22, 02:00 AMlong1.14090
Jul 23, 04:00 AMexit1.14374
Jul 23, 09:00 AMshort1.14155
Jul 23, 09:00 PMexit1.13767
Jul 24, 12:00 AMlong1.13869
Jul 24, 12:00 PMexit1.13732
Jul 24, 06:00 PMshort1.13727
Jul 26, 11:00 PMexit1.13866
Jul 26, 11:00 PMlong1.13986
Jul 27, 11:00 AMexit1.13895
Jul 27, 11:00 AMshort1.13895
Jul 28, 03:00 AMexit1.13779
Jul 28, 03:00 AMlong1.13779
Jul 28, 05:00 AMexit1.13668
Jul 28, 05:00 AMshort1.13701
Jul 28, 08:00 AMexit1.13753
Jul 28, 08:00 AMlong1.13753
Jul 28, 09:00 AMexit1.13624
Jul 29, 10:00 AMshort1.13882
Jul 29, 05:00 PMexit1.14024
Jul 29, 06:00 PMlong1.14534
Jul 30, 06:00 AMexit1.14508
Jul 30, 06:00 AMshort1.14508
Jul 30, 09:00 AMexit1.14702
Jul 30, 11:00 AMlong1.14784
Jul 30, 10:00 PMexit1.15326
Jul 30, 11:00 PMshort1.15260
Jul 31, 06:00 PMexit1.15340
Jul 31, 06:00 PMlong1.15340
Aug 3, 06:00 AMexit1.15300
Aug 3, 06:00 AMshort1.15300
Aug 4, 07:00 AMexit1.15141
Aug 4, 07:00 AMlong1.15141
Aug 5, 06:00 AMexit1.15475
Aug 5, 10:00 PMshort1.15580
Aug 5, 11:00 PMexit1.15607
Aug 5, 11:00 PMlong1.15607
Aug 6, 03:00 AMexit1.15513
Aug 7, 04:00 AMlong1.15274
Aug 7, 12:00 PMexit1.15779
Aug 10, 02:00 AMshort1.15553
Aug 10, 07:00 AMexit1.15650
Aug 11, 12:00 PMlong1.15460
Aug 12, 03:00 AMexit1.15394
Aug 12, 03:00 AMshort1.15380
Aug 12, 09:00 AMexit1.15460
Aug 12, 11:00 AMlong1.15473
Aug 12, 04:00 PMexit1.15311
Aug 12, 04:00 PMshort1.15314
Aug 13, 08:00 AMexit1.15274
Aug 13, 08:00 AMlong1.15274
Aug 13, 07:00 PMexit1.15314
Aug 13, 07:00 PMshort1.15314
Aug 13, 11:00 PMexit1.15367
Aug 13, 11:00 PMlong1.15367
Aug 14, 11:00 AMexit1.15685
Aug 14, 08:00 PMshort1.15727
Aug 17, 12:00 AMexit1.15827
Aug 17, 12:00 AMlong1.15835
Aug 17, 11:00 AMexit1.15955
Aug 17, 11:00 AMshort1.15955
Aug 18, 02:00 PMexit1.15848
Aug 18, 02:00 PMlong1.15848
Aug 18, 07:00 PMexit1.15781
Aug 18, 07:00 PMshort1.15781
Aug 19, 02:00 AMexit1.15881
Aug 19, 02:00 AMlong1.15861
Aug 19, 12:00 PMexit1.16376
Aug 20, 02:00 AMshort1.16781
Aug 20, 07:00 AMexit1.16930
Aug 20, 09:00 AMlong1.17110
Aug 20, 10:00 AMexit1.17000
Aug 20, 10:00 AMshort1.17000
Aug 21, 05:00 AMexit1.17014
Aug 21, 05:00 AMlong1.17014
Aug 21, 07:00 AMexit1.16945
Aug 21, 07:00 AMshort1.16945
Aug 21, 08:00 AMexit1.17089
Aug 21, 12:00 PMshort1.16945
Aug 21, 09:00 PMexit1.16781

Executed from the versioned AlgoNexta IR on the same OHLC dataset used by the chart.

This is an independent reference backtest; TradingView Strategy Tester remains the official comparison.

This is an AI-reconstructed approximation of the script’s logic, not an execution of the exact source — verify the real script in TradingView Strategy Tester.

Vision Grade

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

E2 · LOW confidence

VG-Signal — the measured component of Vision Grade. See the methodology for the Evidence Tier and Confidence axes it is always shown beside.

36.7

/ 100

Predictive power

22

Trading performance

17.1

Robustness

40

Risk

100

Signal-Based Performance

Signals

72

Win rate

43.1%

Profit factor

0.69

Max drawdown

0.0165

Robustness — chronological out-of-sample split

In-sample IC

Out-of-sample IC

OOS retention

OOS_SAMPLE_TOO_SMALL

ic here is a pooled event-conditional Spearman rank correlation (signal_strength vs forward return), not a cross-sectional factor IC — see methodology.

Vision Grade measures the strength of statistical and trading-quality evidence. It does not predict future returns.

A high Information Coefficient does not guarantee profitability.

Trading Performance here is Signal-Based Performance, not an execution backtest against the original source.

Historical results do not guarantee future performance.

Only 72 valid signals (config minimum is 100) — results below are directional, not reliable.

Horizon 10: 1 signals dropped (not enough forward OHLC bars).

Horizon 20: 3 signals dropped (not enough forward OHLC bars).

Horizon 50: 6 signals dropped (not enough forward OHLC bars).

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.

What it does

EmaMacdIce Risk Manager is an overlay indicator that combines an EMA trend filter with MACD signal-line crosses, then draws a risk framework for each accepted signal. It calculates an ATR-based stop-loss distance, three reward levels at 1R, 2R, and 3R, and an estimated position size based on the account and instrument-value inputs.

It is an indicator, not a TradingView strategy: it draws signals and reference levels but does not send orders or use strategy.entry() / strategy.exit().

What it watches

With the default Signal mode of EMA trend MACD crosses:

  • A buy signal requires the Short EMA to be above the Long EMA and the MACD line to cross above its signal line.
  • A sell signal requires the Short EMA to be below the Long EMA and the MACD line to cross below its signal line.
  • Default signal settings are Short EMA = 60, Long EMA = 240, MACD Fast = 12, MACD Slow = 26, and MACD Signal = 9.

The alternative Signal mode, Exact cTrader, adds a MACD zero-line filter:

  • Buys require a bullish EMA trend, a bullish MACD cross, and the MACD line below zero.
  • Sells require a bearish EMA trend, a bearish MACD cross, and the MACD line above zero.

Signals alternate by direction. After an accepted BUY, another BUY is ignored until an accepted SELL occurs, and vice versa.

How risk levels are calculated

On an accepted signal, the indicator uses the close of that signal bar as the reference entry price. The stop distance is:

ATR Period × SL ATR Multiplier

Defaults are ATR Period = 14 and SL ATR Multiplier = 1.5. For a long setup, the stop is below entry and the targets are above it; for a short setup, the placement is reversed.

  • SL is 1R from entry.
  • TP1 is 1R from entry.
  • TP2 is 2R from entry.
  • TP3 is 3R from entry.

The displayed size estimate uses Account Balance = 10000, Account Risk % = 1.0, and Value of 1.0 Price Move per Unit = 1.0 by default. Set the point-value input to the actual cash P/L produced by a one-unit position moving by 1.0 in price for your broker and market; the script cannot verify contract specifications for you.

Reading the chart

  • A teal/green upward triangle below a bar marks an accepted buy signal; a red downward triangle above a bar marks an accepted sell signal.
  • The fast EMA is colored with the current EMA trend: buy color when the short EMA is above the long EMA, sell color otherwise. The slow EMA is silver.
  • Show EMAs and Shade EMA Trend control the moving-average plots and the translucent fill between them.
  • The active setup shows a white entry line, red stop line, and three green target lines. Red shading marks the entry-to-stop risk area; green shading marks the entry-to-TP3 reward area.
  • The signal label shows BUY or SELL, the selected account risk percentage, and the calculated size estimate.
  • TP1 and TP2 lines become solid when reached. A setup closes when SL or TP3 is reached, or when an accepted opposite-direction signal reverses it. The status label then shows SL HIT, TP3 HIT, or REVERSED.
  • Show Level Prices adds or removes prices from the entry, stop, and TP3 labels. Level Projection Bars controls how far active levels extend, with a default of 35 bars.
  • Historical Setups controls the number of previous setup drawings retained, with a default of 50.

Markets and timeframes

The code does not restrict symbols or chart intervals. Because its stop and target distances are ATR-based and the size calculation depends on Value of 1.0 Price Move per Unit, it can be configured for different instruments, but that point-value input must match the instrument you trade. Test the EMA, MACD, and ATR settings on the specific market and timeframe you use.

Limitations

  • The indicator evaluates signals on the live bar, so a MACD cross can appear or disappear before that bar closes. For more stable interpretation, assess signals after bar close and configure alerts accordingly.
  • It assumes the entry occurs at the signal bar's close and does not evaluate stop or target hits on that same bar.
  • If a later bar touches both a stop and a target, the script checks the stop first. It cannot determine the true intrabar sequence from OHLC data alone.
  • The plotted SL/TP levels are visual calculations, not broker orders, trailing stops, partial exits, or guaranteed fills.
  • The indicator does not account for spread, slippage, commissions, liquidity, session rules, or broker-specific lot constraints.
  • It does not identify market structure, support/resistance, divergence, or discretionary trade context beyond its EMA and MACD conditions.

Source

pinescript-v6 · full source

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

//@version=6
indicator("EmaMacdIce Risk Manager", "EmaMacdIce RM", overlay = true, max_labels_count = 500, max_lines_count = 500)

// Signals
string GROUP_SIGNAL = "Signal Inputs"
float source = input.source(close, "Source", group = GROUP_SIGNAL)
int shortEmaPeriod = input.int(60, "Short EMA", minval = 1, group = GROUP_SIGNAL)
int longEmaPeriod = input.int(240, "Long EMA", minval = 1, group = GROUP_SIGNAL)
int macdFastPeriod = input.int(12, "MACD Fast", minval = 1, group = GROUP_SIGNAL)
int macdSlowPeriod = input.int(26, "MACD Slow", minval = 1, group = GROUP_SIGNAL)
int macdSignalPeriod = input.int(9, "MACD Signal", minval = 1, group = GROUP_SIGNAL)
string signalMode = input.string("EMA trend MACD crosses", "Signal mode", options = ["Exact cTrader", "EMA trend MACD crosses"], group = GROUP_SIGNAL)

// Risk management
string GROUP_RISK = "Risk Management"
int atrPeriod = input.int(14, "ATR Period", minval = 1, group = GROUP_RISK)
float atrMultiplier = input.float(1.5, "SL ATR Multiplier", minval = 0.1, step = 0.1, group = GROUP_RISK)
float riskPercent = input.float(1.0, "Account Risk %", minval = 0.1, maxval = 100, step = 0.1, group = GROUP_RISK)
float accountBalance = input.float(10000.0, "Account Balance", minval = 0.0, step = 100.0, group = GROUP_RISK)
float unitPointValue = input.float(1.0, "Value of 1.0 Price Move per Unit", minval = 0.000001, step = 0.01, group = GROUP_RISK, tooltip = "Set this to the cash P/L of one trading unit when price moves by 1.0. For XAUUSD, one ounce is commonly 1; verify with your broker.")
int projectionBars = input.int(35, "Level Projection Bars", minval = 5, maxval = 500, group = GROUP_RISK)
int historicalSetups = input.int(50, "Historical Setups", minval = 1, maxval = 80, group = GROUP_RISK, tooltip = "Number of previous signal risk boxes to keep on the chart.")

// Appearance
string GROUP_DISPLAY = "Appearance"
bool showEma = input.bool(true, "Show EMAs", group = GROUP_DISPLAY)
bool shadeTrend = input.bool(true, "Shade EMA Trend", group = GROUP_DISPLAY)
bool showPriceLabels = input.bool(true, "Show Level Prices", group = GROUP_DISPLAY)
color buyColor = input.color(color.rgb(0, 210, 150), "Buy Color", group = GROUP_DISPLAY)
color sellColor = input.color(color.rgb(255, 72, 88), "Sell Color", group = GROUP_DISPLAY)

float emaShort = ta.ema(source, shortEmaPeriod)
float emaLong = ta.ema(source, longEmaPeriod)
[macdLine, macdSignalLine, _] = ta.macd(source, macdFastPeriod, macdSlowPeriod, macdSignalPeriod)
float atrValue = ta.atr(atrPeriod)

bool bullish = emaShort > emaLong
bool bearish = emaShort < emaLong
bool macdCrossUp = ta.crossover(macdLine, macdSignalLine)
bool macdCrossDown = ta.crossunder(macdLine, macdSignalLine)
bool exactBuy = bullish and macdLine < 0 and macdCrossUp
bool exactSell = bearish and macdLine > 0 and macdCrossDown
bool rawBuy = signalMode == "Exact cTrader" ? exactBuy : bullish and macdCrossUp
bool rawSell = signalMode == "Exact cTrader" ? exactSell : bearish and macdCrossDown

color transparent = color.new(color.white, 100)
shortPlot = plot(showEma ? emaShort : na, "Fast EMA", color = color.new(bullish ? buyColor : sellColor, 5), linewidth = 2)
longPlot = plot(showEma ? emaLong : na, "Slow EMA", color = color.new(color.silver, 25), linewidth = 2)
fill(shortPlot, longPlot, color = shadeTrend and showEma ? color.new(bullish ? buyColor : sellColor, 90) : transparent, title = "Trend Shade")

// Signals must alternate: after BUY, another BUY is ignored until a valid SELL,
// and vice versa. Risk levels themselves remain active until SL, TP3, or reversal.
var bool tradeActive = false
var int tradeDirection = 0
var int lastSignalDirection = 0
var int entryBar = na
var float entryPrice = na
var float stopPrice = na
var float tp1Price = na
var float tp2Price = na
var float tp3Price = na
var int reachedR = 0

var line entryLine = na
var line stopLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
var linefill riskFill = na
var linefill rewardFill = na
var label entryLabel = na
var label stopLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
var label statusLabel = na

// Keep completed setups visible. The arrays let us remove only the oldest
// setup when the user-selected history limit is exceeded.
var array<line> setupLines = array.new<line>()
var array<linefill> setupFills = array.new<linefill>()
var array<label> setupLabels = array.new<label>()

trimSetupHistory() =>
    if array.size(setupLines) > historicalSetups * 5
        for i = 0 to 4
            line.delete(array.shift(setupLines))
        for i = 0 to 1
            linefill.delete(array.shift(setupFills))
        for i = 0 to 5
            label.delete(array.shift(setupLabels))

bool acceptedBuy = rawBuy and not rawSell and lastSignalDirection != 1 and not na(atrValue)
bool acceptedSell = rawSell and not rawBuy and lastSignalDirection != -1 and not na(atrValue)

if acceptedBuy or acceptedSell
    // A signal in the opposite direction closes the former active setup.
    // Its graphics stay frozen on the chart as historical information.
    if tradeActive
        tradeActive := false
        label.set_text(statusLabel, "REVERSED\n" + (reachedR > 0 ? "+" + str.tostring(reachedR) + "R" : "0R"))
        label.set_color(statusLabel, color.gray)
    tradeActive := true
    tradeDirection := acceptedBuy ? 1 : -1
    lastSignalDirection := tradeDirection
    entryBar := bar_index
    entryPrice := close
    float riskDistance = atrValue * atrMultiplier
    float riskCash = accountBalance * riskPercent / 100.0
    float suggestedUnits = riskCash / (riskDistance * unitPointValue)
    stopPrice := entryPrice - tradeDirection * riskDistance
    tp1Price := entryPrice + tradeDirection * riskDistance
    tp2Price := entryPrice + tradeDirection * riskDistance * 2.0
    tp3Price := entryPrice + tradeDirection * riskDistance * 3.0
    reachedR := 0
    int x2 = bar_index + projectionBars
    color directionColor = tradeDirection == 1 ? buyColor : sellColor
    entryLine := line.new(bar_index, entryPrice, x2, entryPrice, color = color.white, width = 2)
    stopLine := line.new(bar_index, stopPrice, x2, stopPrice, color = sellColor, width = 2)
    tp1Line := line.new(bar_index, tp1Price, x2, tp1Price, color = color.new(buyColor, 35), style = line.style_dashed)
    tp2Line := line.new(bar_index, tp2Price, x2, tp2Price, color = color.new(buyColor, 15), style = line.style_dashed)
    tp3Line := line.new(bar_index, tp3Price, x2, tp3Price, color = buyColor, width = 2)
    riskFill := linefill.new(entryLine, stopLine, color.new(sellColor, 88))
    rewardFill := linefill.new(entryLine, tp3Line, color.new(buyColor, 91))
    string priceSuffix = showPriceLabels ? "  " + str.tostring(entryPrice, format.mintick) : ""
    entryLabel := label.new(x2, entryPrice, (tradeDirection == 1 ? "LONG" : "SHORT") + " ENTRY" + priceSuffix, xloc = xloc.bar_index, style = label.style_label_left, color = directionColor, textcolor = color.white, size = size.small)
    stopLabel := label.new(x2, stopPrice, "SL" + (showPriceLabels ? "  " + str.tostring(stopPrice, format.mintick) : ""), xloc = xloc.bar_index, style = label.style_label_left, color = sellColor, textcolor = color.white, size = size.small)
    tp1Label := label.new(x2, tp1Price, "TP1  |  1R", xloc = xloc.bar_index, style = label.style_label_left, color = color.new(buyColor, 25), textcolor = color.white, size = size.tiny)
    tp2Label := label.new(x2, tp2Price, "TP2  |  2R", xloc = xloc.bar_index, style = label.style_label_left, color = color.new(buyColor, 12), textcolor = color.white, size = size.tiny)
    tp3Label := label.new(x2, tp3Price, "TP3  |  3R" + (showPriceLabels ? "  " + str.tostring(tp3Price, format.mintick) : ""), xloc = xloc.bar_index, style = label.style_label_left, color = buyColor, textcolor = color.white, size = size.small)
    statusLabel := label.new(bar_index, tradeDirection == 1 ? low : high, (tradeDirection == 1 ? "BUY" : "SELL") + "\nRisk " + str.tostring(riskPercent, "#.##") + "% | Size " + str.tostring(suggestedUnits, "#.##"), style = tradeDirection == 1 ? label.style_label_up : label.style_label_down, color = directionColor, textcolor = color.white)
    array.push(setupLines, entryLine)
    array.push(setupLines, stopLine)
    array.push(setupLines, tp1Line)
    array.push(setupLines, tp2Line)
    array.push(setupLines, tp3Line)
    array.push(setupFills, riskFill)
    array.push(setupFills, rewardFill)
    array.push(setupLabels, entryLabel)
    array.push(setupLabels, stopLabel)
    array.push(setupLabels, tp1Label)
    array.push(setupLabels, tp2Label)
    array.push(setupLabels, tp3Label)
    array.push(setupLabels, statusLabel)
    trimSetupHistory()

// Do not evaluate the entry candle: entry is assumed at its close.
if tradeActive and bar_index > entryBar
    bool stopHit = tradeDirection == 1 ? low <= stopPrice : high >= stopPrice
    bool tp1Hit = tradeDirection == 1 ? high >= tp1Price : low <= tp1Price
    bool tp2Hit = tradeDirection == 1 ? high >= tp2Price : low <= tp2Price
    bool tp3Hit = tradeDirection == 1 ? high >= tp3Price : low <= tp3Price
    if stopHit
        tradeActive := false
        label.set_text(statusLabel, "SL HIT\n-1R")
        label.set_color(statusLabel, sellColor)
        line.set_color(stopLine, color.white)
    else
        if tp1Hit and reachedR < 1
            reachedR := 1
            line.set_style(tp1Line, line.style_solid)
            line.set_width(tp1Line, 2)
        if tp2Hit and reachedR < 2
            reachedR := 2
            line.set_style(tp2Line, line.style_solid)
            line.set_width(tp2Line, 2)
        if tp3Hit
            reachedR := 3
            tradeActive := false
            label.set_text(statusLabel, "TP3 HIT\n+3R")
            label.set_color(statusLabel, buyColor)
            line.set_color(tp3Line, color.white)

// Keep the active setup projected to the right as new bars arrive.
if tradeActive
    int liveX2 = bar_index + projectionBars
    line.set_x2(entryLine, liveX2)
    line.set_x2(stopLine, liveX2)
    line.set_x2(tp1Line, liveX2)
    line.set_x2(tp2Line, liveX2)
    line.set_x2(tp3Line, liveX2)
    label.set_x(entryLabel, liveX2)
    label.set_x(stopLabel, liveX2)
    label.set_x(tp1Label, liveX2)
    label.set_x(tp2Label, liveX2)
    label.set_x(tp3Label, liveX2)

plotshape(acceptedBuy, "Buy Signal", shape.triangleup, location.belowbar, buyColor, size = size.small)
plotshape(acceptedSell, "Sell Signal", shape.triangledown, location.abovebar, sellColor, size = size.small)

alertcondition(acceptedBuy, "EmaMacdIce Buy", "EmaMacdIce BUY on {{ticker}} {{interval}}")
alertcondition(acceptedSell, "EmaMacdIce Sell", "EmaMacdIce SELL on {{ticker}} {{interval}}")
alertcondition(not tradeActive and tradeActive[1], "EmaMacdIce Setup Closed", "EmaMacdIce setup closed on {{ticker}} {{interval}}")

FAQ

Common questions.

What creates a BUY or SELL signal?

In the default "EMA trend MACD crosses" mode, BUY requires the 60 EMA above the 240 EMA plus a bullish MACD signal-line cross; SELL requires the opposite. "Exact cTrader" also requires MACD to be below zero for buys or above zero for sells.

How are the stop-loss and targets calculated?

The stop is set at ATR × the "SL ATR Multiplier" from the signal-bar close, using ATR 14 and a 1.5 multiplier by default. TP1, TP2, and TP3 are placed at 1R, 2R, and 3R from entry.

Does EmaMacdIce Risk Manager place trades?

No. It is a TradingView indicator that plots signals, projected levels, and a position-size estimate; it does not place orders or run as a TradingView strategy.

Does the indicator repaint?

Historical signals are based on completed chart bars, but MACD cross conditions can change while the current realtime bar is still forming. Waiting for bar close helps avoid acting on an intrabar cross that does not remain valid at close.

How do alerts work?

The script provides separate TradingView alert conditions for "EmaMacdIce Buy", "EmaMacdIce Sell", and "EmaMacdIce Setup Closed". Create an alert from the indicator's alert conditions and choose your preferred TradingView alert frequency.

Is this financial advice or proof of live performance?

No. This indicator is not financial advice, and its plotted levels are not evidence of live results. Use TradingView Strategy Tester or your platform's equivalent, together with your own execution data, as the source of truth for tested and live outcomes.

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.