Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

//@version=5

indicator("TZ and PTZ Calculations", shorttitle="TZ/PTZ", overlay=true)

// Inputs
h_left = input.int(9, title="H left", minval=1, maxval=50)
h_right = input.int(9, title="H right", minval=1, maxval=50)
sample_period = input.int(6000, title="Sample bars for % TZ", minval=100,
maxval=10000)
show_ptz = input.bool(true, title="Show PTZ")
show_channel = input.bool(true, title="Show channel")
timeframe = input.timeframe("5", title="Timeframe")

// Optimized True Zone (TZ) and Potential True Zone (PTZ) calculations
[h_left_low, h_left_high, central_bar_low, central_bar_high, full_zone_low,
full_zone_high] = request.security(syminfo.tickerid, timeframe, [
ta.lowest(low, h_left),
ta.highest(high, h_left),
low[h_right + 1],
high[h_right + 1],
ta.lowest(low, h_left + h_right + 1),
ta.highest(high, h_left + h_right + 1)
], lookahead=barmerge.lookahead_on)

newlow = low <= h_left_low


newhigh = high >= h_left_high
central_bar_is_highest = central_bar_high >= full_zone_high
central_bar_is_lowest = central_bar_low <= full_zone_low

// Plotting optimized
plotshape(series=newlow and show_ptz, title="PTZ Low", shape=shape.triangledown,
location=location.belowbar, color=color.red, size=size.tiny)
plotshape(series=newhigh and show_ptz, title="PTZ High", shape=shape.triangleup,
location=location.abovebar, color=color.green, size=size.tiny)
channel_high = plot(series=show_channel ? h_left_high : na, title="Channel High",
color=color.silver)
channel_low = plot(series=show_channel ? h_left_low : na, title="Channel Low",
color=color.silver)

You might also like