FCScalper Posted 1 hour ago Report Posted 1 hour ago 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)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now