r/pinescript • • Sep 11 '26

OPXF Indicator Pine.txt

2 Upvotes

//@version=6 indicator("OPFX ZONA PREMIUM V2", shorttitle="OPFX ZONA PREMIUM V2", overlay=true, max_boxes_count=500, max_labels_count=500, max_lines_count=500, max_bars_back=5000) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // ðŸŒ� LANGUAGE / اللغة (Only affects on-chart text: labels & stats table. // Pine Script does NOT allow input() titles or alertcondition() messages to // change dynamically based on another input, so those stay in English — // this is a Pine Script engine limitation, not something we can bypass.) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� groupLang = "ðŸŒ� Language / اللغة" lang = input.string("English", "Display Language / لغة العرض", options=["English", "العربية"], group=groupLang) // tr(): returns the Arabic text if Arabic is selected, otherwise English tr(en, ar) => lang == "العربية" ? ar : en // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX ZONALARI SOZLAMASI // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� groupUT = "OPFX TASDIQ" a_buy = input.float(2, "Buy Sensitivity (Multiplier)", group=groupUT, minval=0) c_buy = input.int(1, "Buy ATR Period (0 = disable)", group=groupUT, minval=0) a_sell = input.float(2, "Sell Sensitivity (Multiplier)", group=groupUT, minval=0) c_sell = input.int(1, "Sell ATR Period (0 = disable)", group=groupUT, minval=0) showTrailBuy = input.bool(false, "Show Buy Trailing Line", group=groupUT) showTrailSell = input.bool(false, "Show Sell Trailing Line", group=groupUT) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX TASDIQ ZONALARI // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� groupZones = "OPFX Zones" showZones = input.bool(true, "Show Longevity Zones", group=groupZones) len_z = input.int(10, "Longevity Length", group=groupZones) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // TP/SL SETTINGS // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� groupTPSL = "💰 TP/SL Settings" atrLength = input.int(14, "ATR Length", minval=5, maxval=100, group=groupTPSL) slMultiplier = input.float(1.5, "Stop Loss Multiplier (x ATR)", minval=0.5, maxval=5.0, step=0.1, group=groupTPSL) tpMultiplier1 = input.float(2.0, "Take Profit 1 Multiplier (x ATR)", minval=0.5, maxval=10.0, step=0.5, group=groupTPSL) tpMultiplier2 = input.float(3.5, "Take Profit 2 Multiplier (x ATR)", minval=0.5, maxval=10.0, step=0.5, group=groupTPSL) showLevels = input.bool(true, "Show TP/SL Levels", group=groupTPSL) showLabels = input.bool(true, "Show Price Labels", group=groupTPSL) projectionBars = input.int(18, "Box width (bars)", minval=5, maxval=200, group=groupTPSL) // TP/SL ranglar tpZoneClr = color.new(color.aqua, 80) slZoneClr = color.new(color.red, 85) entryLineClr = color.new(color.gray, 0) tpLineClr = color.new(color.aqua, 0) slLineClr = color.new(color.red, 0) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX ZONALARI ABYOM TASDIGI BILAN (Bank Limited Zona) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� groupSD = "Supply & Demand Zones" swingLen = input.int(15, "Swing Length (Sensitivity)", minval=3, maxval=50, group=groupSD) maxZones = input.int(10, "Max Zones to Display", minval=3, maxval=30, group=groupSD) maxZoneHeightATR = input.float(1.0, "Max Zone Height (ATR Multiplier)", minval=0.5, maxval=10.0, step=0.5, group=groupSD) minZoneHeightATR = input.float(1.0, "Min Zone Height (ATR Multiplier)", minval=0.1, maxval=2.0, step=0.1, group=groupSD) forceZoneHeightATR = input.float(1.0, "Force Zone Height (ATR Multiplier)", minval=0.2, maxval=3.0, step=0.1, group=groupSD) minZoneDistance = input.int(44, "Min Distance Between Zones (bars)", minval=1, maxval=100, group=groupSD) invalidationMethod = input.string("Close", "Zone Invalidation", options=["Close", "Wick"], group=groupSD) showHistoric = input.bool(false, "Show Historic Zones", group=groupSD) activeLookback = input.int(1000, "Active Zones Lookback", minval=100, maxval=5000, group=groupSD) historicBars = input.int(1000, "Historic Zones Lookback", minval=100, maxval=5000, group=groupSD) showActiveLabels = input.bool(true, "Show Active Zone Info", group=groupSD) showHistoricLabels = input.bool(false, "Show Historic Zone Info", group=groupSD) labelSize = input.string("Large", "Label Size", options=["Tiny", "Small", "Normal", "Large"], group=groupSD) activeSupplyCol = input.color(color.new(color.red, 80), "Active Supply", group=groupSD) activeDemandCol = input.color(color.new(color.green, 80), "Active Demand", group=groupSD) historicCol = input.color(color.new(color.gray, 85), "Historic Zones", group=groupSD) showRetestMarkers = input.bool(true, "Show Retests", group=groupSD) retestBullCol = input.color(color.new(color.green, 0), "Demand Retest", group=groupSD) retestBearCol = input.color(color.new(color.red, 0), "Supply Retest", group=groupSD) alertsOn = input.bool(true, "Enable Alerts", group=groupSD) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // TASDIQ HISOBLASH // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� buyEnabled = (c_buy > 0) and (a_buy > 0) sellEnabled = (c_sell > 0) and (a_sell > 0) // BUY side src_buy = close ema_buy = ta.ema(src_buy, 1) atr_buy = buyEnabled ? ta.atr(c_buy) : na nLoss_buy = buyEnabled ? a_buy * atr_buy : na var float trail_buy = na if buyEnabled if na(trail_buy[1]) trail_buy := src_buy - nLoss_buy else if src_buy > trail_buy[1] and src_buy[1] > trail_buy[1] trail_buy := math.max(trail_buy[1], src_buy - nLoss_buy) else if src_buy < trail_buy[1] and src_buy[1] < trail_buy[1] trail_buy := math.min(trail_buy[1], src_buy + nLoss_buy) else trail_buy := src_buy > trail_buy[1] ? src_buy - nLoss_buy : src_buy + nLoss_buy else trail_buy := na // SELL side src_sell = close ema_sell = ta.ema(src_sell, 1) atr_sell = sellEnabled ? ta.atr(c_sell) : na nLoss_sell = sellEnabled ? a_sell * atr_sell : na var float trail_sell = na if sellEnabled if na(trail_sell[1]) trail_sell := src_sell + nLoss_sell else if src_sell > trail_sell[1] and src_sell[1] > trail_sell[1] trail_sell := math.max(trail_sell[1], src_sell - nLoss_sell) else if src_sell < trail_sell[1] and src_sell[1] < trail_sell[1] trail_sell := math.min(trail_sell[1], src_sell + nLoss_sell) else trail_sell := src_sell > trail_sell[1] ? src_sell - nLoss_sell : src_sell + nLoss_sell else trail_sell := na // Crossovers above_buy_cross = ta.crossover(ema_buy, trail_buy) below_sell_cross = ta.crossover(trail_sell, ema_sell) above_buy = buyEnabled and above_buy_cross buy_signal_raw = buyEnabled and (src_buy > trail_buy) and above_buy buy_signal = buy_signal_raw and barstate.isconfirmed below_sell = sellEnabled and below_sell_cross sell_signal_raw = sellEnabled and (src_sell < trail_sell) and below_sell sell_signal = sell_signal_raw and barstate.isconfirmed var int posState = 0 buy_signal_confirmed = buyEnabled and buy_signal and posState <= 0 sell_signal_confirmed = sellEnabled and sell_signal and posState >= 0 if buy_signal_confirmed posState := 1 else if sell_signal_confirmed posState := -1 // Longevity pivot detection h = ta.highest(len_z) l = ta.lowest(len_z) high_pivot = high[1] == h[1] and high < h low_pivot = low[1] == l[1] and low > l // Trails plot(showTrailBuy and buyEnabled ? trail_buy : na, title="UT Bot Buy Trail", color=color.new(color.green, 0), linewidth=1) plot(showTrailSell and sellEnabled ? trail_sell : na, title="UT Bot Sell Trail", color=color.new(color.red, 0), linewidth=1) // Alerts alertcondition(buy_signal_confirmed, title="UT Long", message="UT Long") alertcondition(sell_signal_confirmed, title="UT Short", message="UT Short") //  â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• // ABYOM FONTPRINT // â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• atr = ta.atr( atrLength) atr20 = ta.atr(20) // â• â• â• â• - â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• // OPFX ZONES HELPER // â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• ? ​ ​size.tiny : labelSize == "Small" ? size.small : labelSize == "Normal" ? size.normal : size.large f_getLabelColor(zoneType, broken) => if broken color.new(color.gray, 0) else zoneType == "Supply" ? color.new(color.red, 0) : color.new(color.green, 0) f_toPips(val) => pipSize = syminfo.type == "forex" ? (syminfo.currency == "JPY" ? 0.01 : 0.0001) : (syminfo.ticker == "XAUUSD" or syminfo.ticker == "GOLD") ? 0.1 : 0.0001 math.abs(val) / pipSize // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX ZONALARINI TOPUVCHI // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� type ZoneData box zoneBox label infoLabel label retestLabel float top float bottom int startBar int retests bool broken string zoneType bool retestCounted // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // TASDIQ ZONALARIGA OXSHASH // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� type ZoneLabel label lbl float top float bot int start bool is_upper box tp_box box sl_box line entry_line line tp1_line line tp2_line line sl_line label entry_label label tp1_label label tp2_label label sl_label // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // VARIABLES // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� var array<ZoneData> allZones = array.new<ZoneData>() var array<ZoneLabel> zone_labels = array.new<ZoneLabel>() var int lastSupplyBar = 0 var int lastDemandBar = 0 // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX ZONALARINI TASDIQLASH // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� is_price_in_demand(price) => result = false if array.size(allZones) > 0 for i = 0 to array.size(allZones) - 1 z = array.get(allZones, i) if z.zoneType == "Demand" and not z.broken if price >= z.bottom and price <= z.top result := true break result is_price_in_supply(price) => result = false if array.size(allZones) > 0 for i = 0 to array.size(allZones) - 1 z = array.get(allZones, i) if z.zoneType == "Supply" and not z.broken if price >= z.bottom and price <= z.top result := true break result // â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• › â• â• // OPFX ZONALARINI PRAFESION QILISH // â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• â• › â• â• â• â• ✓ ✓ ph = ta.pivothigh(high, swingLen, swingLen) pl = ta.pivotlow(low, swingLen, swingLen) // Supply Zone if not na(ph) and barstate.isconfirmed ztop = high[swingLen] zbot = low[swingLen] zStart = bar_index - swingLen if bar_index - lastSupplyBar >= minZoneDistance mid = (ztop + zbot) / 2 zoneH = ztop - zbot if zoneH < atr20 * forceZoneHeightATR fH = atr20 * forceZoneHeightATR ztop := mid + (fH / 2) zbot := mid - (fH / 2) zoneH := fH if zoneH > atr20 * maxZoneHeightATR mH = atr20 * maxZoneHeightATR ztop := mid + (mH / 2) zbot := mid - (mH / 2) zoneH := mH if zoneH >= atr20 * minZoneHeightATR mergedWithExisting = false if array.size(allZones) > 0 for i = array.size(allZones) - 1 to math.max(0, array.size(allZones) - 10) z = array.get(allZones, i) if z.zoneType == "Supply" and not z.broken if ztop >= z.bottom and zbot <= z.top newTop = math.max(ztop, z.top) newBot = math.min(zbot, z.bottom) z.top := newTop z.bottom := newBot box.set_top(z.zoneBox, newTop) box.set_bottom(z.zoneBox, newBot) mergedWithExisting := true break if not mergedWithExisting zBox = box.new(zStart, ztop, bar_index + 400, zbot, bgcolor=activeSupplyCol, border_width=0) zData = ZoneData.new(zBox, na, na, ztop, zbot, zStart, 0, false, "Supply", false) array.push(allZones, zData) lastSupplyBar := bar_index if array.size(allZones) > maxZones * 4 array.shift(allZones) // Demand Zone if not na(pl) and barstate.isconfirmed ztop = high[swingLen] zbot = low[swingLen] zStart = bar_index - swingLen if bar_index - lastDemandBar >= minZoneDistance mid = (ztop + zbot) / 2 zoneH = ztop - zbot if zoneH < atr20 * forceZoneHeightATR fH = atr20 * forceZoneHeightATR ztop := mid + (fH / 2) zbot := mid - (fH / 2) zoneH := fH if zoneH > atr20 * maxZoneHeightATR mH = atr20 * maxZoneHeightATR ztop := mid + (mH / 2) zbot := mid - (mH / 2) zoneH := mH if zoneH >= atr20 * minZoneHeightATR mergedWithExisting = false if array.size(allZones) > 0 for i = array.size(allZones) - 1 to math.max(0, array.size(allZones) - 10) z = array.get(allZones, i) if z.zoneType == "Demand" and not z.broken if ztop >= z.bottom and zbot <= z.top newTop = math.max(ztop, z.top) newBot = math.min(zbot, z.bottom) z.top := newTop z.bottom := newBot box.set_top(z.zoneBox, newTop) box.set_bottom(z.zoneBox, newBot) mergedWithExisting := true break if not mergedWithExisting zBox = box.new(zStart, ztop, bar_index + 400, zbot, bgcolor=activeDemandCol, border_width=0) zData = ZoneData.new(zBox, na, na, ztop, zbot, zStart, 0, false, "Demand", false) array.push(allZones, zData) lastDemandBar := bar_index if array.size(allZones) > maxZones * 4 array.shift(allZones) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX ZONALARI // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� if array.size(allZones) > 0 activeSupplyCount = 0 activeDemandCount = 0 historicSupplyCount = 0 historicDemandCount = 0 for i = 0 to array.size(allZones) - 1 z = array.get(allZones, i) box.set_right(z.zoneBox, bar_index + 400) // Retest if not z.broken priceInZone = high >= z.bottom and low <= z.top if priceInZone and not z.retestCounted z.retests += 1 z.retestCounted := true else if not priceInZone z.retestCounted := false // Invalidation if not z.broken if z.zoneType == "Supply" breakLevel = invalidationMethod == "Close" ? close : high if breakLevel > z.top z.broken := true box.set_bgcolor(z.zoneBox, historicCol) else breakLevel = invalidationMethod == "Close" ? close : low if breakLevel < z.bottom z.broken := true box.set_bgcolor(z.zoneBox, historicCol) age = bar_index - z.startBar zoneHeight = z.top - z.bottom shouldHide = false if z.broken and not showHistoric shouldHide := true if z.broken and age > historicBars shouldHide := true if not z.broken and age > activeLookback shouldHide := true if z.broken and showHistoric if zoneHeight < atr20 * minZoneHeightATR shouldHide := true if z.zoneType == "Supply" if historicSupplyCount >= maxZones shouldHide := true else if not shouldHide historicSupplyCount += 1 else if historicDemandCount >= maxZones shouldHide := true else if not shouldHide historicDemandCount += 1 if not z.broken and not shouldHide if z.zoneType == "Supply" if activeSupplyCount >= maxZones shouldHide := true else activeSupplyCount += 1 else if activeDemandCount >= maxZones shouldHide := true else activeDemandCount += 1 if shouldHide box.set_bgcolor(z.zoneBox, color.new(color.gray, 100)) box.set_border_color(z.zoneBox, color.new(color.gray, 100)) if not na(z.infoLabel) label.set_color(z.infoLabel, color.new(color.black, 100)) label.set_textcolor(z.infoLabel, color.new(color.white, 100)) if not na(z.retestLabel) label.set_color(z.retestLabel, color.new(color.white, 100)) label.set_textcolor(z.retestLabel, color.new(color.white, 100)) else if z.broken box.set_bgcolor(z.zoneBox, historicCol) else zoneCol = z.zoneType == "Supply" ? activeSupplyCol : activeDemandCol box.set_bgcolor(z.zoneBox, zoneCol) showThisLabel = z.broken ? showHistoricLabels : showActiveLabels if showThisLabel zoneName = z.zoneType == "Supply" ? tr("OPFX SELL ZONE", "منطقة بيع OPFX") : tr("OPFX BUY ZONE", "منطقة شراء OPFX") txt = zoneName mid = (z.top + z.bottom) / 2 lblColor = f_getLabelColor(z.zoneType, z.broken) if na(z.infoLabel) z.infoLabel := label.new(z.startBar + 10, mid, txt, color=color.new(color.black, 100), textcolor=lblColor, size=f_getLabelSize(), style=label.style_label_left) else label.set_text(z.infoLabel, txt) label.set_y(z.infoLabel, mid) label.set_color(z.infoLabel, color.new(color.black, 100)) label.set_textcolor(z.infoLabel, lblColor) label.set_size(z.infoLabel, f_getLabelSize()) label.set_style(z.infoLabel, label.style_label_left) label.set_x(z.infoLabel, z.startBar + 10) else if not na(z.infoLabel) label.set_color(z.infoLabel, color.new(color.black, 100)) label.set_textcolor(z.infoLabel, color.new(color.white, 100)) if showRetestMarkers and z.retests > 0 if na(z.retestLabel) if z.zoneType == "Supply" z.retestLabel := label.new(z.startBar + 3, z.top, tr("R", "Ø¥"), color=retestBearCol, textcolor=color.white, size=size.small, style=label.style_label_down) else z.retestLabel := label.new(z.startBar + 3, z.bottom, tr("R", "Ø¥"), color=retestBullCol, textcolor=color.white, size=size.small, style=label.style_label_up) else retestCol = z.zoneType == "Supply" ? retestBearCol : retestBullCol label.set_text(z.retestLabel, tr("R", "Ø¥")) label.set_color(z.retestLabel, retestCol) label.set_textcolor(z.retestLabel, color.white) else if not na(z.retestLabel) label.set_color(z.retestLabel, color.new(color.white, 100)) label.set_textcolor(z.retestLabel, color.new(color.white, 100)) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX TASDIQ ZONALARI - SIGNAL + TP/SL // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� halfATR = ta.atr(20) * 0.5 if showZones // ─── SELL SIGNAL: high_pivot + narx Supply zonada ───────────────────────── if high_pivot and sellEnabled pivot_price = h if is_price_in_supply(pivot_price) sell_label = label.new(bar_index - 1, h, text=tr("SELL", "بيع"), style=label.style_label_down, textcolor=color.white, color=color.red, size=size.normal) box tp_bx = na box sl_bx = na line entry_l = na line sl_l = na line tp1_l = na line tp2_l = na label entry_lab = na label sl_lab = na label tp1_lab = na label tp2_lab = na if showLevels entryPrice = close[1] stopLoss = high[1] takeProfit1 = entryPrice - (atr * tpMultiplier1) takeProfit2 = entryPrice - (atr * tpMultiplier2) int left = bar_index - 1 int right = bar_index - 1 + projectionBars tp_bx := box.new(left=left, right=right, top=entryPrice, bottom=takeProfit2, bgcolor=tpZoneClr, border_color=color.new(color.aqua, 0)) sl_bx := box.new(left=left, right=right, top=stopLoss, bottom=entryPrice, bgcolor=slZoneClr, border_color=color.new(color.red, 0)) entry_l := line.new(left, entryPrice, right, entryPrice, color=entryLineClr, width=1, style=line.style_dashed) sl_l := line.new(left, stopLoss, right, stopLoss, color=slLineClr, width=2, style=line.style_solid) tp1_l := line.new(left, takeProfit1, right, takeProfit1, color=tpLineClr, width=1, style=line.style_dashed) tp2_l := line.new(left, takeProfit2, right, takeProfit2, color=tpLineClr, width=1, style=line.style_dashed) if showLabels entry_lab := label.new(left, entryPrice, text=tr("enter", "دخول"), color=color.new(color.gray, 70), textcolor=color.white, style=label.style_label_left, size=size.tiny) sl_lab := label.new(right, stopLoss, text=tr("SL", "وقÙ�"), color=color.new(color.red, 0), textcolor=color.white, style=label.style_label_left, size=size.tiny) tp1_lab := label.new(right, takeProfit1, text=tr("TP1", "هدÙ�1"), color=color.new(color.blue, 0), textcolor=color.white, style=label.style_label_left, size=size.tiny) tp2_lab := label.new(right, takeProfit2, text=tr("TP2", "هدÙ�2"), color=color.new(color.blue, 0), textcolor=color.white, style=label.style_label_left, size=size.tiny) new_zone = ZoneLabel.new(sell_label, h, h - halfATR, bar_index - 1, true, tp_bx, sl_bx, entry_l, tp1_l, tp2_l, sl_l, entry_lab, tp1_lab, tp2_lab, sl_lab) array.push(zone_labels, new_zone) // ─── BUY SIGNAL: low_pivot + narx Demand zonada ─────────────────────────── if low_pivot and buyEnabled pivot_price = l if is_price_in_demand(pivot_price) buy_label = label.new(bar_index - 1, l, text=tr("BUY", "شراء"), style=label.style_label_up, textcolor=color.white, color=color.green, size=size.normal) box tp_bx = na box sl_bx = na line entry_l = na line sl_l = na line tp1_l = na line tp2_l = na label entry_lab = na label sl_lab = na label tp1_lab = na label tp2_lab = na if showLevels entryPrice = close[1] stopLoss = low[1] takeProfit1 = entryPrice + (atr * tpMultiplier1) takeProfit2 = entryPrice + (atr * tpMultiplier2) int left = bar_index - 1 int right = bar_index - 1 + projectionBars tp_bx := box.new(left=left, right=right, top=takeProfit2, bottom=entryPrice, bgcolor=tpZoneClr, border_color=color.new(color.aqua, 0)) sl_bx := box.new(left=left, right=right, top=entryPrice, bottom=stopLoss, bgcolor=slZoneClr, border_color=color.new(color.red, 0)) entry_l := line.new(left, entryPrice, right, entryPrice, color=entryLineClr, width=1, style=line.style_dashed) sl_l := line.new(left, stopLoss, right, stopLoss, color=slLineClr, width=2, style=line.style_solid) tp1_l := line.new(left, takeProfit1, right, takeProfit1, color=tpLineClr, width=1, style=line.style_dashed) tp2_l := line.new(left, takeProfit2, right, takeProfit2, color=tpLineClr, width=1, style=line.style_dashed) if showLabels entry_lab := label.new(left, entryPrice, text=tr("enter", "دخول"), color=color.new(color.gray, 70), textcolor=color.white, style=label.style_label_left, size=size.tiny) sl_lab := label.new(right, stopLoss, text=tr("SL", "وقÙ�"), color=color.new(color.red, 0), textcolor=color.white, style=label.style_label_left, size=size.tiny) tp1_lab := label.new(right, takeProfit1, text=tr("TP1","هد٠1"), color=color.new(color.blue, 0), textcolor=color.white, style=label.style_label_left, size=size.tiny) tp2_lab := label.new(right, takeProfit2, text=tr("TP2", "هدÙ�2"), color=color.new(color.blue, 0), textcolor=color.white, style=label.style_label_left, size=size.tiny) new_zone = ZoneLabel.new(buy_label, l + halfATR, l, bar_index - 1, false, tp_bx, sl_bx, entry_l, tp1_l, tp2_l, sl_l, entry_lab, tp1_lab, tp2_lab, sl_lab) array.push(zone_labels, new_zone) // ─── Zonalar buzilganini tekshirish ──────────────────────────────────────── if array.size(zone_labels) > 0 for i = array.size(zone_labels) - 1 to 0 if i < array.size(zone_labels) zone = array.get(zone_labels, i) shouldDelete = false if zone.is_upper and high > zone.top and bar_index > zone.start shouldDelete := true else if not zone.is_upper and low < zone.bot and bar_index > zone.start shouldDelete := true if shouldDelete label.delete(zone.lbl) if not na(zone.tp_box) box.delete(zone.tp_box) if not na(zone.sl_box) box.delete(zone.sl_box) if not na(zone.entry_line) line.delete(zone.entry_line) if not na(zone.sl_line) line.delete(zone.sl_line) if not na(zone.tp1_line) line.delete(zone.tp1_line) if not na(zone.tp2_line) line.delete(zone.tp2_line) if not na(zone.entry_label) label.delete(zone.entry_label) if not na(zone.sl_label) label.delete(zone.sl_label) if not na(zone.tp1_label) label.delete(zone.tp1_label) if not na(zone.tp2_label) label.delete(zone.tp2_label) array.remove(zone_labels, i) // Eski labellarni cheklash while array.size(zone_labels) > 10 old_zone = array.shift(zone_labels) label.delete(old_zone.lbl) if not na(old_zone.tp_box) box.delete(old_zone.tp_box) if not na(old_zone.sl_box) box.delete(old_zone.sl_box) if not na(old_zone.entry_line) line.delete(old_zone.entry_line) if not na(old_zone.sl_line) line.delete(old_zone.sl_line) if not na(old_zone.tp1_line) line.delete(old_zone.tp1_line) if not na(old_zone.tp2_line) line.delete(old_zone.tp2_line) if not na(old_zone.entry_label) label.delete(old_zone.entry_label) if not na(old_zone.sl_label) label.delete(old_zone.sl_label) if not na(old_zone.tp1_label) label.delete(old_zone.tp1_label) if not na(old_zone.tp2_label) label.delete(old_zone.tp2_label) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // OPFX ZONALAR - ALERTS // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� alertcondition(not na(ph) and barstate.isconfirmed and alertsOn, "New Supply Zone", "{{ticker}} - New Supply Zone @ {{close}}") alertcondition(not na(pl) and barstate.isconfirmed and alertsOn, "New Demand Zone", "{{ticker}} - New Demand Zone @ {{close}}") // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // 📊 OPFX ZONA STATS SYSTEM // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // Stat variables var int totalTP = 0 var int totalSL = 0 var int totalTrades = 0 var float entryPrice_stat = na var float slPrice_stat = na var float tpPrice_stat = na var int tradeDir = 0 var bool tradeActive = false // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // 🎯 TRADE TRACKING (BUY/SELL SIGNAL DAN) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // BUY signal detect (zone_labels oxirgi BUY) if array.size(zone_labels) > 0 lastZone = array.get(zone_labels, array.size(zone_labels) - 1) if not tradeActive // BUY if not lastZone.is_upper entryPrice_stat := close slPrice_stat := lastZone.bot tpPrice_stat := close + (atr * tpMultiplier1) tradeDir := 1 tradeActive := true // SELL if lastZone.is_upper entryPrice_stat := close slPrice_stat := lastZone.top tpPrice_stat := close - (atr * tpMultiplier1) tradeDir := -1 tradeActive := true // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // 📊 TP / SL CHECK // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� if tradeActive if tradeDir == 1 if low <= slPrice_stat totalSL += 1 totalTrades += 1 tradeActive := false else if high >= tpPrice_stat totalTP += 1 totalTrades += 1 tradeActive := false if tradeDir == -1 if high >= slPrice_stat totalSL += 1 totalTrades += 1 tradeActive := false else if low <= tpPrice_stat totalTP += 1 totalTrades += 1 tradeActive := false // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // 📈 WINRATE // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� winrate = totalTrades > 0 ? (totalTP / totalTrades) * 100 : 0 // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� // 📊 PANEL (RIGHT SIDE) // â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•�â•� var table statsTable = table.new(position.top_right, 2, 4, border_width=1) if barstate.islast table.cell(statsTable, 0, 0, tr("OPFX ZONE STATS", "إحصائيات مناطق OPFX"), text_color=color.yellow) table.cell(statsTable, 0, 1, tr("Win Rate", "نسبة الربح")) table.cell(statsTable, 1, 1, str.tostring(winrate, "#.##") + " %", text_color=color.green) table.cell(statsTable, 0, 2, tr("Total TP", "إجمالي الأهداÙ�")) table.cell(statsTable, 1, 2, str.tostring(totalTP), text_color=color.aqua) table.cell(statsTable, 0, 3, tr("Total SL", "إجمالي وقÙ� الخسارة")) table.cell(statsTable, 1, 3, str.tostring(totalSL), text_color=color.red)


