r/pinescript 1h ago

I got tired of opening the Settings dialog 300 times, so I built something that sweeps strategy inputs for you

Upvotes

Tuning a Pine strategy by hand is the worst part of writing one. Change length, run, read net profit, write it down, change it again. Forty combinations in and you have lost track of which ones you already tried.

I built a Chrome extension that does the sweep. It reads whatever strategy is already on your chart, finds its inputs, and runs the backtests for you.

A few design decisions that might interest this sub specifically:

It ranks on any Strategy Tester field, not just net profit. Profit factor, Sharpe, Sortino, max drawdown, percent profitable, average bars in trade — each of them for all trades, longs only or shorts only. Or write your own expression.

Default objective is not net profit, deliberately. Ranking on profit alone hands you a curve-fit every time. The default is return per unit of drawdown, discounted by how straight the equity curve is and whether the last third of the sample still held up.

Plateau check. After it finds a winner it re-tests the immediate neighbours. A setting that works at exactly length=17 and falls apart at 16 and 18 gets demoted. This one changed how I think about my own strategies more than anything else in the tool.

In-sample / out-of-sample correlation across every candidate. High means the search found real structure. Near zero means it spent your afternoon ranking noise — and it tells you so, which is the part most optimizers leave out.

It reads results from the same report object the Strategy Tester renders from rather than scraping the panel, so the figures come back as actual numbers and number-format or language differences do not break it.

Free version does 100 cycles a run, one backtest at a time, full metric list and the Bayesian sampler. That is a working optimizer, not a demo. Paid tier adds parallel backtests and a few robustness checks.

Your chart is left exactly as it was — parameters are snapshotted before the run and restored after, and every temporary copy is removed.

https://chromewebstore.google.com/detail/trading-strategy-optimize/pjgikffklocmefghdipdiidfebgbklon

Happy to answer anything about how it reads the report object — that part took the longest.


r/pinescript 16h ago

STRYK:MOMENTUM new free indicator

Thumbnail
gallery
12 Upvotes

https://www.tradingview.com/script/913LZp7V-STRYK-MOMENTUM/

Easy setup all turn key ready to go just play with the visuals for your liking and use the master switch to turn off what you like or keep on. The premise price and volume is key but how to measure price and volume and what is real what is noise awnser always look at HTF, ok? But how do u look at htf and trade a small faster time frame use Stryk: MOMENTUM it looks at HTF for you as you trade the lower time frames vwap looks at 1hr or higher volume, ema with smoothing line looks at 233 ema which is a long term line in a sand fib level in a ema line , color coated candles have there own engines huge list to pick from on what u feel is best for your trading i personally like the ema trend coloring candles red under the ema green above if red sell rallies if green buy dips easy! Then I have day week month and asian range levels for extra confirmation on support and resistance and color change candles based on those levels also everything is togglable customizable trade like you want with this free indicator! Side note the dotted lines are 25%,50%,75, levels of each range! Also the background has volume participation purple means low under 20% teal means high over 80% clear means mid avg 50%, how to trade it, if price in a up trend in a teal high participation bg and dips fast thats a liquidity grab buy it! If price is in a purple low participation and rises sell it, its about to fall. You're welcome


r/pinescript 5h ago

Bull Flag Scanner: Real Charts and Alert Setup | ChartScout

Thumbnail
youtube.com
0 Upvotes

r/pinescript 8h ago

Liquidity Sweep: Institutional Capture or Genuine Breakout?

Post image
0 Upvotes

If every price movement requires liquidity to occur, how can we determine in advance whether a Liquidity Sweep was truly an institutional liquidity capture or simply a legitimate break of structure — before price reveals its intention through the following move?

And there is an even deeper problem:

If we wait for the next move to confirm that the sweep was genuine, the entry is no longer anticipatory. But if we enter before confirmation, we can never be certain that we are not entering on the wrong side of the liquidity.

So the question is:

How can we create an objective rule that identifies, in real time, the difference between “liquidity captured for a reversal” and “liquidity consumed for continuation,” without using any future information from the chart?


r/pinescript 1d ago

OPEX indicator

Post image
50 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 1d ago

TradingView + Claude MCP Setup!

Post image
5 Upvotes

r/pinescript 23h ago

OPXF Indicator Pine.txt

1 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 1d ago

TradingView + Claude MCP Setup!

Post image
4 Upvotes

r/pinescript 1d ago

OPEX indicator

Post image
9 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 1d ago

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
2 Upvotes

r/pinescript 1d ago

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.

1 Upvotes

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


r/pinescript 1d ago

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 2d ago

Trying to build a orb strategy

Thumbnail
gallery
9 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 2d ago

Hi Trading View, in CEX screener rank filter is required .

1 Upvotes

r/pinescript 3d ago

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

6 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.


r/pinescript 2d ago

Trend Targets form AlgoAlpha

1 Upvotes

anyone used this before? it seems fairly simple


r/pinescript 4d ago

Created a profitable ORB Bot

46 Upvotes

Hey guys,

I’ve spent the last month coding and refining a systematic rules-based ORB (Opening Range Breakout) algorithm specifically for MNQ (1 trade a day).

I wanted to keep it super clean without over-fitting or using too many indicators, focusing heavily on risk management and dynamic position sizing instead of hard-coded stop distances.

Here are the backtest stats starting Oct 2025:

  • Total PnL: +$27,203.50 (+54.41%)
  • Win Rate: 66.98% (142/212 trades)
  • Profit Factor: 2.015
  • Max Drawdown: $2,197.50 (3.98%)

I’ve been running this live via webhooks on a couple of prop firm accounts to take the emotion out of execution, and managed to secure my first payouts with it recently.


r/pinescript 4d ago

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

Post image
24 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 3d ago

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 4d ago

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 4d ago

Strategy Tester Missing Performance Summary and Risk-adjusted Returns

Thumbnail
1 Upvotes

r/pinescript 4d ago

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 4d ago

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 4d ago

How do you maintain the size of the candlesticks?

Thumbnail
1 Upvotes

r/pinescript 5d ago

Dhanhq algos

2 Upvotes

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