Pine Script Origins
Relevant source files
The following files were used as context for generating this wiki page:
The Rabid Raccoon project originates as a multi-feature trading indicator built in Pine Script v6. While the project has expanded into a full-stack Next.js web application with AI forecasting and persistent PostgreSQL storage, its core logic and architectural patterns are derived from Pine Script methodologies tailored for Micro E-mini S&P 500 (MES) futures trading.
The system bridges traditional technical analysis—originally implemented as scripts for the TradingView platform—with modern AI-driven analysis. It maintains a "math-first" approach where signals are computed via raw technical indicators before being overlayed with narrative interpretations from Large Language Models.
Sources: README.md:1-10, src/lib/instant-analysis.ts:1-10
Architecture and Core Modules
The indicator architecture is designed for modularity within a single Pine Script file using //#region blocks. Each module can be toggled via inputs for isolated debugging. The core functionality is built around five primary trading methodologies.
Feature Roadmap
| Module | Status | Description |
|---|---|---|
| Measured Move Detection | TODO | Equal-length price swing identification with projected targets |
| Auto-Fibonacci Engine | TODO | Multi-timeframe fib methodology (4H → 1H → 15m) |
| Break-Hook-Go | TODO | Structure break → retest → continuation pattern detection |
| Correlation Analysis | TODO | Dynamic VIX/DXY/NQ correlation with divergence signals |
| Risk Management | TODO | Position sizing, stop placement, R:R calculation |
Sources: README.md:12-21, README.md:46-55
Swing and Move Detection
The system utilizes a shared swing detection core that feeds multiple analysis modules. This logic identifies SwingPoint data structures (highs and lows) which are then used to calculate Fibonacci levels and detect "Measured Moves" (AB=CD patterns).
A visual representation of the data flow from raw price action to technical setups.
Sources: src/lib/instant-analysis.ts:254-268, src/components/TechChart.tsx:143-167
Technical Implementation and Logic
The transition from Pine Script to the web application involves replicating Pine's built-in functions (like SMA, EMA, RSI) in TypeScript to ensure consistency between the indicator and the dashboard.
Indicator Logic Components
The analysis engine computes over 200 technical signals across multiple timeframes (15M, 1H, 4H). The logic uses User Defined Types (UDTs) to structure data, similar to the MeasuredMove, FibLevel, and RiskProfile types found in the Pine Script version.
- Moving Averages: SMA and EMA for periods 5, 10, 20, 50, 100, and 200.
- Oscillators: RSI (7, 14, 21), Stochastic (9, 14, 21), Williams %R, and CCI.
- Trend/Volatility: MACD, ATR expansion, and VWAP.
Sources: src/lib/instant-analysis.ts:114-175, src/lib/instant-analysis.ts:188-210, README.md:52
The Break-Hook-Go Pattern
A primary strategy inherited from the original Pine Script logic is the "Break-Hook-Go" setup, often visualized in the SetupLog component. It tracks the lifecycle of a trade setup through specific phases.
This diagram shows the state transitions of a trade setup as defined in the system logic.
Sources: src/components/MesIntraday/SetupLog.tsx:21-29
Development and Validation Workflow
The project maintains a strict workflow to ensure that logic edited in VS Code remains compatible with TradingView's environment.
- Edit: Code is edited in VS Code with specific extensions for real-time linting.
- Validate: The system uses the
pine-facadeAPI to catch errors before deployment. - Deploy: Code is copy-pasted into the TradingView Pine Editor.
- Debug: Developers use Pine Logs, the Pine Profiler, and a custom debug dashboard toggled via script inputs.
Sources: README.md:29-37
AI Analysis Integration
The web application enhances the original Pine Script origins by passing technical signal data to AI models (Claude and OpenAI). This creates an "Instant Analysis" that combines deterministic math with qualitative narrative.
Chart Analysis Endpoint
The /api/analyse/chart route takes a base64 screenshot from a chart (likely derived from TradingView or Lightweight Charts) and processes it alongside structured OHLCV data.
| Parameter | Type | Description |
|---|---|---|
| image | string | Base64 PNG from chart.takeScreenshot() |
| tf | string | Timeframe (15M, 1H, 4H) |
| bias | string | Bullish, Bearish, or Neutral |
Sources: src/app/api/analyse/chart/route.ts:16-43, src/lib/instant-analysis.ts:15-32
The system uses specific model candidates for this analysis, starting with claude-opus-4-6 for vision-based tasks and transitioning to various GPT-5 versions for text-based forecasting.
Sources: src/app/api/analyse/chart/route.ts:112, src/lib/forecast.ts:36-47
Conclusion
The origins of the Rabid Raccoon project as a Pine Script v6 indicator continue to dictate the technical architecture of its modern web-based successor. By codifying traditional technical analysis patterns like Measured Moves and the Break-Hook-Go sequence into a TypeScript environment, the project provides a seamless transition from manual charting to automated, AI-augmented trading intelligence.