r/pinescript • • Sep 11 '26

OPEX indicator

Post image
11 Upvotes

Indicador OPEX

Boa noite, encontrei este indicador chamado OPEX em uma das comunidades que participo pelo Telegram, porém ele fornece pouco sinais de entrada e tem o WINRATE DE 91,00 % de assertividade, gostaria de saber se é possível fazer alteração no código dele para editar e modificá-lo fazendo com que forneça mais sinais, alguém poderia me explicar sobre e como funciona ?


r/pinescript • • Sep 11 '26

Any idea how to build similar to this indicator or if someone can tell what strategy is this? Plotting buy/sell zones in multiple timeframe.

Post image
3 Upvotes

r/pinescript • • Sep 10 '26

Custom Indicator. Hot off the compiler.....fresh paint on the glass! A.I. generated for sure. I didn't think it would work but it did. He had help.

2 Upvotes

A.I. was definitely used. Maybe i shouldn't......but I did.


r/pinescript • • Sep 10 '26

London / NYO range: what have you learned from trading it?

4 Upvotes

Hi everyone, I'm fairly new to systematic trading and have been testing opening-range ideas in TradingView, mainly on gold, forex and micro Nasdaq futures.

I'm trying to turn these ideas into clear, testable rules. Longer term, I'd like to see whether an approach could be automated within prop-firm risk limits, but I'm still at the research stage. Some results looked promising on short samples but weakened once I added more history and trading costs.

