Haizan12
@t_Haizan12
تریدر چه نمادی را توصیه به خرید کرده؟
سابقه خرید
تخمین بازدهی ماه به ماه تریدر
پیام های تریدر
فیلتر
نوع پیام

// version =5 strategy("Risk-Managed EMA+MACD+RSI - TP 10% / SL 2% (configurable)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1, // will be overridden by calculated qty_percent commission_type=strategy.commission.percent, commission_value=0.04, // default commission (percent) — change to your broker slippage=0) // ========================== // === User inputs // ========================== tpPercent = input.float(10.0, "Take Profit (%)", step=0.1) stopPercent = input.float(2.0, "Stop Loss (%)", step=0.1) riskPerTradePct = input.float(2.0, "Risk per Trade (% of Equity)", step=0.1) maxPositionPct = input.float(100.0, "Max allowed position (% of equity)", step=1.0) fastEMAlen = input.int(20, "Fast EMA length") slowEMAlen = input.int(50, "Slow EMA length") macdFast = input.int(12, "MACD Fast") macdSlow = input.int(26, "MACD Slow") macdSig = input.int(9, "MACD Signal") rsiLen = input.int(14, "RSI length") rsiThreshold = input.float(50.0, "RSI threshold (filter)") useVolumeFilter = input.bool(true, "Use volume confirmation (above SMA)") volSmaLen = input.int(20, "Volume SMA length") // Optional: minimum equity to trade (prevents tiny buys) minEquityToTrade = input.float(50.0, "Minimum equity to trade (USD)", step=1) // ========================== // === Indicators & Filters // ========================== price = close fastEMA = ta.ema(price, fastEMAlen) slowEMA = ta.ema(price, slowEMAlen) [macdLine, macdSignal, macdHist] = ta.macd(price, macdFast, macdSlow, macdSig) rsi = ta.rsi(price, rsiLen) volSMA = ta.sma(volume, volSmaLen) volOK = not useVolumeFilter or (volume > volSMA) // Trend filter: only take longs when fastEMA above slowEMA (and inverse for shorts) bullTrend = fastEMA > slowEMA bearTrend = fastEMA < slowEMA // Entry signals (conservative — requires multiple confirmations) longSignal = bullTrend and ta.crossover(macdHist, 0) and rsi > rsiThreshold and volOK shortSignal = bearTrend and ta.crossunder(macdHist, 0) and rsi < (100 - rsiThreshold) and volOK // ========================== // === Position sizing (qty_percent) // ========================== // If stopPercent is 0 or nearly 0, avoid division by zero stopPctSafe = math.max(stopPercent, 0.0001) // Position value as percent of equity required so that risking 'riskPerTradePct' with a stop of 'stopPercent' // Formula derived: position_value = equity * (risk% / stop%) -> position_value_pct = (risk%/stop%) * 100 rawPosValuePct = (riskPerTradePct / stopPctSafe) * 100.0 // Cap to user-specified maximum and to 100% (can't allocate more than 100% of equity unless you want leverage) posValuePctCapped = math.min(rawPosValuePct, math.min(maxPositionPct, 100.0)) // If account equity is below minimum, set size to zero qtyPercentToUse = strategy.equity >= minEquityToTrade ? posValuePctCapped : 0.0 // Safety: If computed qty percent is 0, we won't enter trades // (Note: strategy.entry accepts qty_percent parameter in v5) // ========================== // === Order execution // ========================== longId = "Long" shortId = "Short" // When we enter, we immediately place an exit order attached to the entry with stop and limit prices if (longSignal and qtyPercentToUse > 0) // compute stop and take-profit in price space based on current close (entry will use market price) stopPriceLong = price * (1 - stopPercent / 100) limitPriceLong = price * (1 + tpPercent / 100) // submit entry using qty_percent strategy.entry(id=longId, direction=strategy.long, qty_percent=qtyPercentToUse, comment="EMA+MACD+RSI Long") // attach exit to the named entry strategy.exit("Exit Long", from_entry=longId, stop=stopPriceLong, limit=limitPriceLong) if (shortSignal and qtyPercentToUse > 0) stopPriceShort = price * (1 + stopPercent / 100) limitPriceShort = price * (1 - tpPercent / 100) strategy.entry(id=shortId, direction=strategy.short, qty_percent=qtyPercentToUse, comment="EMA+MACD+RSI Short") strategy.exit("Exit Short", from_entry=shortId, stop=stopPriceShort, limit=limitPriceShort) // Optional: ensure exits exist if user disables new entries. // (This handles multi-bar fills: when an entry actually fills, the attached exit will apply) // ========================== // === Plotting & labels // ========================== plot(fastEMA, color=color.new(color.green, 0), title="Fast EMA") plot(slowEMA, color=color.new(color.red, 0), title="Slow EMA") hline(50, "RSI 50", color=color.gray) plot(rsi, title="RSI", color=color.blue, linewidth=1, transp=60, display=display.none) // hidden by default // Show last trade info on chart var label lastTradeLbl = na if (barstate.islast) label.delete(lastTradeLbl) lastTradeLbl := label.new(x=bar_index, y=high, text = "TP: " + str.tostring(tpPercent, "#.##") + "% SL: " + str.tostring(stopPercent, "#.##") + "%\n" + "Risk/trade: " + str.tostring(riskPerTradePct, "#.##") + "%\n" + "Qty% used: " + str.tostring(qtyPercentToUse, "#.##") + "%", style=label.style_label_right, color=color.new(color.black, 80), textcolor=color.white, size=size.small) // Plot buy/sell signals visually plotshape(longSignal, title="Long Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small, text="Long") plotshape(shortSignal, title="Short Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small, text="Short") // ========================== // === Notes // ========================== // - Position sizing uses percent-of-equity logic: position_value_pct = (risk% / stop%) * 100 // Example: riskPerTradePct=2 and stopPercent=2 -> position_value_pct = 100% (full equity). // - If you want to allow leverage >1, increase `maxPositionPct` > 100. BE CAREFUL. // - Commission and slippage are configurable at the top of this script. // - You can change entry filters (EMA lengths, RSI threshold, remove volume filter) to suit your asset/timeframe. // - Backtest thoroughly across different symbols and timeframes before using live. // ==========================
سلب مسئولیت
هر محتوا و مطالب مندرج در سایت و کانالهای رسمی ارتباطی سهمتو، جمعبندی نظرات و تحلیلهای شخصی و غیر تعهد آور بوده و هیچگونه توصیهای مبنی بر خرید، فروش، ورود و یا خروج از بازارهای مالی نمی باشد. همچنین کلیه اخبار و تحلیلهای مندرج در سایت و کانالها، صرفا بازنشر اطلاعات از منابع رسمی و غیر رسمی داخلی و خارجی است و بدیهی است استفاده کنندگان محتوای مذکور، مسئول پیگیری و حصول اطمینان از اصالت و درستی مطالب هستند. از این رو ضمن سلب مسئولیت اعلام میدارد مسئولیت هرنوع تصمیم گیری و اقدام و سود و زیان احتمالی در بازار سرمایه و ارز دیجیتال، با شخص معامله گر است.