[{"data":1,"prerenderedAt":11},["ShallowReactive",2],{"wrun-open-editor-url":3,"wrun:home:try":4},"https://openmarket.xyz/chart/#wrun-open=v1",{"gs-first-step1":5,"fn-alert-golden-cross":6,"cookbook-volume-spike":7,"cookbook-aggregated-cvd":8,"fn-levels-kit-previous-day":9,"strat-rsi-reversion":10},"param(\"period\", 20, { min: 1, max: 200, description: \"EMA length in bars\" });\noutput(\"avg\", line, overlay, { color: \"#2563eb\", width: 2, description: \"EMA of the close\" });\n\nlet ema = new Ema(20);\n\nfunction onStart(): void {\n  ema = new Ema(i32(p_period()));\n}\n\nfunction onBar(): void {\n  out_avg(ema.update(bar.close()));\n}","param(\"fast\", 21, { min: 1, max: 200, description: \"Fast EMA length\" });\nparam(\"slow\", 55, { min: 2, max: 400, description: \"Slow EMA length\" });\noutput(\"fast\", line, overlay, { color: \"#2563eb\", description: \"Fast EMA of the close\" });\noutput(\"slow\", line, overlay, { color: \"#f97316\", description: \"Slow EMA of the close\" });\n// Data-only: 1 on the bar the fast EMA crosses above the slow one, else 0.\nconst goldenCross = output(\"golden_cross\", none);\n// A ready-made signal in the chart's alert dialog: it fires when the gate turns from 0 to 1.\nalert(\"golden_cross_up\", { when: goldenCross, message: \"{{symbol}} golden cross at {{close}}\", description: \"Fast EMA crosses above slow EMA\" });\n\nlet fast = new Ema(21);\nlet slow = new Ema(55);\nlet cross = new Cross();\n\nfunction onStart(): void {\n  fast = new Ema(i32(p_fast()));\n  slow = new Ema(i32(p_slow()));\n  cross = new Cross();\n}\n\nfunction onBar(): void {\n  const close = bar.close();\n  const fastValue = fast.update(close);\n  const slowValue = slow.update(close);\n  const crossed = cross.update(fastValue, slowValue);\n  if (isNaN(slowValue)) return;\n  out_fast(fastValue);\n  out_slow(slowValue);\n  out_golden_cross(crossed == 1 ? 1.0 : 0.0);\n}","param(\"lookback\", 50, { min: 10, max: 300, description: \"Bars of history that define normal volume\" });\nparam(\"threshold\", 2.5, { min: 1, max: 6, description: \"Z-score that counts as a spike\" });\ninput(\"volume\", ohlcv.volume); // the first input is the bar grid: the chart's own candles\noutput(\"z\", line, lower, { color: \"#64748b\", width: 1, description: \"Volume z-score\" });\noutput(\"threshold\", line, lower, { color: \"#ef4444\", width: 1 });\noutput(\"spike\", shape, lower, { color: \"#ef4444\", shape_where: \"is_spike\" });\noutput(\"is_spike\", none);\n\nlet zscore = new Zscore(50);\nlet threshold: f64 = 2.5;\n\nfunction onStart(): void {\n  zscore = new Zscore(i32(p_lookback()));\n  threshold = p_threshold();\n}\n\nfunction onBar(): void {\n  const z = zscore.update(bar.volume());\n  if (isNaN(z)) return;\n  out_z(z);\n  out_threshold(threshold);\n  out_spike(z);\n  out_is_spike(z >= threshold ? 1.0 : 0.0);\n}","param(\"band_len\", 60, { min: 10, max: 500, description: \"Bars in the volatility band\" });\n// The chart's own candles are the grid every other input lines up on.\ninput(\"close\", ohlcv.close);\ninput(\"buy\", trades.volume, { side: \"BUY\", missing: \"zero\", description: \"Aggressive buy volume\" });\ninput(\"sell\", trades.volume, { side: \"SELL\", missing: \"zero\", description: \"Aggressive sell volume\" });\noutput(\"cvd\", line, lower, {\n  width: 2,\n  color_by: \"sign\",\n  colors: [\"#ff5b7f\", \"#22d3a5\"],\n  description: \"Cumulative volume delta on the chart's market\",\n});\noutput(\"upper_band\", line, lower, { color: \"#22d3a5\", opacity: 0.35, description: \"CVD plus one standard deviation\" });\noutput(\"lower_band\", line, lower, { color: \"#ff5b7f\", opacity: 0.35, description: \"CVD minus one standard deviation\" });\noutput(\"sign\", none, lower);\n\nlet stdev = new Stdev(60);\nlet cvd: f64 = 0.0;\n\nfunction onStart(): void {\n  stdev = new Stdev(i32(p_band_len()));\n}\n\nfunction onBar(): void {\n  // A module-level variable is the accumulator: it survives from bar to bar.\n  cvd += in_buy() - in_sell();\n  const band = stdev.update(cvd);\n  const width = isNaN(band) ? 0.0 : band;\n  out_cvd(cvd);\n  out_upper_band(cvd + width);\n  out_lower_band(cvd - width);\n  out_sign(cvd >= 0.0 ? 1.0 : 0.0);\n}","output(\"pdh\", line, overlay, { color: \"#f5a623\", width: 1, description: \"Previous New York day high\" });\noutput(\"pdl\", line, overlay, { color: \"#f5a623\", width: 1, description: \"Previous New York day low\" });\noutput(\"day_open\", line, overlay, { color: \"#94a3b8\", width: 1, line_style: \"dashed\", description: \"Open of the running day\" });\noutput(\"new_day\", none, overlay, { description: \"1 on the first bar of a New York day\" });\n\nlet day = new PeriodLevels(\"day\");\n\nfunction onStart(): void {\n  // Construct in onStart(): an unknown period or zone aborts with a readable message here.\n  day = new PeriodLevels(\"day\", \"America/New_York\");\n}\n\nfunction onBar(): void {\n  day.update(bar.time(), bar.open(), bar.high(), bar.low(), bar.close());\n  out_pdh(day.prevHigh());\n  out_pdl(day.prevLow());\n  out_day_open(day.open());\n  out_new_day(day.isNew() ? 1.0 : 0.0);\n}","// RSI reversion with a protective stop: buy the dip on the bar RSI crosses up through oversold, protect it 4% under the close, leave on recovery.\nstrategy({ initialCapital: 10000, qtyType: \"percentOfEquity\", qtyValue: 25, commissionPercent: 0.05, slippageBps: 2 });\nparam(\"period\", 14, { min: 2, max: 200, description: \"RSI length in bars\" });\noutput(\"rsi\", line, lower, { description: \"Wilder RSI of close, 0 to 100\" });\n\nlet rsi = new Rsi(14);\nconst dip = new Cross();\nconst recovery = new Cross();\n\nfunction onStart(): void {\n  rsi = new Rsi(i32(p_period()));\n}\n\nfunction onBar(): void {\n  const close = bar.close();\n  const value = rsi.update(close);\n  if (isNaN(value)) return;\n  const dipped = dip.update(value, 30.0);\n  const recovered = recovery.update(value, 55.0);\n  if (dipped == 1) strategy.long(\"Dip\").send();\n  if (strategy.positionSize() > 0) strategy.exit(\"Protect\").from(\"Dip\").stop(close * 0.96).send();\n  if (recovered == 1) strategy.closeAll();\n  out_rsi(value);\n}",1791265101959]