OPEN-SOURCE SCRIPT

aurora

43
//version=6
strategy("AURORA PRIME — MAX CAGR v3",
overlay=true,
initial_capital=100000,
pyramiding=2,
process_orders_on_close=true)

//----------------------------------------------------
// INPUTS
//----------------------------------------------------
baseRisk = input.float(0.6, "Base Risk %", step=0.1)
expRisk = input.float(0.9, "Expansion Risk %", step=0.1)
atrLen = input.int(14, "ATR Length")
stopATRmult = input.float(1.5, "Stop ATR Mult")
trailATRmult = input.float(2.0, "Trail ATR Mult")
adxLen = input.int(14, "ADX Length")
adxThresh = input.float(22, "ADX Trend Threshold")
volMult = input.float(1.5, "Volume Expansion Mult")

//----------------------------------------------------
// CORE INDICATORS
//----------------------------------------------------
atr = ta.atr(atrLen)
ema200 = ta.ema(close, 200)
// --- Manual ADX Calculation ---
upMove = high - high[1]
downMove = low[1] - low

plusDM = (upMove > downMove and upMove > 0) ? upMove : 0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0

trur = ta.rma(ta.tr(true), adxLen)

plusDI = 100 * ta.rma(plusDM, adxLen) / trur
minusDI = 100 * ta.rma(minusDM, adxLen) / trur

dx = 100 * math.abs(plusDI - minusDI) / (plusDI + minusDI)
adx = ta.rma(dx, adxLen)

volPower = volume / ta.sma(volume, 20)
volExpansion = volPower > volMult

trendRegime = adx > adxThresh
expansionRegime = trendRegime and volExpansion

// Structure bias (HTF)
htfClose = request.security(syminfo.tickerid, "60", close)
htfEMA = request.security(syminfo.tickerid, "60", ta.ema(close, 50))

bullBias = htfClose > htfEMA
bearBias = htfClose < htfEMA

//----------------------------------------------------
// ENTRY LOGIC
//----------------------------------------------------
longSignal = bullBias and trendRegime and close > ema200
shortSignal = bearBias and trendRegime and close < ema200

//----------------------------------------------------
// RISK ENGINE
//----------------------------------------------------
riskPct = expansionRegime ? expRisk : baseRisk
riskCash = strategy.equity * riskPct * 0.01

stopDist = atr * stopATRmult
qty = stopDist > 0 ? riskCash / stopDist : 0

//----------------------------------------------------
// EXECUTION
//----------------------------------------------------
longSL = close - stopDist
shortSL = close + stopDist

// 2R partial
longTP1 = close + stopDist * 2
shortTP1 = close - stopDist * 2

// ATR trail
trailLong = atr * trailATRmult
trailShort = atr * trailATRmult

if longSignal and strategy.position_size <= 0
strategy.entry("AURORA", strategy.long, qty)
strategy.exit("TP1", "AURORA", qty_percent=50, limit=longTP1)
strategy.exit("Trail", "AURORA", stop=longSL, trail_points=trailLong)

if shortSignal and strategy.position_size >= 0
strategy.entry("AURORA", strategy.short, qty)
strategy.exit("TP1", "AURORA", qty_percent=50, limit=shortTP1)
strategy.exit("Trail", "AURORA", stop=shortSL, trail_points=trailShort)

// Pyramiding logic
inLong = strategy.position_size > 0
inShort = strategy.position_size < 0

entryPrice = strategy.position_avg_price
unrealRLong = inLong ? (close - entryPrice) / stopDist : 0
unrealRShort = inShort ? (entryPrice - close) / stopDist : 0

if inLong and unrealRLong >= 1 and expansionRegime
strategy.entry("AURORA-ADD", strategy.long, qty)

if inShort and unrealRShort >= 1 and expansionRegime
strategy.entry("AURORA-ADD", strategy.short, qty)

plot(ema200, color=color.orange)

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.