PROTECTED SOURCE SCRIPT

Target % Rebalancer Based Strategy on Intention Indicator • v1

23
█ OVERVIEW

It’s a target-percentage rebalancer driven by a higher-timeframe (HTF) signal. The signal is interpreted as intention force (bullish vs bearish strength) and directly mapped to a fraction of capital to be exposed long or short (−100% … +100%). The engine then rebalances into that target exposure using base-asset orders, with optional guards (dead-band, cooldown, quantization) to reduce churn. Executions happen on confirmed HTF closes to avoid look-ahead.

Mental model: +0.65 ≈ “be ~65% long,” −0.30 ≈ “be ~30% short.” You’re not predicting returns point-by-point; you’re setting how much to lean, and the rebalancer does the rest.

█ OPEN INTEGRATION & FULL TRANSPARENCY

This strategy is built around an "External Signal of Intention" input — a flexible connector that lets you plug in any custom signal directly from the chart. Whether it’s your own indicator, a community script, or a proprietary logic, the strategy can adapt and execute on it seamlessly.

The goal is to deliver maximum transparency and full user control: every calculation, condition, and transformation is open-source, so you can inspect, modify, and evolve it for your own trading approach. By design, this framework encourages experimentation and collaboration — empowering traders to test, validate, and refine their ideas in a clear, reproducible way.

Use it as a sandbox for innovation or as a transparent execution layer for your favorite signal. Your signal, your logic, your rules — the strategy simply makes it actionable.

█ REBALANCING & POSITION MANAGEMENT (STEP BY STEP)

Target exposure → target base position
target_base = (target% / 100) × equity ÷ price → then rounded to min order size lot.
For display, “target %” is recomputed from the rounded base quantity.

Trade gating
• Trades only on HTF close (the bar where time changes).
• Optional daily loss halt blocks trading after a drawdown threshold for the rest of the day.
• Optional hysteresis: dead-band around the target and cooldown (n bars) after each non-flip trade.
• Min change step for capital % (min step %): no trade unless |current% − target%| ≥ this size.

Atomic flip logic
Crossing long→short or short→long: close all, then open the exact target. Cooldown is bypassed for clean flipping. Otherwise, top-ups/trims rebalance to target.

Side guards
Allow LONG, SHORT, or both. Disabled side is clipped to flat (0%).

Execution semantics
Orders are base-asset quantity (not cash sizing), filled on close, with chosen commission % and no slippage by default.


█ PNL / RPL CALCULATION

This is a TradingView strategy: realized PnL results from order fills (incl. close-and-flip) with your commission %. Equity is marked-to-market every bar; realized P/L is booked at executions while unrealized moves flow continuously through equity. A synthetic impact tracker (diagnostic only) accumulates a cost proportional to turnover of target %. It does not change equity; it just visualizes hypothetical turnover drag beyond exchange fees.


█ HOW LOOK-AHEAD BIAS IS AVOIDED

• request.security with lookahead off supplies HTF values without future leaks.
• You act only at HTF close and use the previous confirmed signal (e.g., w_signal[1]) so trades occur one HTF bar after confirmation (conservative).
• No intrabar peeking: calc_on_every_tick = false, process_orders_on_close = true. Non-repainting and fair.


█ INPUTS (WITH QUICK TIPS)

Strategy Mode
Min change step for capital, % (min step %) → Trade threshold vs target.
Higher → fewer, larger rebalances (lower fees, more tracking error). Lower → tighter tracking (more trades). Start 0–2%.

Enable LONG / SHORT → On spot and can’t short? Disable SHORT. For symmetric backtests, enable both.

Min order size in base asset → Controls lot rounding. Smaller = finer control (more orders). Larger = coarser (fewer orders). Set to venue min size.

Indicator (the intention force)
Detailed input tips live on the indicator’s own page.

Final weight cap → Hard clamp on |exposure|. Tighten to reduce extremes/turnover; loosen for max expressiveness.

Hysteresis + Cooldown → Tame ping-pong around target. Dead-band 1–3% and cooldown 1–3 bars for chop; toward zero for fast breakouts.

Quantized targets → Rounds exposure into discrete levels (e.g., 5 buckets = −100, −50, 0, +50, +100). Fewer buckets = fewer trades, more tracking error. Good for fee-sensitive venues.