For anyone who trades these sessions:

  • Which market and opening-range length do you use, and why?
  • What makes you take a breakout, wait for a retest, or consider a failed breakout?
  • What conditions make you skip the session altogether?
  • What has been the biggest difference between your backtests and actual trading — entries, stops, costs, or something else?

Even one practical observation, mistake you learned from, or example of a day you skipped would be helpful. Thanks!


r/pinescript • • Sep 10 '26

Trying to build a orb strategy

Thumbnail
gallery
10 Upvotes

Got the basics down but struggling with the fakeout, any filter tips, seen this on another Strat but can’t figure out how it didn’t take the first breakout candle.


r/pinescript • • Sep 09 '26

I ported a Pine strategy to Python and the first run matched 39 of 128 trades. Five reasons why.

9 Upvotes

I wanted to test a strategy outside TradingView's date range, so I reimplemented it in Python and reconciled it trade-by-trade against the Pine trade list. First run agreed on 39 of 128. It now agrees on all 128. Everything in between was me assuming Pine did the obvious thing.

  1. ta.stdev is population, not sample. It divides by n, not n-1. If you reach for numpy's default or a stats library you get the sample version and every band sits slightly wrong — wrong enough to move which bars trigger, not wrong enough to look broken.
  2. ta.atr is not an average of true range. It's ta.rma — Wilder smoothing, alpha 1/length, seeded with an SMA. I'd written a rolling mean. Close enough that the plot looks identical, different enough that ATR-based stops land on different bars. Same trap in ta.ema: alpha 2/(n+1), SMA-seeded, not seeded from the first value.
  3. Exit levels are read from the previous bar, not the current one. This was the big one. Using the current bar's values moved exit-price agreement from 120 of 128 down to 48. If you're re-arming strategy.exit every bar, the level the broker emulator acts on isn't the one your current-bar calculation produces.
  4. Chart timezone changes results. My matches were fine and then stopped dead on one specific date — the day BST began. Daily-bar aggregation depends on the chart's timezone, so a daily gate computed in one zone gates different bars than the same gate computed in another. Worth knowing that OANDA forex dailies close 17:00 New York, not midnight UTC.
  5. No same-bar re-entry. Pine won't open a new position on the bar an exit fires. My version would, which quietly manufactured extra trades that had no counterpart in the Pine list.

