PEAKTROUGHLIB268
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © agungkuswanto

//@version=5
library(title = "PEAKTROUGHLIB268", overlay=true)


h4daysago = high[4]
h3daysago = high[3]
h2daysago = high[2]
h1daysago = high[1]


thePeakCond = h4daysago <= h3daysago and h3daysago >= h2daysago and h3daysago >= h1daysago and h3daysago > high
thePeak = ta.valuewhen(thePeakCond, h3daysago, 0)


l4daysago = low[4]
l3daysago = low[3]
l2daysago = low[2]
l1daysago = low[1]

theTroughCond = l4daysago >= l3daysago and l3daysago <= l2daysago and l2daysago <= l1daysago and l3daysago <= low
theTrough = ta.valuewhen(theTroughCond, l3daysago, 0)

plot (thePeak, title="PEAK", color=color.lime, linewidth=1 )
plot (theTrough, title="TROUGH", color=color.orange, linewidth=1 )

export showThePeak() =>
    ta.valuewhen(thePeakCond, h3daysago, 0)
    
export showTheTrough() =>
    ta.valuewhen(theTroughCond, l3daysago, 0)
    