//@version=6 strategy("Renko Two Brick Strategy", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1, initial_capital=10000, commission_value=0.05, commission_type=strategy.commission.percent, slippage=1) // ============================================ // تنظیمات پارامترها // ============================================ brickSize = input.float(10.0, "سایز آجر رنکو", step=0.5) riskReward = input.float(3.0, "نسبت ریسک به ریوارد", step=0.5) // ============================================ // محاسبه آجرهای رنکو // ============================================ var float lastBrickClose = na var int brickDirection = 0 var float lastBrickHigh = na var float lastBrickLow = na // مقداردهی اولیه if na(lastBrickClose) lastBrickClose := close lastBrickHigh := high lastBrickLow := low // محاسبه تغییرات قیمت از آخرین آجر priceChange = close - lastBrickClose // تشخیص تشکیل آجر جدید newBrick = false if math.abs(priceChange) >= brickSize newBrick := true // تعیین جهت آجر جدید if priceChange >= brickSize brickDirection := 1 lastBrickHigh := close lastBrickLow := close - brickSize else if priceChange <= -brickSize brickDirection := -1 lastBrickHigh := close + brickSize lastBrickLow := close lastBrickClose := close // ============================================ // تشخیص الگوی دو آجر متوالی همرنگ // ============================================ var int prevDirection1 = 0 var int prevDirection2 = 0 if newBrick prevDirection2 := prevDirection1 prevDirection1 := brickDirection // دو آجر سبز پشت سر هم twoGreenBricks = (prevDirection1 == 1 and prevDirection2 == 1) // دو آجر قرمز پشت سر هم twoRedBricks = (prevDirection1 == -1 and prevDirection2 == -1) // ============================================ // متغیرهای مدیریت سیگنال // ============================================ var float lastEntryPrice = na var int barsSinceLastEntry = 0 barsSinceLastEntry := na(lastEntryPrice) ? 0 : barsSinceLastEntry + 1 // ============================================ // منطق ورود و خروج معاملات // ============================================ // سیگنال خرید if twoGreenBricks and not twoGreenBricks[1] entryPrice = close stopLoss = entryPrice - (brickSize * 2) risk = entryPrice - stopLoss takeProfit = entryPrice + (risk * riskReward) // ثبت سیگنال روی چارت label.new(bar_index, low, "BUY\n" + "Entry: " + str.tostring(entryPrice, "#.##") + "\n" + "SL: " + str.tostring(stopLoss, "#.##") + "\n" + "TP: " + str.tostring(takeProfit, "#.##"), color=color.new(color.green, 0), textcolor=color.white, style=label.style_label_up) // اجرای معامله خرید strategy.entry("Long", strategy.long) strategy.exit("Long TP/SL", "Long", stop=stopLoss, limit=takeProfit) lastEntryPrice := entryPrice barsSinceLastEntry := 0 // سیگنال فروش if twoRedBricks and not twoRedBricks[1] entryPrice = close stopLoss = entryPrice + (brickSize * 2) risk = stopLoss - entryPrice takeProfit = entryPrice - (risk * riskReward) label.new(bar_index, high, "SELL\n" + "Entry: " + str.tostring(entryPrice, "#.##") + "\n" + "SL: " + str.tostring(stopLoss, "#.##") + "\n" + "TP: " + str.tostring(takeProfit, "#.##"), color=color.new(color.red, 0), textcolor=color.white, style=label.style_label_down) strategy.entry("Short", strategy.short) strategy.exit("Short TP/SL", "Short", stop=stopLoss, limit=takeProfit) lastEntryPrice := entryPrice barsSinceLastEntry := 0 // ============================================ // نمایش علامت‌های سیگنال روی چارت // ============================================ plotshape(twoGreenBricks and not twoGreenBricks[1], title="سیگنال خرید", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small) plotshape(twoRedBricks and not twoRedBricks[1], title="سیگنال فروش", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small) // ============================================ // نمایش اطلاعات در جدول // ============================================ var table infoTable = table.new(position.top_right, 3, 4, bgcolor=color.new(color.gray, 90), border_width=1) if barstate.islast table.cell(infoTable, 0, 0, "Parameter", text_color=color.white) table.cell(infoTable, 1, 0, "Value", text_color=color.white) table.cell(infoTable, 0, 1, "Brick Size", text_color=color.white) table.cell(infoTable, 1, 1, str.tostring(brickSize), text_color=color.white) table.cell(infoTable, 0, 2, "Risk:Reward", text_color=color.white) table.cell(infoTable, 1, 2, str.tostring(riskReward), text_color=color.white) table.cell(infoTable, 0, 3, "Net Profit", text_color=color.white) table.cell(infoTable, 1, 3, str.tostring(strategy.netprofit, "#.##"), text_color=strategy.netprofit > 0 ? color.green : color.red) // ============================================ // هشدارها // ============================================ alertcondition(twoGreenBricks and not twoGreenBricks[1], title="🔵 سیگنال خرید", message="خرید: دو آجر سبز پشت سر هم") alertcondition(twoRedBricks and not twoRedBricks[1], title="🔴 سیگنال فروش", message="فروش: دو آجر قرمز پشت سر هم")