//@version=5
strategy('Nas Infinity Algo [AlgoPoint] Strategy', overlay=true)
Periods = 40
src = hl2
Multiplier = input.float(title='Sensitivity', step=0.1, defval=7.2)
changeATR = true
showsignals = input(title='Show Buy/Sell Signals ?', defval=true)
highlighting = input(title='Highlighter On/Off ?', defval=false)
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
longCondition = trend == 1 and trend[1] == -1
if (longCondition)
    strategy.entry('Buy', strategy.long)
shortCondition = trend == -1 and trend[1] == 1
if (shortCondition)
    strategy.entry('Sell', strategy.short)
plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, linewidth=2,
color=highlighting ? color.green : na)
plot(trend == -1 ? dn : na, title='Down Trend', style=plot.style_linebr,
linewidth=2, color=highlighting ? color.red : na)
// Peak Profit
import protradingart/pta_plot/6 as pp
pp.peakprofit(longCondition, shortCondition)