//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © ceyhun
study("Top Bottom ", overlay=true)
per = input(14, title="Bottom Period")
loc = low < lowest(low[1], per) and low <= lowest(low[per], per)
bottom = barssince(loc)
per2 = input(14, title="Top Period")
loc2 = high > highest(high[1], per2) and high >= highest(high[per2], per2)
top = barssince(loc2)
/////BUY-SELL/////
Buy = crossover(bottom, top)
Sell = crossunder(bottom, top)
plotshape(Buy,"BUY", shape.labelup, location.belowbar, color.green,
text="BUY",textcolor=color.black)
plotshape(Sell,"SELL", shape.labeldown, location.abovebar, color.red,
text="SELL",textcolor=color.black)
background = top < bottom ? color.new(#0000FF,85) : top > bottom ?
color.new(#FF0000,85) : na
bgcolor(color=background)
alertcondition(Buy, title="Buy Signal", message="Buy")
alertcondition(Sell, title="Sell Signal", message="Sell")