MindLayer TradingView MCP Agent

MindLayer TradingView MCP Agent

Connects TradingView's Pine Script indicators with MindLayer's MCP for cryptocurrency trading signals based on RSI and Stochastic RSI analysis.

Category
Visit Server

README

MindLayer TradingView MCP Agent

A powerful integration system that connects TradingView's Pine Script indicators with MindLayer's MCP (Model Context Protocol) for advanced cryptocurrency trading signals based on RSI and Stochastic RSI.

Overview

This system consists of three main components:

  1. Pine Script Indicator: A TradingView indicator that analyzes RSI and Stochastic RSI to generate buy/sell signals.
  2. MCP Agent: A Python application that processes these signals and communicates with MCP-enabled systems.
  3. REST API: An HTTP API that allows programmatic access to all MCP agent functionality.

Features

  • 📊 RSI & Stochastic RSI Analysis: Generates signals based on these powerful momentum indicators
  • 🔄 Multi-Timeframe Analysis: Confirms signals using higher timeframe data
  • 📱 Real-time Alerts: Sends alerts via TradingView's webhook system
  • 🤖 MCP Integration: Seamlessly integrates with MindLayer's Model Context Protocol
  • 📈 Adaptive Confidence Levels: Each signal includes a strength indicator (1-5)
  • 🛡️ Risk Management: Configurable risk profiles based on your trading style
  • 🌐 RESTful API: Access all functionality programmatically via HTTP API

Setup Instructions

TradingView Indicator Setup

  1. Log in to your TradingView account
  2. Go to Pine Editor
  3. Create a new indicator and paste the contents of MindLayer_MCP_Signal.pine
  4. Save and add to chart
  5. Configure the indicator settings according to your preferences

System Setup

  1. Clone this repository

  2. Install required dependencies:

    pip install -r requirements.txt
    
  3. Configure your settings (edit config.py or use environment variables)

  4. Start the system using the launcher script:

    # Run just the MCP agent
    python run.py agent
    
    # Run just the API server (which includes the agent)
    python run.py api
    
    # Run both the agent and API server separately (advanced)
    python run.py both
    

Command Line Options

The run.py script accepts several command-line arguments:

# Set custom API port
python run.py api --port 8080

# Set custom webhook port
python run.py agent --webhook-port 9000

# Run in debug mode
python run.py api --debug

# Display help
python run.py --help

TradingView Alert Setup

  1. Open your chart with the MindLayer MCP Signal indicator
  2. Right-click on the indicator and select "Add Alert"
  3. Set condition to trigger on "MindLayer MCP Buy Signal" or "MindLayer MCP Sell Signal"
  4. In the webhook URL field, enter your MCP agent's webhook URL (e.g., http://your-server:8000) or the API webhook endpoint (e.g., http://your-server:5000/api/webhook)
  5. In the message field, paste the following JSON template:
    {
        "ticker": "{{ticker}}",
        "type": "{{strategy.order.action}}",
        "confidence": {{plot("Buy Signal")}} or {{plot("Sell Signal")}},
        "price": {{close}},
        "rsi": {{rsi}},
        "stoch": {{stoch}},
        "htf_rsi": {{plot("HTF RSI")}},
        "htf_stoch": {{plot("HTF Stoch")}}
    }
    
  6. Save the alert

Configuration

Environment Variables

You can configure the system using environment variables (create a .env file):

# API Configuration
API_KEY=your_api_key_here
API_SECRET=your_api_secret_here

# Webhook Configuration
WEBHOOK_SECRET=your_webhook_secret_here
WEBHOOK_PORT=8000

# API Configuration
API_PORT=5000
DEBUG=false

# MCP Connection Settings
MCP_API_URL=https://api.mindlayer.io/v1
MCP_WEBSOCKET_URL=wss://api.mindlayer.io/ws

# Trading Configuration
TRADING_ENABLED=false
RISK_TOLERANCE=moderate
MIN_CONFIDENCE=3

# RSI/Stochastic RSI Configuration
RSI_OVERSOLD=30
RSI_OVERBOUGHT=70
STOCH_OVERSOLD=20
STOCH_OVERBOUGHT=80