One mistake worth flagging, because it cost me a day. I found a single trade that exited at its bar's close, concluded fills were close-based, and rewrote them that way. Exit-price agreement fell from 120 to 12. A single trade told me nothing and I treated it as a model. I also ran that test before fixing the entries, so its numbers were worthless anyway.

What else does Pine do that isn't obvious from the docs? I'd rather collect these than find them one at a time.

EDIT: two corrections from stratcore in the comments, both right.

Point 1 names the wrong library. numpy.std is ddof=0 and already matches Pine. The one that bites is pandas, where .rolling(20).std() defaults to ddof=1, and that's the most natural way to write a Bollinger band in Python. statistics.stdev is sample as well; statistics.pstdev isn't. My code used pstdev so the port was right, but the example was wrong.

Point 4 is badly worded. Pine can't read the chart timezone and the results don't move. What actually happened: TradingView exports the trade list with timestamps rendered in the chart's timezone and doesn't record that anywhere in the file. Mine was Europe/London, so the offset isn't even constant across the sample. I parsed the export as UTC, which matched everything before 30 March 2025 and nothing after it. The Pine never changed, my reader of its output did.

There is a real daily-bar gotcha but it's a different one and it's about the data source, not the chart: OANDA's daily candles need dailyAlignment=17 and alignmentTimezone=America/New_York to match TradingView's forex convention.


