A comprehensive project for organizing, tracking, and managing Pine Script files for the TradingView platform. Includes a beautiful web-based interface to view all your scripts with their metadata and backtest performance metrics.
This project provides a production-quality solution for managing your TradingView Pine Scripts, including:
- β Organized directory structure for indicators, strategies, and studies
- β JSON-based data storage (no database required)
- β Interactive web interface for full CRUD operations
- β Backtest performance tracking and metrics
- β Advanced search and filtering
- β Automatic version control with changelog tracking
- β Comprehensive code review based on official TradingView standards
- β Auto-fix system for common code quality issues
- β LLM-powered fixes using OpenAI or Claude
- β Logic validation to catch bugs and errors
- β Automatic backups (keeps last 10, with timestamps)
- β Version history with restore capability
- β Data integrity checks and validation
- β Error recovery mechanisms
π New Users: Start with QUICKSTART.md for a 2-minute setup guide!
π Developers: See API_DOCUMENTATION.md for complete API reference
π Code Review: Check out CODE_REVIEW_REPORT.md for project assessment
pine_scripts/
βββ scripts/ # All Pine Script files
β βββ indicators/ # Technical indicators (RSI, MACD, etc.)
β βββ strategies/ # Trading strategies with entry/exit logic
β βββ studies/ # Other analysis tools
βββ data/ # JSON data files
β βββ scripts.json # Main database of all scripts
β βββ schema.json # JSON schema definition
βββ web/ # Web interface
β βββ index.html # Main HTML page
β βββ css/
β β βββ styles.css # Styling
β βββ js/
β βββ app.js # Application logic
βββ docs/ # Documentation and screenshots
βββ tests/ # Test files (optional)
βββ .cursorrules # Cursor AI rules for this project
βββ .gitignore # Git ignore rules
βββ README.md # This file
Create and activate a virtual environment to isolate project dependencies:
# Create virtual environment
python -m venv venv
# Activate it:
# Windows PowerShell:
.\venv\Scripts\Activate.ps1
# Windows CMD:
venv\Scripts\activate.bat
# macOS/Linux:
source venv/bin/activate
# You should see (venv) in your terminal promptInstall the required Python packages (with virtual environment activated):
pip install -r requirements.txtFor AI-powered code fixes, create a .env file in the project root:
# .env file (create this file)
OPENAI_API_KEY=your_openai_api_key_here
DEFAULT_LLM_PROVIDER=openai
OPENAI_MODEL=gpt-4
# OR use Claude:
# ANTHROPIC_API_KEY=your_anthropic_api_key_here
# DEFAULT_LLM_PROVIDER=anthropic
# CLAUDE_MODEL=claude-3-5-sonnet-20241022Note: LLM features are optional. The app works perfectly without them for manual code reviews and quick-fixes.
Make sure your virtual environment is activated, then start the server:
# Make sure (venv) is shown in your prompt, then:
python server.pyThe server will start at http://localhost:5000 and you'll see:
π Pine Script Library API Server
π Server running at: http://localhost:5000
π Open web interface: http://localhost:5000
Navigate to http://localhost:5000 in your web browser. The interface will automatically load your scripts and provide full Create, Read, Update, Delete functionality.
You can now manage your scripts in two ways:
- Click "+ Create New Script" to add a new script
- Fill in the form with script details and backtest metrics
- Click "Edit" on any script to update its information
- Click "Delete" to remove a script (with confirmation)
- All changes are automatically saved to
data/scripts.jsonwith backups
- Save Pine Script files in the appropriate directory:
- Indicators β
scripts/indicators/ - Strategies β
scripts/strategies/ - Studies β
scripts/studies/
- Indicators β
- Add metadata entries to
data/scripts.json(see schema below) - Refresh the web interface to see your changes
The data/scripts.json file stores all metadata about your scripts. Here's the structure:
id: Unique identifier (e.g., "rsi-divergence-indicator")name: Display nametype: "indicator", "strategy", or "study"version: Version number (e.g., "1.0.0")filePath: Relative path to the .pine filedateCreated: ISO 8601 timestamp
description: What the script doesauthor: Your nametags: Array of searchable tagstimeframes: Recommended timeframes (e.g., ["1h", "4h"])parameters: Input parameters with defaultsbacktest: Performance metrics (see below)status: "active", "testing", "deprecated", or "archived"notes: Additional information
{
"symbol": "BTCUSD",
"timeframe": "4h",
"startDate": "2023-01-01",
"endDate": "2025-12-31",
"initialCapital": 10000,
"netProfit": 2450.50,
"netProfitPercent": 24.51,
"totalTrades": 45,
"winningTrades": 28,
"losingTrades": 17,
"winRate": 62.22,
"profitFactor": 1.85,
"maxDrawdown": -12.5,
"avgTrade": 54.46,
"avgWinningTrade": 145.80,
"avgLosingTrade": -85.20,
"sharpeRatio": 1.42,
"notes": "Additional context"
}- Sortable columns: Click headers to sort by any metric
- Search: Find scripts by name, description, or tags
- Filters: Filter by type, status
- Stats Dashboard: Overview of your script collection
- Color-coded metrics: Green (good), yellow (neutral), red (poor)
- Win Rate (%)
- Profit Factor
- Net Profit (%)
- Max Drawdown (%)
- Total Trades
- Last Modified Date
- Create: Click "+ Create New Script" to add new entries
- Read: Click "View" to see full details in a modal popup
- Update: Click "Edit" to modify script information
- Delete: Click "Delete" to remove scripts (with confirmation)
- Automatic Backups: Every save creates a timestamped backup in
data/backups/ - Smart Backup Management: Keeps last 10 backups, throttles to prevent spam
- Validation: Required fields enforced, data integrity checks
- Notifications: Visual feedback for all operations
- Responsive Design: Works on desktop, tablet, and mobile
- Code Review Reports: Export to PDF or copy to clipboard for LLM analysis
- Version Control: Complete history with restore and compare capabilities
- Auto-Fix: One-click fixes for common code quality issues
- Click "+ Create New Script" button
- Fill in the required fields:
- Name (required)
- Type: Indicator, Strategy, or Study (required)
- Version (required, defaults to 1.0.0)
- File Path (required, e.g.,
scripts/indicators/my-script.pine)
- Add optional details:
- Description, author, tags, timeframes
- Backtest metrics (for strategies)
- Click "Save Script"
The script will be automatically added to data/scripts.json with timestamps and a backup will be created.
Create your script file in the appropriate folder:
scripts/strategies/my-strategy.pine
Add an entry to data/scripts.json or use the web interface:
{
"id": "my-strategy",
"name": "My Trading Strategy",
"type": "strategy",
"version": "1.0.0",
"pineVersion": 5,
"description": "A description of what this strategy does",
"filePath": "scripts/strategies/my-strategy.pine",
"dateCreated": "2026-01-08T12:00:00Z",
"dateModified": "2026-01-08T12:00:00Z",
"author": "Your Name",
"tags": ["trend", "momentum"],
"timeframes": ["1h", "4h"],
"status": "active",
"parameters": [
{
"name": "length",
"type": "int",
"default": 14,
"description": "Period length"
}
],
"backtest": {
"symbol": "BTCUSD",
"timeframe": "4h",
"startDate": "2024-01-01",
"endDate": "2025-12-31",
"initialCapital": 10000,
"netProfit": 1500,
"netProfitPercent": 15,
"totalTrades": 30,
"winningTrades": 20,
"losingTrades": 10,
"winRate": 66.67,
"profitFactor": 2.1,
"maxDrawdown": -8.5,
"avgTrade": 50
}
}- Open your script file
- Copy the code
- Paste into TradingView Pine Editor
- Run backtest and record results
- Click "Edit" in the web interface and add/update backtest metrics
The Flask server provides a comprehensive RESTful API. For complete documentation, see API_DOCUMENTATION.md.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/scripts |
List all scripts |
| GET | /api/scripts/:id |
Get single script |
| POST | /api/scripts |
Create new script |
| PUT | /api/scripts/:id |
Update script |
| DELETE | /api/scripts/:id |
Delete script |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/scripts/:id/code |
Get script code (current or specific version) |
| GET | /api/scripts/:id/review |
Perform code quality review |
| POST | /api/scripts/:id/save-code |
Save edited code (creates new version) |
| POST | /api/scripts/:id/autofix |
Auto-fix single issue |
| POST | /api/scripts/:id/auto-fix-all |
Auto-fix all fixable issues |
| POST | /api/scripts/:id/smart-autofix |
LLM-powered intelligent fixes |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/scripts/:id/versions |
Get version history |
| POST | /api/scripts/:id/versions/:v/restore |
Restore previous version |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/backups |
List available backups |
| POST | /api/backups/:file |
Restore from backup |
# Get all scripts
curl http://localhost:5000/api/scripts
# Create a new script
curl -X POST http://localhost:5000/api/scripts \
-H "Content-Type: application/json" \
-d '{
"name": "My Strategy",
"type": "strategy",
"version": "1.0.0",
"filePath": "scripts/strategies/my-strategy.pine"
}'
# Update a script
curl -X PUT http://localhost:5000/api/scripts/my-strategy-id \
-H "Content-Type: application/json" \
-d '{"version": "1.1.0"}'
# Delete a script
curl -X DELETE http://localhost:5000/api/scripts/my-strategy-id- Use lowercase with hyphens:
my-indicator.pine - Be descriptive:
rsi-divergence-detector.pine - Include type if not in a subfolder:
strategy-ema-cross.pine
//@version=5
strategy("My Strategy Name",
overlay=true,
default_qty_type=strategy.percent_of_equity,
default_qty_value=10)
// ============================================================================
// DESCRIPTION
// ============================================================================
// Brief description of what this script does
//
// AUTHOR: Your Name
// VERSION: 1.0.0
// DATE: 2026-01-08
//
// PARAMETERS:
// - length: Description of parameter
// - threshold: Description of parameter
//
// USAGE:
// Explain how to use this script
// ============================================================================
// Your code here...
- Use semantic versioning:
MAJOR.MINOR.PATCH - Increment MAJOR for breaking changes
- Increment MINOR for new features
- Increment PATCH for bug fixes
- Update both the script file and
scripts.json
The web interface supports:
- Text search: Searches name, description, and tags
- Type filter: Show only indicators, strategies, or studies
- Status filter: Show only active, testing, deprecated, or archived scripts
- Sorting: By name, date modified, or any performance metric
-
Win Rate: Percentage of winning trades
- Good: >60%
- Average: 50-60%
- Poor: <50%
-
Profit Factor: Gross profit / Gross loss
- Excellent: >2.0
- Good: 1.5-2.0
- Average: 1.0-1.5
- Poor: <1.0
-
Max Drawdown: Largest peak-to-trough decline
- Good: <10%
- Average: 10-20%
- Poor: >20%
-
Sharpe Ratio: Risk-adjusted return
- Excellent: >2.0
- Good: 1.0-2.0
- Average: 0.5-1.0
- Poor: <0.5
- Every save operation creates a timestamped backup in
data/backups/ - The system keeps the last 10 backups automatically
- Backups are named:
scripts_YYYYMMDD_HHMMSS.json
# Create a manual backup
cp data/scripts.json data/scripts_backup_$(date +%Y%m%d).jsonUse the API endpoint to restore:
curl -X POST http://localhost:5000/api/backups/scripts_20260108_120000.jsonOr manually copy:
cp data/backups/scripts_20260108_120000.json data/scripts.jsonCreate a .env file in the project root for optional configuration:
# LLM Provider Configuration (optional)
OPENAI_API_KEY=sk-... # OpenAI API key
DEFAULT_LLM_PROVIDER=openai # 'openai' or 'anthropic'
OPENAI_MODEL=gpt-4 # OpenAI model name
CLAUDE_MODEL=claude-3-5-sonnet-20241022 # Claude model name
# Anthropic Alternative (optional)
ANTHROPIC_API_KEY=sk-ant-... # Anthropic API keySecurity Note: Never commit
.envto version control. It's already in.gitignore.
Visit the settings page in the web interface or call:
curl http://localhost:5000/api/debug/api-key-status- Update
data/schema.jsonwith the new field - Update the form in
web/index.html(edit modal) - Modify
web/js/app.jsto handle the new field - Update the table in
web/index.htmlif adding a new column
All styles are in web/css/styles.css. The design uses CSS custom properties (variables) for easy theming:
:root {
--primary-color: #2962ff; /* Blue accent */
--secondary-color: #00bcd4; /* Cyan accent */
--success-color: #4caf50; /* Green (good metrics) */
--warning-color: #ff9800; /* Orange (warnings) */
--danger-color: #f44336; /* Red (errors) */
--dark-bg: #1e1e1e; /* Main background */
--card-bg: #2d2d2d; /* Card background */
/* ... more variables ... */
}To create a light theme: Just change these variables!
For production use, consider using a production WSGI server:
# Install gunicorn
pip install gunicorn
# Run with gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 server:appOr use Waitress (Windows-friendly):
pip install waitress
waitress-serve --port=5000 server:appWhen adding scripts to this repository:
- Follow the directory structure
- Add complete metadata
- Include backtest results for strategies
- Use descriptive tags
- Document your code
- Test in TradingView before committing
This project structure is free to use and modify for personal or commercial purposes.
- Make sure you've installed dependencies:
pip install -r requirements.txt - Check that port 5000 is not already in use
- Try a different port:
python server.py(then edit server.py to change port)
- Ensure the Flask server is running at
http://localhost:5000 - Check that
data/scripts.jsonexists and is valid JSON - Check browser console for errors (F12)
- Verify CORS is not blocking requests
- Confirm Flask server is running
- Check file permissions on
data/scripts.json - Look at server console for error messages
- Ensure
data/backups/directory exists and is writable
- Check the server console for errors
- Refresh the page (F5)
- Verify the script was saved in
data/scripts.json
- Ensure the script type is "strategy"
- Verify numeric values are entered correctly (not text)
- Check that backtest metrics are numbers, not strings
- README.md - This file (project overview and setup)
- QUICKSTART.md - Quick reference for daily use
- API_DOCUMENTATION.md - Complete API reference
- CODE_REVIEW_REPORT.md - Comprehensive code review
- PINE_SCRIPT_STANDARDS.md - Official TradingView standards
- LOGICAL_SANITY_CHECKS.md - Logic validation rules
- SANITY_CHECKS_QUICK_REF.md - Quick reference checklist
- JSON_SCHEMA_GUIDE.md - Metadata schema documentation
- FILE_STRUCTURE_GUIDE.md - Project organization guide
- SCRIPT_DOCUMENTATION_TEMPLATE.md - Template for script docs
- β Full CRUD Operations - Create, Read, Update, Delete scripts via web interface
- β Version Control - Automatic versioning with changelog tracking
- β Automated Code Review - Based on official TradingView standards
- β Auto-Fix System - Quick fixes for common issues
- β LLM Integration - Smart fixes powered by OpenAI/Claude
- β Backup System - Automatic backups with restore capability
- β Search & Filter - Find scripts by name, tags, type, status
- β Backtest Tracking - Record and display strategy performance metrics
- β Export Capabilities - PDF export and clipboard copy for code reviews
- β Pine Script v5/v6 Support - Both versions fully supported
- β Comprehensive Validation - Checks structure, naming, formatting, logic
- β Performance Analysis - Detects anti-patterns and optimization opportunities
- β Logic Sanity Checks - Validates strategy logic for common errors
- β Platform Limitations - Warns about plot limits, loop bounds, etc.
- β Modern Dark Theme - Optimized for code viewing
- β Responsive Design - Works on desktop, tablet, mobile
- β Real-time Updates - Instant feedback on all operations
- β Syntax Highlighting - Beautiful code display
- β Sortable Tables - Sort by any metric
- β Visual Metrics - Color-coded performance indicators
Happy Trading! ππ