Snapshots




How it works
- Two EMAs (9 and 21 by default) are plotted, and ta.crossover / ta.crossunder mark where they cross.
- A var trend variable remembers the direction of the last cross, and bgcolor shades the chart green or red from it.
- It is deliberately small and uses an if block, strings and several function calls, so every common paste error shows up in it.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fast EMA | 9 | Fast EMA length |
| Slow EMA | 21 | Slow EMA length |
Source code
In TradingView: open the Pine Editor, create a new indicator, paste the code, then click "Add to chart".
//@version=6 indicator("Paste Check", overlay = true) fastLen = input.int(9, "Fast EMA") slowLen = input.int(21, "Slow EMA") fast = ta.ema(close, fastLen) slow = ta.ema(close, slowLen) plot(fast, "Fast", color = color.teal, linewidth = 2) plot(slow, "Slow", color = color.orange, linewidth = 2) bullCross = ta.crossover(fast, slow) bearCross = ta.crossunder(fast, slow) var int trend = 0 if bullCross trend := 1 else if bearCross trend := -1 bullBg = color.new(color.green, 88) bearBg = color.new(color.red, 88) bgcolor(trend == 1 ? bullBg : trend == -1 ? bearBg : na) plotshape(bullCross, "Buy", shape.triangleup, location.belowbar, color.green) plotshape(bearCross, "Sell", shape.triangledown, location.abovebar, color.red)
Watch it built
This script is written and explained step by step in the video lesson.
Need a custom indicator or strategy?
Non-repainting Pine Script v6, backtested with real costs, alert and webhook ready. Fixed quote within 24 hours.