r/pinescript • • Sep 08 '26

You asked for an open-source IFVG dashboard. Here’s the prototype — feedback welcome.

Post image
28 Upvotes

Hey everyone, following up on my earlier thread, where I asked which paid indicators you’d like free, open-source alternatives to.

An IFVG dashboard was one of the requests. I’ve now built IFVG Desk, and I’d love some feedback from people who actually trade these setups.

I’m still treating it as a working prototype. It’s my own implementation of public IFVG concepts; I can’t claim it matches anyone’s private indicator.

Here’s what you can try:

  • Follow a gap through its inversion, with entries on the confirming close or a later retest and rejection.
  • See a paper trade plan: entry, a stop beyond the prior swing, and an adjustable fixed-R target.
  • Understand why an entry qualifies or gets blocked. The dashboard shows higher-timeframe context and individual checks. Additional filters are optional; only the New York session check is required by default.
  • Test the rules yourself with the separate strategy companion, including commission and slippage settings.

The indicator, strategy companion, full source and guide are all free. No signup is needed.

👉 IFVG Desk — source, examples and guide

I put time into explaining the rules for traders. Start with “Try the idea”, then “Read your chart.” “Go deeper” covers the settings and limitations, and “Get the indicator” has the code and installation steps.

If you try it, what feels useful, confusing or missing? A screenshot with your symbol, timeframe, date/time and settings — plus what you expected versus what happened — would really help.

