Quantellics: NQ Reverse From EMA [Strategy]

// © 2025 Quantellics. All rights reserved.
strategy("Quantellics: NQ Reverse From EMA [Strategy]", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
// Inputs
emaLen = input.int(60, "EMA Length", minval = 1)
rsiLen = input.int(14, "RSI Length", minval = 1)
lb = input.int(10, "Lookback Candles", minval = 1)
entryOff = input.float(75.0, "Entry Offset ($)", minval = 0, step = 1)
slDollar = input.float(50.0, "Stop Loss ($)", minval = 0, step = 1)
tpDollar = input.float(50.0, "Take Profit ($)", minval = 0, step = 1)
trailAct = input.float(30.0, "Trail Activation ($)", minval = 0, step = 1)
trailOff = input.float(30.0, "Trail Offset ($)", minval = 0, step = 1)
trailDelay = input.int(2, "Trail Delay (Candles)", minval = 0, step = 1)
ssH = input.int(9, "Session Start Hour (ET)", minval = 0, maxval = 23)
ssM = input.int(30, "Session Start Minute (ET)", minval = 0, maxval = 59)
seH = input.int(12, "Session End Hour (ET)", minval = 0, maxval = 23)
seM = input.int(0, "Session End Minute (ET)", minval = 0, maxval = 59)
// Session calc
int h = hour(time, "America/New_York")
int m = minute(time, "America/New_York")
sStart = ssH * 60 + ssM
sEnd = seH * 60 + seM
nowMin = h * 60 + m
inSess = nowMin >= sStart and nowMin < sEnd
eos = nowMin >= sEnd
// Indicators
ema60 = ta.ema(close, emaLen)
rsi = ta.rsi(close, rsiLen)
hiN = ta.highest(high, lb)
loN = ta.lowest(low, lb)
// Levels
longLvl = hiN - entryOff
shortLvl = loN + entryOff
// Conditions
longOk = high[1] > ema60[1] and rsi[1] > 50 and strategy.position_size == 0 and inSess and not eos
shortOk = low[1] < ema60[1] and rsi[1] < 50 and strategy.position_size == 0 and inSess and not eos
// State
var float ePrice = na
var float slLvl = na
var float tpLvl = na
var int bars = 0
if strategy.position_size != 0
bars += 1
else
bars := 0
// Orders
if longOk
strategy.entry("Long", strategy.long, limit = longLvl)
else
strategy.cancel("Long")
if shortOk
strategy.entry("Short", strategy.short, limit = shortLvl)
else
strategy.cancel("Short")
if strategy.position_size > 0
if bars > trailDelay
strategy.exit("Long Exit", "Long", stop = strategy.position_avg_price - slDollar, limit = strategy.position_avg_price + tpDollar, trail_points = trailAct, trail_offset = trailOff)
else
strategy.exit("Long Exit", "Long", stop = strategy.position_avg_price - slDollar, limit = strategy.position_avg_price + tpDollar)
if strategy.position_size < 0
if bars > trailDelay
strategy.exit("Short Exit", "Short", stop = strategy.position_avg_price + slDollar, limit = strategy.position_avg_price - tpDollar, trail_points = trailAct, trail_offset = trailOff)
else
strategy.exit("Short Exit", "Short", stop = strategy.position_avg_price + slDollar, limit = strategy.position_avg_price - tpDollar)
// EOS flat
if eos and strategy.position_size != 0
strategy.close_all(comment = "EOS Exit")
if eos
strategy.cancel_all()
// Tracking
if strategy.position_size > 0 and strategy.position_size[1] <= 0
ePrice := strategy.position_avg_price
slLvl := ePrice - slDollar
tpLvl := ePrice + tpDollar
if strategy.position_size < 0 and strategy.position_size[1] >= 0
ePrice := strategy.position_avg_price
slLvl := ePrice + slDollar
tpLvl := ePrice - tpDollar
// Plots
plot(ema60, color = color.blue, title = "EMA 60", linewidth = 2)
plot(hiN, color = color.new(color.green, 50), title = "Lookback High", linewidth = 1, style = plot.style_stepline)
plot(loN, color = color.new(color.red, 50), title = "Lookback Low", linewidth = 1, style = plot.style_stepline)
plot(longLvl, color = color.new(color.orange, 30), title = "Long Entry", linewidth = 2)
plot(shortLvl, color = color.new(color.purple, 30), title = "Short Entry", linewidth = 2)
Invite-only script
Only users approved by the author can access this script. You'll need to request and get permission to use it. This is typically granted after payment. For more details, follow the author's instructions below or contact mchernyshov directly.
TradingView does NOT recommend paying for or using a script unless you fully trust its author and understand how it works. You may also find free, open-source alternatives in our community scripts.
Author's instructions
Disclaimer
Invite-only script
Only users approved by the author can access this script. You'll need to request and get permission to use it. This is typically granted after payment. For more details, follow the author's instructions below or contact mchernyshov directly.
TradingView does NOT recommend paying for or using a script unless you fully trust its author and understand how it works. You may also find free, open-source alternatives in our community scripts.