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

//@version=5
indicator("Sniper Entry", overlay = true)

// Constants
riskRewardRatio = 3
startingCapital = 100
lotSize = 0.01

// Functions
bullishPinBar(c, o) =>
    c > o and (c - o) / o >= 0.05
bearishPinBar(c, o) =>
    c < o and (o - c) / o >= 0.05
bullishEngulfing(c, o) =>
    c > o and close[1] < open[1]
bearishEngulfing(c, o) =>
    c < o and close[1] > open[1]

// Indicator calculations
stochastic = ta.stoch(close, high, low, 14)

// Buy signal
longCondition = ta.crossover(stochastic, 20)
buySignal = longCondition and (bullishPinBar(close, open) or bullishEngulfing(close, open))

// Buy stop loss
buyStopLoss = longCondition ? low : na

// Buy target
buyTarget = (high + low) / 2 + riskRewardRatio * (high - low)

// Sell signal
shortCondition = ta.crossunder(stochastic, 80)
sellSignal = shortCondition and (bearishPinBar(close, open) or bearishEngulfing(close, open))

// Sell stop loss
sellStopLoss = shortCondition ? high : na

// Sell target
sellTarget = (high + low) / 2 - riskRewardRatio * (high - low)

// Plot signals and levels
plotshape(buySignal, title='Buy', location=location.belowbar, color=color.new(color.green, 0), size=size.small)
plot(buyStopLoss, title='Buy Stop Loss', color=color.red)
plot(buyTarget, title='Buy Target', color=color.green)

plotshape(sellSignal, title='Sell', location=location.abovebar, color=color.new(color.red, 0), size=size.small)
plot(sellStopLoss, title='Sell Stop Loss', color=color.green)
plot(sellTarget, title='Sell Target', color=color.red)

