OPEN-SOURCE SCRIPT

AMD Session Structure Levels

# Market Structure & Manipulation Probability Indicator

## Overview
This advanced indicator is designed for traders who want a systematic approach to analyzing market structure, identifying manipulation, and assessing probability-based trade setups. It incorporates four core components:

### 1. Session Price Action Analysis
- Tracks **OHLC (Open, High, Low, Close)** within defined sessions.
- Implements a **dual tracking system**:
- **Official session levels** (fixed from the session open to close).
- **Real-time max/min tracking** to differentiate between temporary spikes and real price acceptance.

### 2. Market Manipulation Detection
- Identifies **manipulative price action** using the relationship between the open and close:
- If **price closes below open** → assumes **upward manipulation**, followed by **downward distribution**.
- If **price closes above open** → assumes **downward manipulation**, followed by **upward distribution**.
- Normalized using **ATR**, ensuring adaptability across different volatility conditions.

### 3. Probability Engine
- Tracks **historical wick ratios** to assess trend vs. reversal conditions.
- Calculates **conditional probabilities** for price moves.
- Uses a **special threshold system (0.45 and 0.03)** for reversal signals.
- Provides **real-time probability updates** to enhance trade decision-making.

### 4. Market Condition Classification
- Classifies market conditions using a **wick-to-body ratio**:
```pine
wick_to_body_ratio = open > close ? upper_wick / (high - low) : lower_wick / (high - low)
```
- **Low ratio (<0.25)** → Likely a **trend day**.
- **High ratio (>0.25)** → Likely a **range day**.

---

## Why This Indicator Stands Out

### ✅ Smarter Level Detection
- Uses **ATR-based dynamic levels** instead of static support/resistance.
- Differentiates **manipulation from distribution** for better decision-making.
- Updates probabilities **in real-time**.

### ✅ Memory-Efficient Design
- Implements **circular buffers** to maintain efficiency:
```pine
var float[] manipUp = array.new_float(lookbackPeriod, 0.0)
var float[] manipDown = array.new_float(lookbackPeriod, 0.0)
```
- Ensures **constant memory usage**, even over extended trading sessions.

### ✅ Advanced Probability Calculation
- Utilizes **conditional probabilities** instead of simple averages.
- Incorporates **market context** through wick analysis.
- Provides **actionable signals** via a probability table.

---

## Trading Strategy Guide

### **Best Entry Setups**
✅ Wait for **price to approach manipulation levels**.
✅ Confirm using the **probability table**.
✅ Check the **wick ratio for context**.
✅ Enter when **conditional probability aligns**.

### **Smart Exit Management**
✅ Use **distribution levels** as **profit targets**.
✅ Scale out **when probabilities shift**.
✅ Monitor **wick percentiles** for confirmation.

### **Risk Management**
✅ Size positions based on **probability readings**.
✅ Place stops at **manipulation levels**.
✅ Adjust position size based on **trend vs. range classification**.

---

## Configuration Tips

### **Session Settings**
```pine
sessionTime = input.session("0830-1500", "Session Hours")
weekDays = input.string("23456", "Active Days")
```
- Match these to your **primary trading session**.
- Adjust for different **market opens** if needed.

### **Analysis Parameters**
```pine
lookbackPeriod = input.int(50, "Lookback Period")
low_threshold = input.float(0.25, "Trend/Range Threshold")
```
- **50 periods** is a good starting point but can be optimized per instrument.
- The **0.25 threshold** is ideal for most markets but may need adjustments.

---

## Market Structure Breakdown

### **Trend/Continuation Days**
- **Characteristics:**
✅ Small **opposing wicks** (minimal counter-pressure).
✅ Clean, **directional price movement**.
- **Bullish Trend Day Example:**
✅ Small **lower wicks** (minimal downward pressure).
✅ Strong **closes near the highs** → **Buyers in control**.
- **Bearish Trend Day Example:**
✅ Small **upper wicks** (minimal upward pressure).
✅ Strong **closes near the lows** → **Sellers in control**.

### **Reversal Days**
- **Characteristics:**
✅ **Large opposing wicks** → Failed momentum in the initial direction.
- **Bullish Reversal Example:**
✅ **Large upper wick early**.
✅ **Strong close from the lows** → **Sellers failed to maintain control**.
- **Bearish Reversal Example:**
✅ **Large lower wick early**.
✅ **Weak close from the highs** → **Buyers failed to maintain control**.

---

## Summary
This indicator systematically quantifies market structure by measuring **manipulation, distribution, and probability-driven trade setups**. Unlike traditional indicators, it adapts dynamically using **ATR, historical probabilities, and real-time tracking** to offer a structured, data-driven approach to trading.

🚀 **Use this tool to enhance your decision-making and gain an objective edge in the market!**

Disclaimer