Pine Script Customization

The TradingView indicator is highly customizable:

  • Risk Profile: Conservative, Moderate, or Aggressive
  • RSI Parameters: Change length and overbought/oversold thresholds
  • Stochastic RSI Parameters: Adjust K, D periods and thresholds
  • Visual Settings: Customize colors and display options

Signal Interpretation

Buy Signals

  • Strong Buy: Green arrow with high confidence rating (4-5)
  • Moderate Buy: Light green arrow with medium confidence rating (2-3)
  • Weak Buy: Dotted green arrow with low confidence rating (1)

Sell Signals

  • Strong Sell: Red arrow with high confidence rating (4-5)
  • Moderate Sell: Light red arrow with medium confidence rating (2-3)
  • Weak Sell: Dotted red arrow with low confidence rating (1)

How It Works

  1. The Pine Script indicator analyzes price action using RSI and Stochastic RSI
  2. When conditions meet your configured criteria, it displays a buy/sell signal on the chart
  3. TradingView sends an alert via webhook to your MCP agent or API
  4. The MCP agent processes the signal and communicates with MCP-enabled systems
  5. (Optional) The agent can execute trades based on these signals

REST API Documentation

The system includes a comprehensive REST API for programmatic access to all functionality.

API Endpoints

Signal Management

  • GET /api/signals - Get all trading signals
  • GET /api/signals?symbol=BTCUSDT - Get signals for a specific symbol
  • POST /api/signals - Manually create a new signal

Indicator Values

  • GET /api/indicators - Get all indicator values
  • GET /api/indicators?symbol=BTCUSDT - Get indicator values for a specific symbol

Agent Control

  • GET /api/status - Get current agent status
  • POST /api/start - Start the MCP agent
  • POST /api/stop - Stop the MCP agent

Configuration

  • GET /api/config - Get current configuration
  • PUT /api/config - Update configuration settings

Webhook

  • POST /api/webhook - Receive webhook from TradingView

API Documentation

  • GET /api/docs - Get detailed API documentation

API Usage Examples

Get Current Agent Status

curl http://localhost:5000/api/status

Get All Signals

curl http://localhost:5000/api/signals

Create a Manual Signal

curl -X POST http://localhost:5000/api/signals \
  -H "Content-Type: application/json" \
  -d '{
    "symbol": "BTCUSDT",
    "type": "BUY",
    "price": 50000.0,
    "confidence": 4,
    "rsi": 25.5,
    "stoch": 15.2
  }'

Update Configuration

curl -X PUT http://localhost:5000/api/config \
  -H "Content-Type: application/json" \
  -d '{
    "trading_enabled": true,
    "min_confidence": 4,
    "rsi_oversold": 25
  }'

Requirements

  • Python 3.7+
  • TradingView account (Pro plan recommended for webhook alerts)
  • Server or cloud instance to run the MCP agent and API (if using webhooks)

System Architecture

┌─────────────────┐     ┌──────────────────┐     ┌────────────────┐
│   TradingView   │     │   MCP Agent or   │     │   MCP/Trading  │
│   Pine Script   │────▶│    API Server    │────▶│     System     │
└─────────────────┘     └──────────────────┘     └────────────────┘
                               ▲     ▲
                               │     │
                               │     │
                        ┌──────┘     └────────┐
                        │                     │
                  ┌───────────┐       ┌─────────────┐
                  │ External  │       │   Manual    │
                  │   API     │       │  Commands   │
                  │  Clients  │       │ (CLI/Config)│
                  └───────────┘       └─────────────┘

Best Practices

  • Always test thoroughly in a paper trading environment before using real funds
  • Combine these signals with other analysis and risk management techniques
  • Higher timeframe signals tend to be more reliable than very short timeframes
  • Consider market conditions that might impact signal reliability
  • Secure your API server behind proper authentication if exposing to the internet

Support

If you encounter issues or have questions, please open an issue on this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

Trading cryptocurrency involves substantial risk. Past performance of this indicator does not guarantee future results. Always use proper risk management and never trade with funds you cannot afford to lose.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured