{
“nodes”: [
{
“parameters”: {
“jsCode”: “const { chromium } = require(‘playwright’);\n\nasync function captureChart() {\n const browser = await chromium.launch({\n headless: true,\n args: [‘–no-sandbox’, ‘–disable-setuid-sandbox’, ‘–disable-dev-shm-usage’]\n });\n \n const context = await browser.newContext({\n viewport: { width: 1920, height: 1080 },\n userAgent: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36’\n });\n \n const page = await context.newPage();\n \n try {\n console.log(‘Navigating to TradingView…’);\n await page.goto(‘https://www.tradingview.com/’, { waitUntil: ‘networkidle’ });\n \n // Handle potential cookie banner\n try {\n await page.click(‘text=Accept’, { timeout: 3000 });\n } catch (e) {\n console.log(‘No cookie banner found’);\n }\n \n console.log(‘Clicking sign in…’);\n await page.click(‘text=Sign in’);\n await page.waitForSelector(‘input[name="username"], input[name="email"]’, { timeout: 10000 });\n \n // Login process - replace with your credentials\n const username = $env.TRADINGVIEW_USERNAME || ‘login’;\n const password = $env.TRADINGVIEW_PASSWORD || ‘password’;\n \n await page.fill(‘input[name="username"], input[name="email"]’, username);\n await page.fill(‘input[name="password"]’, password);\n await page.click(‘button[type="submit"], button:has-text("Sign in")’);\n \n console.log(‘Waiting for login completion…’);\n await page.waitForSelector(‘[data-name="header-user-menu"], .tv-header__user-menu’, { timeout: 15000 });\n \n console.log(‘Navigating to BTCUSD chart…’);\n await page.goto(‘Live stock, index, futures, Forex and Bitcoin charts on TradingView’, { waitUntil: ‘networkidle’ });\n \n // Wait for chart to load\n await page.waitForSelector(‘[data-name="legend-source-item"], .chart-container’, { timeout: 20000 });\n \n // Wait for indicators and data to load\n console.log(‘Waiting for chart data to load…’);\n await page.waitForTimeout(5000);\n \n // Take screenshot of the chart area\n console.log(‘Taking screenshot…’);\n let screenshot;\n try {\n const chartElement = await page.locator(‘[data-name="chart-container"], .chart-container’).first();\n screenshot = await chartElement.screenshot({\n type: ‘png’,\n quality: 90\n });\n } catch (e) {\n // Fallback to full page screenshot\n screenshot = await page.screenshot({\n type: ‘png’,\n quality: 90,\n fullPage: false\n });\n }\n \n await browser.close();\n \n console.log(‘Screenshot captured successfully’);\n return {\n screenshot: screenshot.toString(‘base64’),\n timestamp: new Date().toISOString(),\n pair: ‘BTCUSD’,\n timeframe: ‘5m’,\n success: true\n };\n \n } catch (error) {\n await browser.close();\n console.error(‘Error in chart capture:’, error);\n throw new Error(Chart capture failed: ${error.message});\n }\n}\n\nreturn await captureChart();”
},
“id”: “eb7ccd10-603e-4a8f-ac59-3cf130593920”,
“name”: “Playwright Chart Capture1”,
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
-288,
1152
],
“retryOnFail”: true,
“notesInFlow”: true
},
{
“parameters”: {
“conditions”: {
“options”: {
“caseSensitive”: true,
“leftValue”: “”,
“typeValidation”: “strict”
},
“conditions”: [
{
“leftValue”: “={{ $json.analysis.status }}”,
“rightValue”: “SIGNAL_DETECTED”,
“operator”: {
“type”: “string”,
“operation”: “equals”
}
}
],
“combineOperation”: “any”
},
“options”: {}
},
“id”: “4c95885e-645f-4022-be36-feac2650a79d”,
“name”: “Check Signal Detected1”,
“type”: “n8n-nodes-base.if”,
“typeVersion”: 2,
“position”: [
368,
1152
]
},
{
“parameters”: {
“method”: “POST”,
“url”: “=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/sendMessage”,
“sendBody”: true,
“bodyParameters”: {
“parameters”: [
{}
]
},
“options”: {}
},
“id”: “8a87cc0e-520e-457d-9db0-b08d87ad7e11”,
“name”: “Send Telegram Alert1”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
592,
1056
]
},
{
“parameters”: {
“jsCode”: “// Log that no signal was detected\nconsole.log(‘No trading signal detected at:’, $(‘Playwright Chart Capture1’).item.json.timestamp);\nconsole.log(‘Analysis result:’, $(‘Parse AI Response1’).item.json.analysis);\n\nreturn {\n message: ‘No signal detected’,\n timestamp: $(‘Playwright Chart Capture1’).item.json.timestamp,\n analysis: $(‘Parse AI Response1’).item.json.analysis\n};”
},
“id”: “b84e6f0a-b298-4a9a-b952-5381449ba9a0”,
“name”: “Log No Signal1”,
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
592,
1264
]
},
{
“parameters”: {
“model”: {
“__rl”: true,
“mode”: “list”,
“value”: “gpt-4.1-mini”
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“typeVersion”: 1.2,
“position”: [
-128,
1248
],
“id”: “e2b5e628-9911-48ab-958b-8a5785ecf97e”,
“name”: “OpenAI Chat Model1”,
“credentials”: {
“openAiApi”: {
“id”: “Wtn6gBtvaJqs3bMn”,
“name”: “OpenAi account 2”
}
}
},
{
“parameters”: {
“jsCode”: “// Parse the OpenAI response and extract the analysis\nconst openaiResponse = $input.all()[0].json;\nconst messageContent = openaiResponse.choices[0].message.content;\n\nconsole.log(‘Raw AI Response:’, messageContent);\n\n// Try to parse JSON from the response\nlet analysisResult;\ntry {\n // Sometimes the response might have extra text, so we’ll try to extract JSON\n const jsonMatch = messageContent.match(/\{[\s\S]*\}/);\n if (jsonMatch) {\n analysisResult = JSON.parse(jsonMatch[0]);\n } else {\n // Fallback if no JSON found\n analysisResult = {\n status: ‘NO_SIGNAL’,\n details: ‘Failed to parse AI response’,\n levels_detected: ,\n distance_pips: 0,\n current_price_estimate: ‘Unknown’,\n target_level_price: ‘Unknown’\n };\n }\n} catch (error) {\n console.error(‘Error parsing AI response:’, error);\n analysisResult = {\n status: ‘NO_SIGNAL’,\n details: 'Error parsing AI response: ’ + error.message,\n levels_detected: ,\n distance_pips: 0,\n current_price_estimate: ‘Unknown’,\n target_level_price: ‘Unknown’\n };\n}\n\nconsole.log(‘Parsed Analysis Result:’, analysisResult);\n\nreturn {\n analysis: analysisResult,\n raw_response: messageContent,\n timestamp: $(‘Playwright Chart Capture1’).item.json.timestamp\n};”
},
“id”: “0a785ac8-f907-4fec-97a8-fbfed30102ef”,
“name”: “Parse AI Response1”,
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
144,
1152
]
}
],
“connections”: {
“Playwright Chart Capture1”: {
“main”: [
]
},
“Check Signal Detected1”: {
“main”: [
[
{
“node”: “Send Telegram Alert1”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Log No Signal1”,
“type”: “main”,
“index”: 0
}
]
]
},
“OpenAI Chat Model1”: {
“ai_languageModel”: [
]
},
“Parse AI Response1”: {
“main”: [
[
{
“node”: “Check Signal Detected1”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “e7c4b792915e2daf008c27865c5fcdf71e98c4fe45d2645b9492364076b54425”
}
}
Please expand on
- what is not working,
- how it is not working,
- what are you doing,
- what do you expect vs what actually happens
also please share your workflow and your setup information.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.