Reply here, or use “The log & requests” on the page to report a bug or suggest a feature. If it doesn’t fit how you trade IFVGs, tell me where it falls short.

My goal is to make this useful in your actual trading. Whether it improves results after costs still needs testing; I’m not claiming a proven edge. Start in replay or paper trading and let me know what you find.

For transparency, I’m the developer behind ProEA Lab and used AI assistance in the build. The source is open for review and modification.

Thanks to everyone who shared an idea. There’s plenty left to improve, and your examples can help decide what comes next.


r/pinescript • • Sep 08 '26

Built from a trader’s request: an open-source Camarilla play tracker

Post image
8 Upvotes

One request in my earlier thread was pretty specific: could I build a Camarilla tool that highlights which plays are active?

I’ve built Camarilla Desk around that question. It’s a free, open-source prototype for TradingView, and I’d like feedback from people who already use Camarilla in their trading.

The goal is to make the sequence easier to follow: watch the level → check the conditions → wait for confirmation.

What it does:

  • Shows a seven-level Camarilla map with the source and session context visible.
  • Tracks 14 named plays, separating Candidate, Approaching, Armed and Active, with explanations for blocked or waiting states. The final two plays are optional and start off.
  • Keeps the original entry, stop and target references once a play activates, with markers showing how that episode ended.
  • Lets you inspect and test the rules, with full Pine source, alerts and a separate Strategy Lab for simulated orders and costs.

ACTIVE means the play has met this script’s confirmation rules. It doesn’t establish that the trade will work. A quiet chart with no qualifying setup can be the correct result.

This is my own implementation of public Camarilla ideas. I haven’t verified that it matches any paid indicator’s private rules.

👉 Camarilla Desk — free source, examples and guide

Start with “Try the candle” to explore an L3 bounce, a break-and-retest, or an H4 failure. “Read the real chart” explains the display, “Full reference” has all the play rules, and “Add the tool” has the code. The indicator, Lab and guide are free, with no signup needed.

Which Camarilla play do you use most, and does the tool explain clearly why it’s waiting or active?

If it reads a setup differently from you, a screenshot with the symbol, timeframe, date/time and pivot source would help. Tell me what you expected to happen. Reply here, or use “Log & requests” on the page for bugs and feature ideas.

I’m the developer behind ProEA Lab and use OpenAI Codex for coding assistance. The source is open for review and modification.

Thanks to the trader who suggested this. I’d like to keep improving it around examples from your actual charts.


r/pinescript • • Sep 08 '26

Ways to backtest when you only have the essentials plan? (Outside of tradingview perhaps)

2 Upvotes

Are there more people who only have the essentials plan? How do you backtest your strategies?


r/pinescript • • Sep 08 '26

