//@version=5
strategy("Parabolic SAR - Eterna",
overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=10,
commission_type=strategy.commission.percent,
commission_value=0.075)
// ==================== Parameters ====================
sarStart = input.float(0.02, "SAR Start", minval=0.001, step=0.001)
sarIncrement = input.float(0.02, "SAR Increment", minval=0.001, step=0.001)
sarMaximum = input.float(0.2, "SAR Maximum", minval=0.01, step=0.01)
trendFilter = input.int(50, "Trend Filter EMA", minval=1)
useTrendFilter = input.bool(true, "Use Trend Filter")
leverage = input.int(5, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, step=0.001)
webhookMessage = input.string('{"action":"{{strategy.order.action}}", "symbol":"{{ticker}}", "size":' + str.tostring(positionSize) + ', "leverage":' + str.tostring(leverage) + '}',
"Webhook JSON", group="Webhook")
// ==================== Indicators ====================
sarValue = ta.sar(sarStart, sarIncrement, sarMaximum)
trendEMA = ta.ema(close, trendFilter)
// ==================== Entry Conditions ====================
// SAR flips indicate trend change
sarBullish = sarValue < close
sarBearish = sarValue > close
// Detect SAR flip
sarFlipUp = ta.crossover(close, sarValue)
sarFlipDown = ta.crossunder(close, sarValue)
// Optional trend filter
longCondition = useTrendFilter ? (sarFlipUp and close > trendEMA) : sarFlipUp
shortCondition = useTrendFilter ? (sarFlipDown and close < trendEMA) : sarFlipDown
// ==================== Strategy Execution ====================
if longCondition
strategy.entry("Long", strategy.long, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "buy"))
if shortCondition
strategy.entry("Short", strategy.short, alert_message=str.replace(webhookMessage, "{{strategy.order.action}}", "sell"))
// ==================== Plotting ====================
plot(sarValue, "SAR", style=plot.style_cross, color=sarBullish ? color.green : color.red, linewidth=2)
plot(useTrendFilter ? trendEMA : na, "Trend EMA", color=color.orange, linewidth=1)
plotshape(longCondition, "Long", shape.triangleup, location.belowbar, color.green, size=size.normal)
plotshape(shortCondition, "Short", shape.triangledown, location.abovebar, color.red, size=size.normal)
bgcolor(sarBullish ? color.new(color.green, 95) : color.new(color.red, 95))
// SAR dots
plotchar(sarValue, "SAR Dots", "•", location=sarBullish ? location.belowbar : location.abovebar,
color=sarBullish ? color.green : color.red, size=size.tiny)