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
访问服务器

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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选