OPEN-SOURCE SCRIPT

NIFTY Weekly Option Seller Directional

61
Here’s a straight description you can paste into the TradingView “Description” box and tweak if needed:

---

### NIFTY Weekly Option Seller – Regime + Score + Management (Single TF)

This indicator is built for **weekly option sellers** (primarily NIFTY) who want a **structured regime + scoring framework** to decide:

* Whether to trade **Iron Condor (IC)**, **Put Credit Spread (PCS)** or **Call Credit Spread (CCS)**
* How strong that regime is on the current timeframe (score 0–5)
* When to **DEFEND** existing positions and when to **HARVEST** profits

> **Note:** This is a **single timeframe** tool. The original system uses it on **4H and 1D separately**, then combines scores manually (e.g., using `min(4H, 1D)` for conviction and lot sizing).

---

## Core logic

The script classifies the market into 3 regimes:

* **IC (Iron Condor)** – range/mean-reversion conditions
* **PCS (Put Credit Spread)** – bullish/trend-up conditions
* **CCS (Call Credit Spread)** – bearish/trend-down conditions

For each regime, it builds a **0–5 score** using:

* **EMA stack (8/13/34)** – trend structure
* **ADX (custom DMI-based)** – trend strength vs range
* **Previous-day CPR** – in CPR vs break above/below
* **VWAP (session)** – near/far value
* **Camarilla H3/L3** – for IC context
* **RSI (14)** – used as a **brake**, not a primary signal
* **Daily trend / Daily ADX** – used as **hard gates**, not double-counted as extra points

Then:

* Scores for PCS / CCS / IC are **cross-penalised** (they pull each other down if conflicting)
* Final scores are **smoothed** (current + previous bar) to avoid jumpy signals

The **background colour** shows the current regime and conviction:

* Blue = IC
* Green = PCS
* Red = CCS
* Stronger tint = higher regime score

---

## Scoring details (per timeframe)

**PCS (uptrend, bullish credit spreads)**

* +2 if EMA(8) > EMA(13) > EMA(34)
* +1 if ADX > ADX_TREND
* +1 if close > CPR High
* +1 if close > VWAP
* RSI brake:

* If RSI < 50 → PCS capped at 2
* If RSI > 75 → PCS capped at 3
* Daily gating:

* If daily EMA stack is **not** uptrend → PCS capped at 2

**CCS (downtrend, bearish credit spreads)**

* +2 if EMA(8) < EMA(13) < EMA(34)
* +1 if ADX > ADX_TREND
* +1 if close < CPR Low
* +1 if close < VWAP
* RSI brake:

* If RSI > 50 → CCS capped at 2
* If RSI < 25 → CCS capped at 3
* Daily gating:

* If daily EMA stack is **not** downtrend → CCS capped at 2

**IC (range / mean-reversion)**

* +2 if ADX < ADX_RANGE (low trend)
* +1 if close inside CPR
* +1 if near VWAP
* +0.5 if inside Camarilla H3–L3
* +1 if daily ADX < ADX_RANGE (daily also range-like)
* +0.5 if RSI between 45 and 55 (classic balance zone)
* Daily gating:

* If daily ADX ≥ ADX_TREND → IC capped at 2 (no “strong IC” in strong trends)

**Cross-penalty & smoothing**

* Each regime’s raw score is reduced by **0.5 × max(other two scores)**
* Final IC / PCS / CCS scores are then **smoothed** with previous bar
* Scores are always clipped to **[0, 5]**

---

## Regime selection

* If one regime has the highest score → that regime is selected.
* If there is a tie or close scores:

* When ADX is high, trend regimes (PCS/CCS) are preferred in the direction of the EMA stack.
* When ADX is low, IC is preferred.

The selected regime’s score is used for:

* Background colour intensity
* Minimum score gate for alerts
* Display in the info panel

---

## DEFEND / HARVEST / REGIME alerts

The script also defines **management signals** using ATR-based buffers and Camarilla breaks:

* **DEFEND**

* Price moving too close to short strikes (PCS/CCS/IC) relative to ATR, or
* Trend breaks through Camarilla with ADX strong
→ Suggests rolling away / widening / converting to reduce risk.

* **HARVEST**

* Price has moved far enough from your short strikes (in ATR multiples) and market is still range-compatible
→ Suggests booking profits / rolling closer / reducing risk.

* **REGIME CHANGED**

* Regime flips (IC ↔ PCS/CCS) with cooldown and minimum score gate
→ Suggests switching playbook (range vs trend) for new entries.

Each of these has a plotshape label plus an `alertcondition()` for TradingView alerts.

---

## UI / Panel

The **top-right panel** (optional) shows:

* Strategy + final regime score (IC / PCS / CCS, x/5)
* ADX / RSI values
* CPR status (Narrow / Normal / Wide + %)
* EMA Stack (Up / Down / Mixed) and EMA tightness
* VWAP proximity (Near / Away)
* Final **IC / PCS / CCS** scores (for this timeframe)
* H3/L3, H4/L4, CPR Low/High and VWAP levels (rounded)

These values are meant to be **read quickly at the decision time** (e.g. near the close of the 4H bar or daily bar).

---

## Intended workflow

1. Run the script on **4H** and **1D** charts separately.
2. For each timeframe, read the panel’s **IC / PCS / CCS scores** and regime.
3. Decide:

* Final regime (IC vs PCS vs CCS)
* Combined score (e.g. `AlignScore = min(Score_4H, Score_1D)`)
4. Map that combined score to **your own lot-size buckets** and trade rules.
5. During the life of the position, use **DEFEND / HARVEST / REGIME** alerts to adjust.

The script does **not** auto-calculate lot size or P&L. It focuses on giving a structured, consistent **market regime + strength + levels + management** layer for weekly option selling.

---

## Disclaimer

This is a discretionary **decision-support tool**, not a guarantee of profit or a replacement for risk management.
No performance is implied or promised. Always size positions and manage risk according to your own capital, rules, and regulations.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.