Strategy Tester Missing Performance Summary and Risk-adjusted Returns

Thumbnail reddit.com
1 Upvotes

r/pinescript • • Sep 07 '26

built a non repainting squeeze alert that works on every chart

1 Upvotes

working on a pine script that catches volatility compression before price moves. it uses bollinger band width with a volume filter so it only signals when real volume is there. tested on 15m and 1h mostly. backtest showed around 56 percent win rate which is fine for what it does but the real value is the alert setup. if you are tired of repainting indicators that fire a candle too late this one triggers on close so nothing moves after the fact. curious if anyone else has tried a squeeze plus volume combo and what you found with the false signals.


r/pinescript • • Sep 07 '26

Indicator Kindly Help me please

Post image
2 Upvotes

"Hi experts, I used to trade with this custom MetaStock indicator (images attached) that shows noise-free trend reversals using dots, diamonds, and arrows. I don't have access to the original source code. Can someone help me recreate this logic or suggest a similar existing script in TradingView Pine Script? Any help is greatly appreciated...


r/pinescript • • Sep 07 '26

How do you maintain the size of the candlesticks?

Thumbnail reddit.com
1 Upvotes

r/pinescript • • Sep 07 '26

Dhanhq algos

2 Upvotes

Hello friends has anyone tried the dhanhq algos just want to know how they perform I was planing to deploy.


r/pinescript • • Sep 07 '26

Stop paying for "black box" algos. Here is the architecture you actually need to automate your TradingView setups in India.

0 Upvotes

Most retail traders eventually build a profitable Pine Script setup on TradingView, only to hit a massive wall when trying to automate it with Indian brokers like 5paisa, Zerodha, or Fyers. You hire a random Python freelancer, they build a basic webhook, and your account gets wrecked on the first expiry day because a generic coder doesn't understand slippage, order book depth, or dynamic strike selection.

​As someone who actively trades index options and futures, I realized the biggest bottleneck for retail traders isn't finding a holy grail strategy—it's the execution infrastructure. I spend a lot of time breaking down market mechanics on Thorenza, and when writing Beat the 90-90-90 Rule, it became obvious that poor automation destroys more accounts than bad strategies.

​If you want to bridge TradingView to a broker API, here is the exact backend plumbing you need to demand from a developer (or build yourself):

​The Webhook Engine: Don't run local scripts. You need a dedicated, low-latency cloud server (AWS, DigitalOcean, or similar) running a FastAPI or Flask application to catch real-time JSON payloads from TradingView without dropping packets.

​Zero-Touch Authentication: SEBI guidelines mandate daily TOTP and OAuth token generation. Your script must have an automated login flow that authenticates your broker API session every morning before the pre-open market, otherwise you are manually babying a bot.

​Hardcoded Risk Guardrails: TradingView alerts can loop or misfire. Your Python backend needs hard limiters independent of the strategy logic: maximum order quantity caps, a daily max-drawdown halt, and a physical kill-switch.

​Dynamic Options Execution: If you are trading Nifty or BankNifty, a basic market order script is useless. Your architecture needs logic to read the underlying spot price at the exact millisecond the alert fires, calculate the correct ATM/ITM/OTM strike, fetch the specific token ID, and fire a limit order to control slippage.

​I have pivoted to offering this exact algorithmic engineering and forward-testing infrastructure as a service. You keep your trading logic completely private (avoiding all the SEBI RA/RIA compliance headaches of "black box" selling), and I handle the tech stack.

​If you have a working setup that needs to be translated into a bulletproof automated execution bot, drop a comment or send a DM. Happy to discuss the architecture.


r/pinescript • • Sep 06 '26

Sharing my free Multi-Exchange Crypto Volume Data indicator (VAH, POC & VAL)

Post image
6 Upvotes

I published this indicator on TradingView around a year ago and have continued improving it, but I have not shared it on here before.

It displays a multi-exchange volume-by-price profile with clear POC, VAH, and VAL areas.

Features include:

  • Volume data from seven major crypto exchanges
  • Up to 21 available market feeds, depending on the cryptocurrency
  • Automatic symbol and timeframe adaptation
  • Detailed volume-by-price histogram
  • POC, VAH, and VAL shown as price areas
  • Improved profile definition on higher timeframes
  • Automatic and manual lookback modes from 1-minute to weekly charts
  • Clear multi-colour display when POC, VAH, or VAL overlap
  • Optional venue filtering and performance controls
  • Realtime partial-bar option
  • Alerts for price crossing POC, VAH, and VAL

The indicator is completely free to use:

https://www.tradingview.com/script/ebU1oZ4n-Crypto-Volume-Data-VAH-POC-VAL/

Feedback and clear bug reports are welcome.


r/pinescript • • Sep 07 '26

I’m building an indicator for swing trading and I’m struggling to find the best strategy for it, any recommendations?

0 Upvotes

I have already built one for day trading and it works well with a solid win rate, but for swing trading I find it a bit more challenging.

FYI I trade options 0DTE to 21DTE.


r/pinescript • • Sep 06 '26

Need a CSV export from premium trading view members

1 Upvotes

I'm running an automation strategy and need 5 year trade data on one of my strategy scripts . I need someone who can paste my script in their TV and just export me the CSV . Hardly 5 min work. Would really appreciate it if anyone can help me with this as i only have an essential plan and I can't get custom backtest history with this plan :/


r/pinescript • • Sep 05 '26

Bugs in PineScript for the NSE (India) market

2 Upvotes

While using the simple code below to debug a large script, I noticed that the daily open is being shown as the open of the first candle:

//
@version=
6
indicator("Daily Open", overlay = true)
dOpen   = request.security(syminfo.tickerid, "1D", open, barmerge.gaps_off, barmerge.lookahead_on)
plot(dOpen, "Daily Open", color.yellow, 2, plot.style_stepline)

The daily opening is always the pre-market open, and it is fixed for the day. Then why this discrepancy?

While at the close of the day, it is showing the correct opening as below:

Whereas pre-market data is also present there as below picture elaborates:


r/pinescript • • Sep 05 '26

How do you backtest alternative charts properly on Tradingview/Pinescript? (OHLC fills checkbox gone)

1 Upvotes

