TradingView indicators

Elder Impulse System on TradingView

The Elder Impulse System colors a bar green when its 13-period EMA and MACD histogram both rise, red when both fall, and blue otherwise. Compare each value with the previous bar. A positive histogram alone is not enough for green.

Use this guide to audit the calculation, identify flat or mixed states, and decide when a bar becomes final. The color is a state description; entries, exits, sizing and trading costs need separate rules.

Formula and complete color matrix

The script calculates the MACD line as EMA(close, 12) minus EMA(close, 26), its signal as a 9-period EMA of that line, and the histogram as MACD minus signal. The separate trend calculation is EMA(close, 13). These lengths count chart bars.

ΔEMA = EMA[t] − EMA[t−1]

ΔHistogram = Histogram[t] − Histogram[t−1]

Strict comparisons in the supplied script; values must be available.
EMA directionHistogram risesHistogram flatHistogram falls
RisesGreenBlueBlue
FlatBlueBlueBlue
FallsBlueBlueRed

Flat means exact equality, not two numbers rounded to the same displayed value. The script has no tolerance or minimum-slope threshold. A tiny change can therefore change the color. Adding a tolerance creates a modified rule that should be documented.

The matrix follows the StockCharts calculation; the component formulas match TradingView's MACD documentation. EMA and MACD both use close here, so their agreement is not independent evidence from two different data sources.

Worked example: six comparison states

These are hypothetical EMA and histogram outputs supplied to the color rule. They test comparisons only: they are not a price history, an EMA reconstruction or a backtest. Assume exact values and a closed bar for each row.

BarEMAHistogramΔEMAΔHistogramResult
A100.00−0.40BaselineBaselineNo prior comparison
B100.20−0.20+0.20+0.20Green
C100.35−0.25+0.15−0.05Blue
D100.25−0.35−0.10−0.10Red
E100.25−0.300.00+0.05Blue
F100.40−0.30+0.150.00Blue

At B, −0.20 − (−0.40) = +0.20: momentum rises below zero, and the EMA rises too. At C, the EMA keeps rising but the histogram falls by 0.05, producing blue. D satisfies both falling tests. E and F show why a tie in either component prevents green or red.

Row A provides a comparison baseline. In the script, the first loaded bar has no prior values; its comparisons do not establish either directional condition, so the fallback color is blue. Treat that as unavailable history, not evidence of a neutral market. Early EMA values also depend on initialization.

Pine Script v6: inspect and copy

Paste this complete indicator into TradingView's Pine Editor, save it, and add it to a chart. It colors existing price bars. The lengths are fixed in the source: the script does not expose length inputs, generate orders or define alerts.

Pine Script v6 · chart timeframe
//@version=6
indicator(title="Elder Impulse System", overlay=true, max_labels_count=500)

// Calculate MACD
macd_ma_fast = ta.ema(close, 12)
macd_ma_slow = ta.ema(close, 26)
macd = macd_ma_fast - macd_ma_slow
macd_signal = ta.ema(macd, 9)
macd_histogram = macd - macd_signal

// Calculate 13-period EMA
ema = ta.ema(close, 13)

// Determine Elder Impulse
elder_bulls = (ema > ema[1]) and (macd_histogram > macd_histogram[1])
elder_bears = (ema < ema[1]) and (macd_histogram < macd_histogram[1])
elder_color = elder_bulls ? 1 : elder_bears ? -1 : 0

// Bar Coloring
barcolor(elder_color == 1 ? color.rgb(38, 166, 154) :
         elder_color == -1 ? color.rgb(239, 83, 80) :
         color.rgb(33, 150, 243), title="EIS Bar Color")

For a chart comparison, add an EMA with length 13 and source close, then MACD with 12/26/9 and EMA smoothing for both oscillator and signal. Compare their values on two adjacent closed bars. Keep symbol, timeframe, session and chart type identical.

Elder Impulse System chart preview with colored price bars
Existing indicator preview for visual orientation. Use the source and comparison table to verify exact behavior; the image is not a performance result.

Confirmation and when a trade should wait

The current bar can change color before it closes. Its latest price changes the EMA and histogram, so an intrabar green reading may finish blue or red. This example has no bar-close gate. A close-confirmed adaptation should require barstate.isconfirmed at the point where its signal becomes actionable, as described in TradingView's bar-state documentation.

  • Direction filter: a rule that blocks shorts on green and longs on red still needs a separate entry setup. A permitted direction is not an instruction to place an order.
  • Blue state: the two directional tests are not aligned. Skipping every blue bar is an optional strategy restriction. Blue alone does not prove low volatility, predict a reversal, or require an exit.
  • Missing comparison or open bar: wait if the trading plan requires valid previous values and a final color. Initial blue fallback and an unconfirmed color do not meet those requirements.
  • Multiple timeframes: this code uses only the chart timeframe. If a plan separately checks a higher timeframe, define that bar's confirmation rule too; the chart bar closing does not close the higher-timeframe bar.

Confirmation resolves one timing issue. It does not prove a profitable signal, prevent rapid color changes between closed bars, or remove changes caused by revised source data. See TradingView's repainting discussion. Define exits, risk limits, commission and slippage before testing a strategy built around these states.

Specify the behavior in Pineify

Pineify's Pine Script AI Coding Agent can help turn these requirements into an editable indicator. Give it the comparison rules and expected results before asking for extra features.

Create an Elder Impulse System indicator using close, EMA 13, and MACD 12/26/9. Expose the four lengths as inputs. Use strict comparisons; ties are blue. Add a close-confirmed mode and distinguish missing history from neutral states. Include the EMA, histogram and state values in the Data Window so I can check adjacent bars. Keep entry and exit orders separate.

Review the generated code against the matrix, test the below-zero example and both tie cases, then compare live and closed-bar behavior. Syntax validation checks the script's language; it does not validate trading performance.

Open Pine Script AI Coding Agent

Educational information, not investment advice. The example does not establish a trading edge.

Frequently asked questions

It combines the direction of a 13-period EMA with the change in a MACD(12,26,9) histogram. Both rising produces green; both falling produces red. Every other combination is blue. It describes agreement between two calculations on the same price series.

Yes. A histogram moving from −0.40 to −0.20 is rising even though both values are negative. If the EMA also rises, the impulse bar is green. The histogram zero line does not determine the impulse color.

Blue means neither directional alignment condition is true. It does not impose a universal trading ban. A strategy may choose to skip blue bars, but that is an additional entry rule. Blue also does not predict a flat market or require closing a position.

The example uses strict greater-than and less-than comparisons. An exact tie in either component makes both directional conditions false, so the bar is blue. Values that merely look equal after display rounding can still differ internally.

No. It colors the current chart bar as prices update. Use closed bars for a stable comparison, or specify a bar-close condition when adapting the script. Confirmation settles the current bar calculation; it does not confirm that the next price move will follow the color.

The supplied script fixes the EMA length at 13 and MACD lengths at 12, 26 and 9. It has no length inputs in the settings panel. Edit those constants or ask Pineify to expose them as inputs, then compare the changed output bar by bar. No alternative setting is established here as best.