same as the Range bot from Ninja AI/ 5min HA candles, just plot it as it is and test it out ( MNQ or NQ 1 contract). thanks
//@version=6
strategy("Range Swing Bias Strategy (0-100 Scale) [NinjaBotAI]", overlay=true, max_lines_count=500, max_labels_count=500,
initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ─────────────────────────────
// Inputs
// ─────────────────────────────
swingPeriod = input.int(15, "Swing Period", minval=1)
swingMultiplier = input.float(4, "Swing Multiplier", step=0.1)
lookback = input.int(50, "Normalization Lookback") // for 0-100 scaling
showSwingLine = input.bool(true, "Show Swing Line")
colorBg = input.bool(false, "Color Background by Bias")
takeProfitPerc = input.float(2.0, "Take Profit (%)", step=0.1)
stopLossPerc = input.float(1.0, "Stop Loss (%)", step=0.1)
// ─────────────────────────────
// Double-smoothed price change
// ─────────────────────────────
priceChange = math.abs(close - close[1])
fastEMA = ta.ema(priceChange, swingPeriod)
slowPeriod = swingPeriod * 2 - 1
slowEMA = ta.ema(fastEMA, slowPeriod)
// ─────────────────────────────
// Swing line calculation
// ─────────────────────────────
bandwidth = slowEMA * swingMultiplier
var float swingLine = na
swingLine := na(swingLine[1]) ? close :
close - bandwidth > swingLine[1] ? close - bandwidth :
close + bandwidth < swingLine[1] ? close + bandwidth :
swingLine[1]
// ─────────────────────────────
// Directional bias (slope-based)
// ─────────────────────────────
var int bias = 0
s = swingLine
bias := s > s[1] ? 1 : s < s[1] ? -1 : bias[1]
// ─────────────────────────────
// Normalize swing line to 0-100 scale
// ─────────────────────────────
minSwing = ta.lowest(swingLine, lookback)
maxSwing = ta.highest(swingLine, lookback)
swingScaled = maxSwing != minSwing ? 100 * (swingLine - minSwing) / (maxSwing - minSwing) : 50
// ─────────────────────────────
// Plotting
// ─────────────────────────────
plot(showSwingLine ? swingScaled : na, "Swing Line (0-100)", color=bias == 1 ? color.lime : color.red, linewidth=2)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)
bgcolor(colorBg ? (bias == 1 ? color.new(color.green, 85) : color.new(color.red, 85)) : na)
plotchar(bias == 1, title="Bullish Bias", char="▲", location=location.bottom, color=color.lime, size=size.tiny)
plotchar(bias == -1, title="Bearish Bias", char="▼", location=location.top, color=color.red, size=size.tiny)
// ─────────────────────────────
// Strategy Logic (swing slope-based)
// ─────────────────────────────
longCondition = bias == 1 and bias[1] != 1 // enters long only when bias flips to bullish
shortCondition = bias == -1 and bias[1] != -1 // enters short only when bias flips to bearish
// Exit levels based on percentage
longStop = close * (1 - stopLossPerc / 100)
longTP = close * (1 + takeProfitPerc / 100)
shortStop = close * (1 + stopLossPerc / 100)
shortTP = close * (1 - takeProfitPerc / 100)
// Close opposite position first before opening new
if longCondition
strategy.close("Short")
strategy.entry("Long", strategy.long, stop=longStop, limit=longTP)
if shortCondition
strategy.close("Long")
strategy.entry("Short", strategy.short, stop=shortStop, limit=shortTP)