// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Adam911
//@version=5
//0.005
indicator("QTE Scalper Modified", overlay=true)
emaPeriodInput = input.int(10, "EMA Period", minval=2, maxval=50)
upArrowColorInput = input.color(color.green, "Up Arrow Color")
downArrowColorInput = input.color(color.rgb(255, 0, 21), "Down Arrow Color")
minAtrValueInput = input.float(1, "Minimum ATR Value for Signals", minval=0) // Default changed to 1
showAtrLabelInput = input.bool(true, "Show ATR Label")
atrLabelColorInput = input.color(color.white, "ATR Label Color")
touchTypeInput = input.string("Body Touch", "Candle Touch Type", options=["Body Touch", "Wick Touch", "No Touch"]) // Default changed to 'Body Touch'
// Create the EMA Filter line
emaFilter = ta.ema(close, emaPeriodInput)
plot(emaFilter, linewidth = 2)
// Calculate the 10-period ATR
atrValue = ta.atr(10)
// Basic signal conditions
upArrowCondition = ((high < high[1]) and (low < low[1])) and (open < close) and (close > emaFilter) and (close[1] > emaFilter[1]) and (atrValue > minAtrValueInput)
downArrowCondition = ((high > high[1]) and (low > low[1])) and (open > close) and (close < emaFilter) and (close[1] < emaFilter[1]) and (atrValue > minAtrValueInput)
// New 'Body Touch' condition
bool bodyTouchUp = (open < emaFilter and close > emaFilter) or (open > emaFilter and close < emaFilter)
bool bodyTouchDown = bodyTouchUp
bool wickTouchUp = (low <= emaFilter and close > emaFilter and open > emaFilter)
bool wickTouchDown = (high >= emaFilter and close < emaFilter and open < emaFilter)
// Existing 'No Touch' condition (unchanged)
bool noTouchUp = low > emaFilter // Entire candle, including wick, is above EMA
bool noTouchDown = high < emaFilter // Entire candle, including wick, is below EMA
// Modified logic for applying touch type conditions to signals
bool upArrow = false
bool downArrow = false
if touchTypeInput == "Body Touch"
upArrow := upArrowCondition and (bodyTouchUp or wickTouchUp or noTouchUp)
downArrow := downArrowCondition and (bodyTouchDown or wickTouchDown or noTouchDown)
else if touchTypeInput == "Wick Touch"
upArrow := upArrowCondition and (wickTouchUp or noTouchUp)
downArrow := downArrowCondition and (wickTouchDown or noTouchDown)
else if touchTypeInput == "No Touch"
upArrow := upArrowCondition and noTouchUp
downArrow := downArrowCondition and noTouchDown
alertcondition(upArrow, title="Bullish Signal", message="Bullish signal detected.")
alertcondition(downArrow, title="Bearish Signal", message="Bearish signal detected.")
plotshape(upArrow, style=shape.arrowup, color=upArrowColorInput, size=size.normal, location = location.belowbar)
plotshape(downArrow, style=shape.arrowdown, color=downArrowColorInput, size=size.normal, location = location.abovebar)
// Display the ATR Label (if enabled)
var label atrLabel = na
if showAtrLabelInput and barstate.islast
label.delete(atrLabel)
atrLabel := label.new(bar_index, high, "ATR: " + str.tostring(atrValue), yloc=yloc.abovebar, style=label.style_label_down, color=atrLabelColorInput)