OPEN-SOURCE SCRIPT
Updated

Prism Strategy

4 889
## Prism Strategy: Multi-Dimensional Trend & Structural Flow

**Prism Strategy** is a high-precision trend-following and momentum execution engine designed to capture institutional-grade moves while providing a comprehensive structural analysis of the market. It integrates a dynamic EMA Ribbon, RSI momentum filtering, automated Fibonacci levels, and a proprietary "Structural Wall" logic to determine the most logical points for entry and risk management.

### 1. Trend Identification (The EMA Ribbon)
The strategy utilizes a 12-layer EMA Ribbon to identify trend alignment.
* **Short-Term Stack:** 3, 5, 8, 10, 12, 15 EMAs.
* **Long-Term Stack:** 30, 35, 40, 45, 50, 60 EMAs.
A signal is only considered valid when the ribbon is in a **Full Stack** configuration (perfectly ordered from fastest to slowest), ensuring the trend is established across multiple time-cycles.

### 2. Momentum Filtering
To prevent "whipsaws" in low-volatility environments, the strategy incorporates **RSI (14)**.
* **Long Positions:** Require RSI > 50.
* **Short Positions:** Require RSI < 50.
This ensures that the price is not just trending, but moving with sufficient velocity.

### 3. The "Structural Wall" Logic
One of the most advanced features of this strategy is the **Structural Wall Analysis**. The algorithm identifies the strongest confluence between:
* **Dynamic Support/Resistance:** The Base EMA (12).
* **Static Support/Resistance:** Auto-calculated Fibonacci Retracement levels (0.0 to 1.618).
The "Wall" is formed by selecting the maximum (for Longs) or minimum (for Shorts) of these two values, creating a "Hard Floor/Ceiling" that acts as the primary anchor for the trailing stop.

### 4. Dynamic Risk Management (ATR-Based)
* **Stop Loss & Take Profit:** Initial levels are calculated using **ATR (Average True Range)** multiplied by a user-defined factor (default 1.5x for stops and a 2.0 RR ratio).
* **Intelligent Trailing Stop:** The strategy tracks the "Structural Wall" and updates the stop loss in real-time. It only moves in the direction of the trade (up for long, down for short) to lock in profits while giving the price enough room to breathe based on current volatility.

### 5. Integrated Execution Dashboard
The built-in UI provides real-time data for professional monitoring:
* **System Mode:** Displays current trend bias (Bullish/Bearish/Neutral).
* **Entry Advice:** An AI-driven logic that evaluates if the current price is "Ideal," "Overextended," or if the "Risk > Reward" is currently unfavorable for new entries.
* **Fibonacci Alerts:** Warns the user when the price is approaching a major Fibonacci level (⚠️ Alert) to prepare for potential reversals or pullbacks.

### 6. Exit Logic
The strategy employs a **Unified Exit Engine** based on three criteria:
1. **Hard Stop/TP:** Triggered if price hits the ATR-based levels.
2. **Structural Violation:** Triggered if the "Trailing Stop" (Structural Wall) is breached.
3. **Trend Break:** Triggered if the EMA Ribbon loses its "Full Stack" alignment, indicating a loss of trend momentum.

---

### **How to Use**
* **Timeframes:** Optimized for trend-rich environments (5m, 15m, 1h, and Daily).
* **Markets:** Effective on liquid assets including Equities, Forex, and Crypto.
* **Entry:** Look for "IDEAL ENTRY" status on the dashboard for the highest probability setups.

---

**Disclaimer:** *Trading involves significant risk. This strategy is an analytical tool and does not guarantee profits. Past performance is not indicative of future results. This is not investment advice; it is for educational purposes only.*
Release Notes
This update focuses on giving absolute visual control over the Prism Strategy while fixing a minor rendering issue with the dynamic levels.

What's New & Fixed:

👁️ Full Ribbon Toggle Control: You now have complete power over what appears on your chart! We've added individual "Show/Hide" checkboxes for all 12 EMAs (6 Short-term, 6 Long-term) in the settings panel.

🧹 Clean Default Layout: Although the engine calculates the full 12-layer GMMA ribbon for its structural logic, the default visual layout remains clean and optimized. Only the core 6 EMAs are visible by default to prevent chart clutter, but you can enable the rest anytime with a single click.

🔧 Fibonacci Labels Restored (Bug Fix): Addressed a rendering optimization issue that caused the dynamic Fibonacci level values to disappear from the chart. The text labels and their corresponding prices are now fully restored and consistently visible next to the structural lines.

Your momentum logic, risk management, and dashboard remain fully intact. Enjoy the enhanced customization!
Release Notes

### Prism Strategy - Release Notes

**Bug Fixes & Critical Updates**
* **Resolved "Zero Trades" Issue (Margin Fix):** Adjusted the default order quantity from 100% to 99% of equity. This prevents broker rejection due to insufficient margin or fractional share limitations (specifically required for spot exchanges like BIST).
* **Fixed "ENGINE LOCKED" State Conflict:** Overhauled the core state machine (`trade_state`). The system now strictly requires a neutral state before validating new entry signals, eliminating conflicting states and ensuring smooth transitions between Long and Short biases.

**Enhancements in Trade Management**
* **Stabilized Position Holding:** Removed the hyper-sensitive EMA micro-trend break condition for exits. Trades are now confidently managed strictly through predefined Take-Profit (Target) and Trailing Stop-Loss levels, preventing premature and unnecessary exits during minor market pullbacks.

**Performance Optimizations**
* **Dashboard Rendering Efficiency:** Refactored the UI table code. Dashboard calculations and visual updates are now strictly executed on the last bar (`barstate.islast`). This prevents memory leaks, eliminates execution timeouts, and drastically speeds up historical backtesting.
Release Notes
Changed the code to use sma for first three moving average
Release Notes
Corrected sma calc

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.