//@version=5 strategy("LabotKripto Free Trend Helper Strategy v2", overlay=true, initial_capital=1000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, pyramiding=0, process_orders_on_close=true) // ---------------------------------------------------- // LabotKripto Free Pine Pack - Strategy / Backtest v2 // Oktatási és historikus tesztelési célú példa. // Nem minősül pénzügyi, befektetési vagy kereskedési tanácsadásnak. // A múltbeli teljesítmény nem garancia a jövőbeli eredményre. // ---------------------------------------------------- // Inputs fastEmaLength = input.int(21, "Gyors EMA", minval=1) slowEmaLength = input.int(50, "Lassú EMA", minval=1) trendEmaLength = input.int(200, "Trend EMA", minval=1) rsiLength = input.int(14, "RSI hossz", minval=1) rsiEntryLevel = input.int(50, "Long RSI belépési szint", minval=1, maxval=99) rsiExitLevel = input.int(45, "RSI kilépési szint", minval=1, maxval=99) minEmaDistancePercent = input.float(0.15, "Min. EMA távolság %", minval=0.0, step=0.05) useAtrStop = input.bool(true, "ATR stop használata") atrLength = input.int(14, "ATR hossz", minval=1) atrMultiplier = input.float(2.5, "ATR stop szorzó", minval=0.1, step=0.1) useTakeProfit = input.bool(false, "Take profit használata") takeProfitPercent = input.float(8.0, "Take profit %", minval=0.1, step=0.1) useDateFilter = input.bool(false, "Dátumszűrő használata") startTime = input.time(timestamp("2024-01-01T00:00:00"), "Backtest kezdete") endTime = input.time(timestamp("2026-12-31T23:59:59"), "Backtest vége") // Calculations fastEma = ta.ema(close, fastEmaLength) slowEma = ta.ema(close, slowEmaLength) trendEma = ta.ema(close, trendEmaLength) rsi = ta.rsi(close, rsiLength) atr = ta.atr(atrLength) inDateRange = not useDateFilter or (time >= startTime and time <= endTime) emaDistancePercent = math.abs(fastEma - slowEma) / close * 100 majorTrendUp = close > trendEma minorTrendUp = fastEma > slowEma enoughTrendDistance = emaDistancePercent >= minEmaDistancePercent rsiReclaim = ta.crossover(rsi, rsiEntryLevel) longEntry = inDateRange and majorTrendUp and minorTrendUp and enoughTrendDistance and rsiReclaim longExitByTrend = ta.crossunder(fastEma, slowEma) longExitByRsi = ta.crossunder(rsi, rsiExitLevel) longExit = longExitByTrend or longExitByRsi // Entry if longEntry and strategy.position_size <= 0 strategy.entry("Long", strategy.long) // Exit by signal if longExit and strategy.position_size > 0 strategy.close("Long") // ATR stop / Take profit if strategy.position_size > 0 longAtrStop = strategy.position_avg_price - atr * atrMultiplier longTakeProfit = strategy.position_avg_price * (1 + takeProfitPercent / 100) if useAtrStop and useTakeProfit strategy.exit("Long ATR/TP", "Long", stop=longAtrStop, limit=longTakeProfit) else if useAtrStop strategy.exit("Long ATR Stop", "Long", stop=longAtrStop) else if useTakeProfit strategy.exit("Long TP", "Long", limit=longTakeProfit) // Plots plot(fastEma, title="Gyors EMA", linewidth=2) plot(slowEma, title="Lassú EMA", linewidth=2) plot(trendEma, title="Trend EMA 200", linewidth=2) bgcolor(majorTrendUp and minorTrendUp ? color.new(color.green, 92) : na, title="Long trend háttér") bgcolor(not majorTrendUp ? color.new(color.red, 94) : na, title="Trend EMA alatti háttér") plotshape(longEntry, title="Long belépő", style=shape.triangleup, location=location.belowbar, size=size.small, text="LONG") plotshape(longExit and strategy.position_size > 0, title="Long kilépő", style=shape.triangledown, location=location.abovebar, size=size.small, text="EXIT") // Status table var table statusTable = table.new(position.top_right, 2, 6, border_width=1) if barstate.islast table.cell(statusTable, 0, 0, "Fő trend") table.cell(statusTable, 1, 0, majorTrendUp ? "EMA200 felett" : "EMA200 alatt") table.cell(statusTable, 0, 1, "EMA21/50") table.cell(statusTable, 1, 1, minorTrendUp ? "Bullish" : "Bearish") table.cell(statusTable, 0, 2, "EMA távolság") table.cell(statusTable, 1, 2, str.tostring(emaDistancePercent, "#.##") + "%") table.cell(statusTable, 0, 3, "RSI") table.cell(statusTable, 1, 3, str.tostring(rsi, "#.##")) table.cell(statusTable, 0, 4, "Pozíció") table.cell(statusTable, 1, 4, strategy.position_size > 0 ? "Long" : "Nincs") table.cell(statusTable, 0, 5, "Idősík") table.cell(statusTable, 1, 5, timeframe.period) // Alerts alertcondition(longEntry, title="LabotKripto Strategy v2 Long Entry", message="LabotKripto Strategy v2 Long Entry: {{ticker}} | close={{close}} | timeframe={{interval}}") alertcondition(longExit, title="LabotKripto Strategy v2 Long Exit", message="LabotKripto Strategy v2 Long Exit: {{ticker}} | close={{close}} | timeframe={{interval}}")