Ai algoGoldOANDA:XAUUSDGefrii//@version=5 // VERSION = 'v1'// 2025.04.17 strategy( 'AI ALGO ', shorttitle = 'AI ALGO ' + VERSION, overlay = true, explicit_plot_zorder = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 50, calc_on_every_tick = false, process_orders_on_close = true, max_bars_back = 500, initial_capital = 5000, commission_type = strategy.commission.percent, commission_value = 0.02 ) // Support and Resistances ShowSmartTrail = input.bool(true, 'Smart Trail ', inline = 'overlayLine1', group = 'Smart Trail') enableSR = input(false, "SR On/Off", group="🧊 Support and Resistances") colorSup = input(color.new(#00DBFF,20), "Support Color", group="Support and Resistances") colorRes = input(color.new(#9598a1,50), "Resistance Color", group="Support and Resistances") strengthSR = input.int(2, "S/R Strength", 1, group="Support and Resistances") lineStyle = input.string("Dotted", "Line Style", , group="Support and Resistances") lineWidth = input.int(1, "S/R Line Width", 1, group="Support and Resistances") useZones = input(true, "Zones On/Off", group="Support and Resistances") useHLZones = input(true, "High Low Zones On/Off", group="Support and ResistancesSR") zoneWidth = input.int(2, "Zone Width %", 0, tooltip="it's calculated using % of the distance between highest/lowest in last 300 bars", group="Support and Resistances") expandSR = input(true, "Expand Support and Resistances") /////////////////////////////// S/R ////////////////////////////////////////// trailType = input.string('modified', 'Trailtype', options=, group = "S/R") ATRPeriod = input(200, 'ATR Period') ATRFactor = input.float(4.2, 'ATR Factor', minval = 2, maxval = 26,step=0.1,tooltip = "Changes the sensetivity of the signals.") Smoothing = input(4, 'Smoothing') /////////////////////////////////// norm_o = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, open) norm_h = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, high) norm_l = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, low) norm_c = request.security(ticker.new(syminfo.prefix, syminfo.ticker), timeframe.period, close) //} //////// FUNCTIONS ////////////// //{ // Wilders ma // Wild_ma(_src, _malength) => _wild = 0.0 _wild := nz(_wild) + (_src - nz(_wild)) / _malength _wild /////////// TRUE RANGE CALCULATIONS ///////////////// HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod))) HRef = norm_l = norm_l ? norm_c - norm_l : norm_c - norm_l - 0.5 * (norm_l - norm_h) trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) : math.max(norm_h - norm_l, math.abs(norm_h - norm_c), math.abs(norm_l - norm_c)) //} /////////// TRADE LOGIC //////////////////////// //{ loss = ATRFactor * Wild_ma(trueRange, ATRPeriod) Up68 = norm_c - loss Dn68 = norm_c + loss TrendUp = Up68 TrendDown = Dn68 Trend = 1 TrendUp := norm_c > TrendUp ? math.max(Up68, TrendUp) : Up68 TrendDown := norm_c < TrendDown ? math.min(Dn68, TrendDown) : Dn68 Trend := norm_c > TrendDown ? 1 : norm_c < TrendUp ? -1 : nz(Trend, 1) trail = Trend == 1 ? TrendUp : TrendDown ex = 0.0 ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend == 1 ? math.max(ex, norm_h) : Trend == -1 ? math.min(ex, norm_l) : ex