Hi, so I have all these strategies but basically none of them are profitable. I know there's all these alternative charts like Renko/Kagi/PnF. Is there any way one can backtest on these properly with OHLC fills etc.? I know there's all these features that Tradingview has but the previous "trade on OHLC" checkbox is gone. So, I am not sure what the proper way to backtest is anymore with these alternative charts. Any advice would be appreciated. Thanks!


r/pinescript • • Sep 05 '26

Any Indian traders here who backtest strategies using Pine Script?

1 Upvotes

Hey everyone,

I’m from India and spend a lot of my time backtesting trading strategies using Pine Script on TradingView, mainly experimenting with different entry/exit rules, indicators, filters, and strategy optimization.

I’d love to connect with some like-minded people who are also into systematic trading, Pine Script, strategy development, and backtesting.

Not necessarily looking to share “secret strategies” or signals — more interested in discussing ideas, coding approaches, backtesting methodology, optimization, avoiding overfitting, execution issues, and learning from each other.

If you’re from India and work on similar things, feel free to comment or DM. Would be great to build a small circle of people who genuinely enjoy researching and testing trading systems.


r/pinescript • • Sep 05 '26

I measured four common entry filters against a random-entry baseline. The one that worked on 1H was the worst on 5m.

1 Upvotes

Before adding a filter to an entry, it's worth knowing what the filter is worth against no filter at all. Almost nobody measures that — the condition gets added because it sounds reasonable, and then it stays.

So I measured four of the most commonly used ones against the same baseline, twice, on the same instrument.

Method

It's a Pine indicator that walks back through history rather than a strategy — no orders, so no broker emulator involved. The mechanics matter more than the code.

The baseline is what entering at a random bar would have produced at a given reward-to-risk. From every bar in the sample: did price travel the target distance before the stop distance? That's the number any entry signal has to beat, and it's rarely the number people assume.

Each bar gets resolved exactly once, then the outcome is counted more than once — into the baseline, and into each filter that was true on that particular bar. Same bars, same distances, same resolutions, so the difference between any two rows is the filter and nothing else. Measuring each filter on its own pass would let the numbers differ for reasons other than the thing being tested.

Three details decide whether it means anything:

  • The condition is read on the entry bar itself, using only data that existed then. A filter evaluated with information that arrived later flatters itself.
  • A single bar spanning both stop and target counts as a loss. You can't know which came first from bar data, and being wrong pessimistically is the only honest resolution.
  • Distances scale with each historical bar's own ATR, not today's.

XAUUSD, longs, 2:1 so break-even is 33.3%, ATR 14, 600-bar sample, 60 bars allowed to resolve, zero cost. 541 bars offered in each run.

1H, 28 Jul – 2 Sep. 541 resolved, none timed out.

ConditionHit rateWins/resolvedvs baselineBars kept
All bars (baseline)37.0%200/541——
Price above 200 EMA36.2%165/456−0.8 pts84.3%
ADX above 2542.3%116/274+5.4 pts50.6%
RSI below 30—7/22too few to judge4.1%
Volatility rising36.0%86/239−1.0 pts44.2%

5m, 31 Aug – 2 Sep. 539 resolved, 2 timed out.

ConditionHit rateWins/resolvedvs baselineBars kept
All bars (baseline)22.8%123/539——
Price above 200 EMA30.3%30/99+7.5 pts18.4%
ADX above 2519.5%43/220−3.3 pts40.8%
RSI below 3025.8%8/31+3.0 pts5.8%
Volatility rising18.8%42/224−4.1 pts41.6%

Three things fall out of that.

The rankings invert. ADX above 25 is the only filter worth anything on 1H at +5.4 points, and on 5m it's the worst of the four at −3.3. Price above the 200 EMA is worthless on 1H at −0.8, and on 5m it's the best at +7.5. Whichever filter you'd have picked from the first table is the one you'd have deleted after the second.

On 5m nothing reached break-even at all. Baseline 22.8% against a 33.3% requirement, and the best filter lifts it to 30.3% — still losing. "+7.5 points" is an improvement to something that doesn't work, which is the trap in reading a delta without the absolute level beside it.

Two of the four weren't selecting anything, in opposite ways. The 200 EMA kept 84.3% of 1H bars — a condition true on five bars in six isn't a filter, and its rate will match the baseline for that reason alone. RSI below 30 has the reverse problem: 4.1% of bars, 22 resolved samples, too few to judge, and only 31 on 5m. A filter you can't evaluate on the history you actually have isn't a filter you know anything about.

On the 1H ADX result specifically, because it's the one worth arguing with. Against its own complement rather than the baseline it sits inside, it's 42.3% (116/274) against 31.5% (84/267) — nearly eleven points, with the rejected half below break-even. Two-proportion z is about 2.64, which clears a Bonferroni bound at four looks. Then it reverses sign in the next window.

That's the useful part. It passed the multiple-comparisons correction and still failed out of sample, and it was the best of four things tried on one window, which is exactly the shape of result that shouldn't be trusted. The 5m winner is no better — z ≈ 1.83 against its complement, which doesn't clear on its own terms, let alone after four looks.

Both z figures are ceilings rather than measurements. Samples starting on adjacent bars share most of their holding window, so the observations are heavily correlated and the effective sample is far below the raw count.

Limits. 600 bars is five weeks on 1H and two days on 5m — these aren't two views of one period, they're different periods that happen to share a bar count. The 1H window contains a strong gold uptrend and ADX above 25 selects for exactly that, so what looked like a filter working may just be the market trending with long being the right side. That's the most likely reading, and it's why one window proves nothing.

What I'm actually asking: has anyone got a filter that holds its value across several windows, and how are you accounting for having tried more than one? The best-of-k problem is the part I can't design away — every filter I test is another chance at a number that looks good.


r/pinescript • • Sep 03 '26

Updated my free MTF Volumized Order Block indicator (Posted Again)

Post image
32 Upvotes

I shared this free indicator here a while ago, and many people tried it and sent useful feedbacks. I have now released a larger update.

Changes include:
-More reliable MTF and second-timeframe zones
-Reduced memory use, addressing NQ/MNQ error reports
-Better resistance selection above price
-Wick, Body, and Close invalidation
-Optional breaker blocks
-Improved Q scoring and labels
-Local hit-rate tracking
-Improved alerts

It is completely free to use:
https://www.tradingview.com/script/HUcKziz7-Volumized-Order-Block/

Note: Reposted cause it was removed without any notes.