AI Brain: RSI + Structure Tracker — Strategy by chapmancapital1

By version

Performance Metrics

Description

//version=5strategy("AI Brain: RSI + Structure Tracker", overlay=true, initial_capital=5000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10)// ==========================================// 1. INPUT PARAMETERS// ==========================================// -- RSI & SMA --rsiLen = input.int(14, "RSI Length", group="Trend Settings")rsiOverSold = input.int(30, "RSI Oversold Level", group="Trend Settings")rsiOverBought = input.int(70, "RSI Overbought Level", group="Trend Settings")smaFastLen = input.int(50, "SMA Fast Length", group="Trend Settings")smaSlowLen = input.int(200, "SMA Slow Length", group="Trend Settings")// -- Structure Detection --structLookback = input.int(10, "Structure Lookback (Swings)", group="Market Structure")showLabels = input.bool(true, "Show HH/HL/LL/LH Labels", group="Market Structure")// -- Risk Management --useATRexit = input.bool(true, "Use ATR Stop Loss/Take Profit", group="Risk Management")atrLen = input.int(14, "ATR Length", group="Risk Management")atrMultSL = input.float(1.5, "Stop Loss ATR Multiplier", group="Risk Management")atrMultTP = input.float(3.0, "Take Profit ATR Multiplier", group="Risk Management")// ==========================================// 2. MARKET STRUCTURE LOGIC (HH, HL, LL, LH)// ==========================================// Find Swing Highs and Lows based on pivot pointsswingHigh = ta.pivothigh(high, structLookback, structLookback)swingLow = ta.pivotlow(low, structLookback, structLookback)// Variable to store the current trend statevar string trendState = "Neutral"// Variables to store last swing values for comparisonvar float lastSwingHigh = 0.0var float lastSwingLow = 0.0// --- Structure Calculations ---// We calculate this on every bar to ensure the "Trend" is up to date// 1. Process New Swing Highif not na(swingHigh) // If current high is higher than previous high -> HH isHH = swingHigh > lastSwingHigh // If current high is lower than previous high -> LH isLH = swingHigh HL isHL = swingLow > lastSwingLow // If current low is lower than previous low -> LL isLL = swingLow sma200smaTrendDown = sma50 < sma200// -- Combined Entry Conditions --// Long: RSI oversold + SMA Trend Up + Structure is "Up" (HH/HL confirmed)longCondition = rsiBuyTrigger and smaTrendUp and trendState == "Up"// Short: RSI overbought + SMA Trend Down + Structure is "Down" (LL/LH confirmed)shortCondition = rsiSellTrigger and smaTrendDown and trendState == "Down"// -- Dynamic Exits --longSL = close - atr * atrMultSLlongTP = close + atr * atrMultTPshortSL = close + atr * atrMultSLshortTP = close - atr * atrMultTP// ==========================================// 5. EXECUTION// ==========================================if longCondition strategy.entry("Buy", strategy.long) if useATRexit strategy.exit("Exit Buy", "Buy", stop=longSL, limit=longTP)if shortCondition strategy.entry("Sell", strategy.short) if useATRexit strategy.exit("Exit Sell", "Sell", stop=shortSL, limit=shortTP)// ==========================================// 6. VISUALIZATION// ==========================================// Plot SMAsplot(sma50, color=color.yellow, title="SMA 50", linewidth=2)plot(sma200, color=color.blue, title="SMA 200", linewidth=2)// Background color for Trend Statebgcolor(trendState == "Up" ? color.new(color.green, 95) : trendState == "Down" ? color.new(color.red, 95) : na)// Plot Buy/Sell Signalsplotshape(longCondition, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.normal)plotshape(shortCondition, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal)

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView