Roylty Ai Trading Code (Stocks, Options, ETFs, Index)
This Exclusive code was made for TradingView, use wisely and get money!
E. Morra Ai Trading Code:
//@version=6
strategy("Neural BB Reversal Pro", overlay=true,
initial_capital=100000,
default_qty_type=strategy.percent_of_equity,
commission_type=strategy.commission.percent,
commission_value=0.075,
pyramiding=0)
// === AI LEARNING MODULE ===
var float[] winRates = array.new_float(0)
var float[] rewardRatios = array.new_float(0)
var int learningCycle = 0
// === ADAPTIVE PARAMETERS ===
bbLength = input.int(20, "BB Length", minval=10, maxval=50)
bbMult = input.float(2.0, "BB StdDev", minval=1.5, maxval=3.0, step=0.1)
autoOptimize = input(true, "AI Auto-Optimize")
// === BOLLINGER BAND REVERSAL SYSTEM ===
basis = ta.sma(close, bbLength)
dev = bbMult * ta.stdev(close, bbLength)
upperBB = basis + dev
lowerBB = basis - dev
// Enhanced Reversal Detection
priceCrossUpper = ta.crossover(close, upperBB)
priceCrossLower = ta.crossunder(close, lowerBB)
wickReversalUpper = high[1] > upperBB[1] and close < open and close > upperBB
wickReversalLower = low[1] < lowerBB[1] and close > open and close < lowerBB
// === CONFIRMATION INDICATORS ===
rsi = ta.rsi(close, 14)
atr = ta.atr(14)
ema200 = ta.ema(close, 200)
// === AI SIGNAL GENERATION ===
longCondition = (priceCrossLower or wickReversalLower) and
rsi < 45 and
close > ema200 and
(autoOptimize ? array.size(winRates) == 0 or array.avg(winRates) > 0.5 : true)
shortCondition = (priceCrossUpper or wickReversalUpper) and rsi > 55 and close < ema200 and (autoOptimize ? array.size(winRates) == 0 or array.avg(winRates) > 0.5 : true)
// === AI RISK MANAGEMENT ===
baseStop = atr * (autoOptimize ? 1.8 - (array.avg(winRates)/10) : 1.5)
dynamicRR = autoOptimize ? 3.0 + (array.avg(rewardRatios)/2) : 2.5
longStop = close - baseStop
shortStop = close + baseStop
longTP = close + (baseStop * dynamicRR)
shortTP = close - (baseStop * dynamicRR)
// === STRATEGY EXECUTION ===
if (longCondition)
strategy.entry("AI BB Long", strategy.long)
strategy.exit("AI Long Exit", "AI BB Long", stop=longStop, limit=longTP, qty_percent=100)
if (shortCondition)
strategy.entry("AI BB Short", strategy.short)
strategy.exit("AI Short Exit", "AI BB Short", stop=shortStop, limit=shortTP, qty_percent=100) // === AI LEARNING ALGORITHM === if (strategy.closedtrades > 0) astTrade = strategy.closedtrades - 1 isWin = strategy.closedtrades.profit(lastTrade) > 0 rrRatio = math.abs(strategy.closedtrades.max_runup(lastTrade)/strategy.closedtrades.max_drawdown(lastTrade)) array.push(winRates, isWin ? 1.0 : 0.0) array.push(rewardRatios, rrRatio) learningCycle := learningCycle + 1 // Adative Optimization if (learningCycle % 5 == 0 and autoOptimize) currentWinRate = array.avg(winRates) if (currentWinRate < 0.6) bbMult := bbMult * 0.98 bbLength := int(bbLength * 1.02) else bbMult := bbMult * 1.02 bbLength := int(bbLength * 0.98)// === VISUAL INTELLIGENCE === // BB Plots plot(basis, "Basis", color=color.blue) plot(upperBB, "Upper", color=color.red) plot(lowerBB, "Lower", color=color.green) // Reversal Signals plotshape(longCondition, "AI Long", shape.labelup, location.belowbar, color=color.new(#00FF00, 0), text="AI BUY", textcolor=color.black, size=size.large) plotshape(shortCondition, "AI Short", shape.labeldown, location.abovebar, color=color.new(#FF0000, 0), text="AI SELL", textcolor=color.black, size=size.large) // Performance Dashboard var table perfTable = table.new(position.top_right, 3, 6) if (barstate.islast) table.cell(perfTable, 0, 0, "AI Performance", bgcolor=color.gray) table.cell(perfTable, 0, 1, "Win Rate:", bgcolor=color.gray) table.cell(perfTable, 1, 1, str.tostring(array.avg(winRates)*100, "#.##")+"%") table.cell(perfTable, 0, 2, "Avg RR:", bgcolor=color.gray) table.cell(perfTable, 1, 2, str.tostring(array.avg(rewardRatios), "#.##")+"R") table.cell(perfTable, 0, 3, "BB Length:", bgcolor=color.gray) table.cell(perfTable, 1, 3, str.tostring(bbLength)) table.cell(perfTable, 0, 4, "BB Mult:", bgcolor=color.gray) table.cell(perfTable, 1, 4, str.tostring(bbMult, "#.##"))"""
//@version=6
strategy("Ultimate Trading System", overlay=true,
initial_capital=100000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
commission_type=strategy.commission.percent,
commission_value=0.1,
pyramiding=0)
// === INPUTS ===
// Trend Filters
emaShort = input(9, "Fast EMA")
emaMedium = input(21, "Medium EMA")
emaLong = input(50, "Slow EMA")
ema200 = input(200, "200 EMA")
// Profit Targets
riskReward = input.float(2.5, "Risk/Reward Ratio", minval=1.0, step=0.1)
profitTargetPct = input.float(25, "Partial Profit %", minval=1, maxval=100)/100
// Risk Management
atrLength = input(14, "ATR Length")
slMultiplier = input.float(1.5, "SL ATR Multiplier", minval=0.5, step=0.1)
// Bollinger Bands
bbLength = input(20, "BB Length")
bbStdDev = input.float(2.0, "BB StdDev")
// RSI
rsiLength = input(14, "RSI Length")
rsiOverbought = input(70, "RSI Overbought")
rsiOversold = input(30, "RSI Oversold")
// === CALCULATIONS ===
// EMA Ribbon
ema1 = ta.ema(close, emaShort)
ema2 = ta.ema(close, emaMedium)
ema3 = ta.ema(close, emaLong)
ema200Val = ta.ema(close, ema200)
// Bollinger Bands
basis = ta.sma(close, bbLength)
dev = bbStdDev * ta.stdev(close, bbLength)
upperBB = basis + dev
lowerBB = basis - dev
// RSI
rsi = ta.rsi(close, rsiLength)
rsiBullish = rsi > 50 and rsi[1] <= 50
rsiBearish = rsi < 50 and rsi[1] >= 50
// ATR for Stops
atr = ta.atr(atrLength)
// === TRADE CONDITIONS ===
// Long Conditions (Above 200EMA)
bbLongSignal = close[1] < lowerBB[1] and close > upperBB
emaRibbonLong = ema1 > ema2 and ema2 > ema3
longEntry = close > ema200Val and bbLongSignal and emaRibbonLong and rsiBullish
// Short Conditions (Below 200EMA)
bbShortSignal = close[1] > upperBB[1] and close < lowerBB
emaRibbonShort = ema1 < ema2 and ema2 < ema3
shortEntry = close < ema200Val and bbShortSignal and emaRibbonShort and rsiBearish
// === RISK MANAGEMENT ===
// Stop Loss Calculations
longStop = close - (atr * slMultiplier)
shortStop = close + (atr * slMultiplier)
// Take Profit Calculations
longTP = close + ((close - longStop) * riskReward)
shortTP = close - ((shortStop - close) * riskReward)
// Breakeven Price
longBEPrice = strategy.position_avg_price * (1 + profitTargetPct)
shortBEPrice = strategy.position_avg_price * (1 - profitTargetPct)
// === STRATEGY EXECUTION ===
// Long Trade
if (longEntry)
strategy.entry("Long", strategy.long)
strategy.exit("Long TP/SL", "Long", stop=longStop, limit=longTP)
// Move to Breakeven
if (strategy.position_size > 0 and close >= longBEPrice)
strategy.exit("Long BE", "Long", stop=strategy.position_avg_price)
// Short Trade
if (shortEntry)
strategy.entry("Short", strategy.short)
strategy.exit("Short TP/SL", "Short", stop=shortStop, limit=shortTP)
// Move to Breakeven
if (strategy.position_size < 0 and close <= shortBEPrice)
strategy.exit("Short BE", "Short", stop=strategy.position_avg_price)
// === PLOTS ===
// EMA Ribbon
plot(ema1, "Fast EMA", color=color.blue)
plot(ema2, "Medium EMA", color=color.orange)
plot(ema3, "Slow EMA", color=color.red)
plot(ema200Val, "200 EMA", color=color.black, linewidth=2)
// Bollinger Bands
plot(basis, "BB Basis", color=color.purple)
plot(upperBB, "Upper BB", color=color.green)
plot(lowerBB, "Lower BB", color=color.red)
// Breakeven Marker
plot(strategy.position_avg_price, "Breakeven", style=plot.style_circles, color=color.white, linewidth=2)
// === VISUAL SIGNALS ===
// Entry Signals
plotshape(longEntry, "Buy Signal", shape.triangleup, location.belowbar, color=color.green, size=size.large)
plotshape(shortEntry, "Sell Signal", shape.triangledown, location.abovebar, color=color.red, size=size.large)
// RSI Signals
plotshape(rsiBullish and longEntry, "RSI Bullish", shape.labelup, location.belowbar, color=color.lime, text="RSI BULL")
plotshape(rsiBearish and shortEntry, "RSI Bearish", shape.labeldown, location.abovebar, color=color.fuchsia, text="RSI BEAR")
Gekko Ai Indicator (FREE):
//@version=6
strategy("BB Reversal Strategy - Verified", overlay=true,
initial_capital=100000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
commission_type=strategy.commission.percent,
commission_value=0.1)
// === INPUTS ===
// Bollinger Bands input.int(2, minval=1)
bbMult = input.float(2.0, "BB StdDev", minval=0.1, step=0.1)
// RSI
rsiLength = input.int(14, "RSI Length", minval=1)
rsiOverbought = input.int(70, "RSI Overbought", minval=50, maxval=100)
rsiOversold = input.int(30, "RSI Oversold", minval=0, maxval=50)
// ATR
atrLength = input.int(14, "ATR Length", minval=1)
slMult = input.float(1.5, "SL Multiplier", minval=0.1)
tpMult = input.float(2.5, "TP Multiplier", minval=0.1)
// Volume
volMult = input.float(1.5, "Volume Multiplier", minval=1)
// Trend EMAs
emaFast = input.int(50, "Fast EMA", minval=1)
emaSlow = input.int(200, "Slow EMA", minval=1)
// === CALCULATIONS ===
// Bollinger Bands
basis = ta.sma(close, bbLength)
dev = bbMult * ta.stdev(close, bbLength)
upper = basis + dev
lower = basis - dev
// RSI
rsi = ta.rsi(close, rsiLength)
// ATR
atr = ta.atr(atrLength)
// Volume
volMa = ta.sma(volume, 20)
volFilter = volume > (volMa * volMult)
// Trend
fastMa = ta.ema(close, emaFast)
slowMa = ta.ema(close, emaSlow)
trendUp = fastMa > slowMa
// === CONDITIONS ===
// Entry
wasBelow = (low[1] < lower[1]) and (close[1] < lower[1])
closesAbove = close > upper
rsiRising = rsi[1] < rsiOversold and rsi > rsiOversold
entryCond = wasBelow and closesAbove and rsiRising and volFilter and trendUp
// Exit
exitCond = close < basis
// === STRATEGY EXECUTION ===
if entryCond
strategy.entry("BB Long", strategy.long)
strategy.exit("Exit", "BB Long",
stop=close - (atr * slMult),
limit=close + (atr * tpMult))
if exitCond
strategy.close("BB Long")
// === PLOTTING ===
plot(basis, "Basis", color=color.blue)
plot(upper, "Upper", color=color.red)
plot(lower, "Lower", color=color.green)
plot(fastMa, "Fast MA", color=color.orange)
plot(slowMa, "Slow MA", color=color.purple)
// Entry/Exit markers
plotshape(entryCond, "Entry", shape.triangleup, location.belowbar, color=color.green, size=size.small)
plotshape(exitCond, "Exit", shape.triangledown, location.abovebar, color=color.red, size=size.small)