Max daily loss halt → Circuit breaker (e.g., −3% halts until next day). Tighten in high vol to avoid cascading flips.

Synthetic impact → Diagnostic turnover-drag curve (bps per 100% turnover). Does not hit PnL.


█ VISUALIZATION

1) Target exposure (%) — “what I want to hold”
• Intention force → target % (−100 … +100) after z-score, scaling (scaleK), capping (weight_cap), optional quantization (buckets), and lot rounding. Updates on HTF closes (confirmed), not intrabar.
• Smooth stair-steps at HTF closes = normal. Quantization → plateaus (e.g., −100/−50/0/+50/+100).
• SHORT off → negative targets clipped to 0%.
• Target jumps too often? Increase TF, widen dead-band, enable buckets.
• At ±100% often? Lower scale or weight cap.

2) Current exposure (%) — “what I’m actually holding”
• position_size × price ÷ equity. Includes rounding, min order size, side clamps, gating.
• Should match target right after a rebalance (HTF close).
• Large persistent gap → min order too big, min step % too high, or hysteresis/cooldown blocking.
• Never negative despite negative targets? SHORT disabled or venue permission.

3) Delta exposure (%) — “tracking error”
• current% − target%. Near 0% after rebalances is healthy.
• Grows between HTF closes; resets on next close.
• Chronic large |delta| → loosen controls (smaller min order, lower min step %, relax hysteresis/cooldown).
• Spikes on flips are expected (close+open, rounded).

4) Trade markers — entries, trims, flips
• Orders only at HTF closes (by design).
• Flip = two markers on same bar (close then open).
• Too many tiny trades? Raise min step %, add dead-band/quantization.
• Missing flips? Side disabled, cooldown blocking, or min step % not met.

5) Regime tint / signal band — “why the target is what it is”
• Background tint shows confirmed HTF signal (z-scored, scaled, capped).
• Positive tint → bullish; negative → bearish. Target should align with tint direction (subject to caps/quantization).
• Flips too fast? Lengthen standardization window or raise backtest TF.
• Extremes too often? Lower Scale / Final Weight Cap.

6) Synthetic impact (bps) — “turnover drag simulator”
• Cumulative cost ∝ turnover of target %. Doesn’t affect equity; just a what-if line.
• Upward slope = frequent rebalances; flat = quiet.
• Steep climb → widen dead-band, add buckets, raise min step %, or slow the signal.

7) Daily loss halt markers — session risk breaker
• Marker appears on the bar/day where same-day drawdown breaches the threshold; trading halts until next day.
• Frequent halts → lower leverage (reduce Scale/Weight cap), raise TF, or widen threshold cautiously.

8) Equity / drawdown panel (if enabled)
• Strategy equity and per-bar returns.
• Step-downs on trade bars = commissions; continuous drift with price.
• Big drops on flip bars → two orders (close+open) pay commission; consider higher HTF to reduce flip frequency.


█ PRACTICAL TUNING PLAYBOOK

1 — First, disable hysteresis/quantization and set min step % to 0 to validate parity with your external backtest.
2 — Re-introduce controls to reduce churn.
3 — On spot, keep SHORT off unless hedging or using perps with borrow considerations.
4 — If fills feel “late,” align chart TF with backtest TF (or keep the one-bar HTF lag intentionally for safety).


█ WHEN THIS STRATEGY SHINES (MARKET REGIMES)

• Persistent trends / clean regimes: stays sized in the right direction without perfect timing.
• Moderate volatility with low chop: hysteresis/cooldown cut churn but still resize meaningfully at HTF closes.
• Less ideal in range-bound chop with frequent false flips — unless you widen dead-band, add buckets, or lengthen TF.


█ QUICK TROUBLESHOOTING FLOWS

“Why didn’t we short here?”
Check target% (went negative?) → current% (stayed ≥ 0?) → Trade markers (was a short blocked?) → confirm SHORT enabled & thresholds/lot size allow the trade.

“Why so many fees?”
High density of trims/top-ups → add dead-band/cooldown, enable quantization, or increase min step %. Watch Synthetic impact flatten as churn drops.

“Why is live exposure off from target?”
If delta% doesn’t collapse to ~0 at HTF close, something is gating (cooldown, min step not met, lot rounding).

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.