OPEN-SOURCE SCRIPT

13 EMA Cross - Next Day High/Low

//version=6
indicator("13 EMA Cross - Next Day High/Low", overlay=true)

// Inputs for EMAs
length1 = input.int(13, title="Short EMA (13 EMA)")
length2 = input.int(34, title="Long EMA (34 EMA)")

// Input for support line properties
supportColor = input.color(#A52A2A, title="Support Line Color") // Brown color
lineWidth = input.int(2, title="Line Width")

// Calculate EMAs
ema13 = ta.ema(close, length1)
ema34 = ta.ema(close, length2)

// Detect Crosses
crossAbove = ta.crossover(ema13, ema34)
crossBelow = ta.crossunder(ema13, ema34)

// Track when a crossover happens
var float nextDayHigh = na
var float nextDayLow = na
var int crossoverBarIndex = na

if crossAbove or crossBelow
crossoverBarIndex := bar_index
nextDayHigh := na
nextDayLow := na

// Capture next day candle's high and low after crossover
if bar_index == crossoverBarIndex + 1
nextDayHigh := high
nextDayLow := low

// Draw horizontal lines at the next day's high and low
if not na(nextDayHigh) and not na(nextDayLow)
line.new(x1=crossoverBarIndex + 1, y1=nextDayHigh, x2=bar_index, y2=nextDayHigh, color=supportColor, width=lineWidth)
line.new(x1=crossoverBarIndex + 1, y1=nextDayLow, x2=bar_index, y2=nextDayLow, color=supportColor, width=lineWidth)
Candlestick analysisChart patternsMoving Averages

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer