Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve chart pattern studies example missing #220

Open
mac2000 opened this issue Oct 26, 2023 · 4 comments
Open

Retrieve chart pattern studies example missing #220

mac2000 opened this issue Oct 26, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@mac2000
Copy link

mac2000 commented Oct 26, 2023

By chart patterns I mean this ones:

image

Restriction:

  • they are available only for paid plans
  • TradingView.searchIndicator somehow does not find them
  • from ws messages on trading view it seems that identifiers are something like BearishFlagCP@tv-chart_patterns-26 but attempt to retrieve it fails with error that indicator is undefined
  • also from indicator search in inspector I see that its data id attribute is BearishFlagCP@tv-chart_patterns
image image

How I tried to retrieve it:

import TradingView from '@mathieuc/tradingview';

var username = 'hello'
var password = 'world'

var user = await TradingView.loginUser(username, password, false)

var client = new TradingView.Client({
  signature: user.signature,
  token: user.token,
});
var chart = new client.Session.Chart();
chart.setMarket('NYSE:VOO');

var indicator = await TradingView.getIndicator('BearishFlagCP@tv-chart_patterns')

var study = new chart.Study(indicator)
console.log(`Retrieving ${indicator.description}`)
study.onUpdate(() => {
  console.log(`Retrieved ${indicator.description}`)
  console.log(study.periods)
})

Notes:

  • chart patterns are not usual pine scripts, not sure if thats relates at all because after end it is still study that is just being rendered
  • indicator is searchable even in anonymous session from web site, it just not works for non paid accounts

Wondering if I am missing something, willing to create one more example while have paid subscription, because I bed I am not a first one and not last one who is struggling with this

@mac2000 mac2000 added the enhancement New feature or request label Oct 26, 2023
@mac2000
Copy link
Author

mac2000 commented Oct 26, 2023

Here is a dump of ws messages with single study

create_study

raw
~m~689~m~{"m":"create_study","p":["cs_J9dHOapfH83N","st11","st1","sds_1","HeadAndShouldersCP@tv-chart_patterns-26",{"Source":"ohlc4","Patterns":"All","Price Targets":"All","Trend Height":50,"Minimum required difference":20,"Maximum slope of the neck line":15,"Shoulders height maximum difference":30,"Shoulders width maximum difference":60,"In Progress":true,"Color Graph":"rgba(156, 39, 176, 1)","Line Style":"Solid","Width Graph":2,"Color Extend Line":"rgba(156, 39, 176, 1)","Neck Line Style":"Dotted","Width Neck Line":2,"Background":true,"Background color":"rgba(156, 39, 176, 0.15)","Labels":true,"Label Background color":"rgba(156, 39, 176, 1)","Label Text color":"rgba(255, 255, 255, 1)"}]}
json
{
  "m": "create_study",
  "p": [
    "cs_J9dHOapfH83N",
    "st11",
    "st1",
    "sds_1",
    "HeadAndShouldersCP@tv-chart_patterns-26",
    {
      "Source": "ohlc4",
      "Patterns": "All",
      "Price Targets": "All",
      "Trend Height": 50,
      "Minimum required difference": 20,
      "Maximum slope of the neck line": 15,
      "Shoulders height maximum difference": 30,
      "Shoulders width maximum difference": 60,
      "In Progress": true,
      "Color Graph": "rgba(156, 39, 176, 1)",
      "Line Style": "Solid",
      "Width Graph": 2,
      "Color Extend Line": "rgba(156, 39, 176, 1)",
      "Neck Line Style": "Dotted",
      "Width Neck Line": 2,
      "Background": true,
      "Background color": "rgba(156, 39, 176, 0.15)",
      "Labels": true,
      "Label Background color": "rgba(156, 39, 176, 1)",
      "Label Text color": "rgba(255, 255, 255, 1)"
    }
  ]
}

study_loading

raw
~m~97~m~{"m":"study_loading","p":["cs_J9dHOapfH83N","st11","s5_st1"],"t":1698306758,"t_ms":1698306758285}
json
{
  "m": "study_loading",
  "p": ["cs_J9dHOapfH83N", "st11", "s5_st1"],
  "t": 1698306758,
  "t_ms": 1698306758285
}

du, study_completed

raw
~m~3065~m~{"m":"du","p":["cs_J9dHOapfH83N",{"st11":{"node":"ams1-32-studies-charts-pro-2-runner-2","st":[{"i":299,"v":[1698240600.0,0.0,0.0]}],"ns":{"d":"{\"graphicsCmds\":{\"create\":{\"dwglabels\":[{\"data\":[{\"id\":8,\"x\":2,\"y\":221.42,\"yl\":\"ab\",\"t\":\"Left Shoulder\",\"st\":\"lcn\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"\"},{\"id\":9,\"x\":4,\"y\":228.965,\"yl\":\"ab\",\"t\":\"Head\",\"st\":\"lcn\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"\"},{\"id\":10,\"x\":6,\"y\":225.78,\"yl\":\"ab\",\"t\":\"Right Shoulder\",\"st\":\"lcn\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"\"},{\"id\":22,\"x\":8,\"y\":201.26,\"yl\":\"pr\",\"t\":\"Target\",\"st\":\"luprg\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"Head And Shoulders\\nPrice: 201.26\\nStatus: Awaiting\"}],\"styleId\":\"labels\"}],\"dwglinefills\":[{\"data\":[{\"id\":13,\"line1\":11,\"line2\":12,\"ci\":6.49078684E8},{\"id\":16,\"line1\":14,\"line2\":15,\"ci\":6.49078684E8},{\"id\":19,\"line1\":17,\"line2\":18,\"ci\":6.49078684E8}],\"styleId\":\"lineFills\"}],\"dwglines\":[{\"data\":[{\"id\":1,\"x1\":0,\"y1\":200.2,\"x2\":2,\"y2\":221.42,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":2,\"x1\":2,\"y1\":221.42,\"x2\":3,\"y2\":214.14,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":3,\"x1\":3,\"y1\":214.14,\"x2\":4,\"y2\":228.965,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":4,\"x1\":4,\"y1\":228.965,\"x2\":5,\"y2\":215.03,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":5,\"x1\":5,\"y1\":215.03,\"x2\":6,\"y2\":225.78,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":6,\"x1\":6,\"y1\":225.78,\"x2\":7,\"y2\":215.57,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":7,\"x1\":7,\"y1\":215.56872231260166,\"x2\":1,\"y2\":213.7695757124901,\"ex\":\"n\",\"st\":\"dot\",\"ci\":4.289734556E9,\"w\":2},{\"id\":11,\"x1\":1,\"y1\":213.7695757124901,\"x2\":2,\"y2\":221.42,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":12,\"x1\":3,\"y1\":214.14,\"x2\":2,\"y2\":221.42,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":14,\"x1\":3,\"y1\":214.14,\"x2\":4,\"y2\":228.965,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":15,\"x1\":5,\"y1\":215.03,\"x2\":4,\"y2\":228.965,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":17,\"x1\":5,\"y1\":215.03,\"x2\":6,\"y2\":225.78,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":18,\"x1\":7,\"y1\":215.56872231260166,\"x2\":6,\"y2\":225.78,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":20,\"x1\":7,\"y1\":215.57,\"x2\":7,\"y2\":201.26,\"ex\":\"n\",\"st\":\"dot\",\"ci\":4.289734556E9,\"w\":2},{\"id\":21,\"x1\":7,\"y1\":201.26,\"x2\":8,\"y2\":201.26,\"ex\":\"n\",\"st\":\"dot\",\"ci\":4.289734556E9,\"w\":2}],\"styleId\":\"lines\"}]},\"erase\":[{\"action\":\"all\"}]}}","indexes":[179,199,209,214,236,252,262,275,300]},"t":"s5_st1"}}]}~m~99~m~{"m":"study_completed","p":["cs_J9dHOapfH83N","st11","s5_st1"],"t":1698306758,"t_ms":1698306758379}
json
[
  {
    "m": "du",
    "p": [
      "cs_J9dHOapfH83N",
      {
        "st11": {
          "node": "ams1-32-studies-charts-pro-2-runner-2",
          "st": [{ "i": 299, "v": [1698240600.0, 0.0, 0.0] }],
          "ns": {
            "d": "{\"graphicsCmds\":{\"create\":{\"dwglabels\":[{\"data\":[{\"id\":8,\"x\":2,\"y\":221.42,\"yl\":\"ab\",\"t\":\"Left Shoulder\",\"st\":\"lcn\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"\"},{\"id\":9,\"x\":4,\"y\":228.965,\"yl\":\"ab\",\"t\":\"Head\",\"st\":\"lcn\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"\"},{\"id\":10,\"x\":6,\"y\":225.78,\"yl\":\"ab\",\"t\":\"Right Shoulder\",\"st\":\"lcn\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"\"},{\"id\":22,\"x\":8,\"y\":201.26,\"yl\":\"pr\",\"t\":\"Target\",\"st\":\"luprg\",\"ci\":4.289734556E9,\"tci\":4.294967295E9,\"sz\":\"normal\",\"ta\":\"center\",\"tt\":\"Head And Shoulders\\nPrice: 201.26\\nStatus: Awaiting\"}],\"styleId\":\"labels\"}],\"dwglinefills\":[{\"data\":[{\"id\":13,\"line1\":11,\"line2\":12,\"ci\":6.49078684E8},{\"id\":16,\"line1\":14,\"line2\":15,\"ci\":6.49078684E8},{\"id\":19,\"line1\":17,\"line2\":18,\"ci\":6.49078684E8}],\"styleId\":\"lineFills\"}],\"dwglines\":[{\"data\":[{\"id\":1,\"x1\":0,\"y1\":200.2,\"x2\":2,\"y2\":221.42,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":2,\"x1\":2,\"y1\":221.42,\"x2\":3,\"y2\":214.14,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":3,\"x1\":3,\"y1\":214.14,\"x2\":4,\"y2\":228.965,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":4,\"x1\":4,\"y1\":228.965,\"x2\":5,\"y2\":215.03,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":5,\"x1\":5,\"y1\":215.03,\"x2\":6,\"y2\":225.78,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":6,\"x1\":6,\"y1\":225.78,\"x2\":7,\"y2\":215.57,\"ex\":\"n\",\"st\":\"sol\",\"ci\":4.289734556E9,\"w\":2},{\"id\":7,\"x1\":7,\"y1\":215.56872231260166,\"x2\":1,\"y2\":213.7695757124901,\"ex\":\"n\",\"st\":\"dot\",\"ci\":4.289734556E9,\"w\":2},{\"id\":11,\"x1\":1,\"y1\":213.7695757124901,\"x2\":2,\"y2\":221.42,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":12,\"x1\":3,\"y1\":214.14,\"x2\":2,\"y2\":221.42,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":14,\"x1\":3,\"y1\":214.14,\"x2\":4,\"y2\":228.965,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":15,\"x1\":5,\"y1\":215.03,\"x2\":4,\"y2\":228.965,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":17,\"x1\":5,\"y1\":215.03,\"x2\":6,\"y2\":225.78,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":18,\"x1\":7,\"y1\":215.56872231260166,\"x2\":6,\"y2\":225.78,\"ex\":\"n\",\"st\":\"sol\",\"ci\":0.0,\"w\":2},{\"id\":20,\"x1\":7,\"y1\":215.57,\"x2\":7,\"y2\":201.26,\"ex\":\"n\",\"st\":\"dot\",\"ci\":4.289734556E9,\"w\":2},{\"id\":21,\"x1\":7,\"y1\":201.26,\"x2\":8,\"y2\":201.26,\"ex\":\"n\",\"st\":\"dot\",\"ci\":4.289734556E9,\"w\":2}],\"styleId\":\"lines\"}]},\"erase\":[{\"action\":\"all\"}]}}",
            "indexes": [179, 199, 209, 214, 236, 252, 262, 275, 300]
          },
          "t": "s5_st1"
        }
      }
    ]
  },
  {
    "m": "study_completed",
    "p": ["cs_J9dHOapfH83N", "st11", "s5_st1"],
    "t": 1698306758,
    "t_ms": 1698306758379
  }
]

@mac2000
Copy link
Author

mac2000 commented Oct 26, 2023

Tried to debug whats being called on tv

I see that whenever we are adding some well known indicator _createStudyOnServer is being called

image

and from its properties we can retrieve indicator id like so: this._inputs.pineId so for macd we have STD;MACD

but for this patterns there is no such property 🤷‍♂️

just for future reference here are identifiers of head and shoulders I have catched

_id: "c390ZF"
_instanceId: "9FU3Bh"
_studyId: "st13"
_studyName: "HeadAndShouldersCP@tv-chart_patterns-26"

From what I understand to get this we need low level call passing this identifiers rather than pineId

@mac2000
Copy link
Author

mac2000 commented Oct 26, 2023

Further check agains volume indicator, from what I understand from sources we should use built in indicator rahter than pine indicator. There are some predefined default for well know indicators here

While in debug did tried to add indicator and check what I have in object

_studyName: "Volume@tv-basicstudies-226"

almost same as in defaults, so I do believe thats a starting point

inputs are

{
    "length": 20,
    "col_prev_close": false
}

and here is what we have in defaults for build in indicators

const defaultValues = {
  'Volume@tv-basicstudies-144': {
    length: 20,
    col_prev_close: false,
  },

constructor of indicator takes name so in case of volume it will be Volume@tv-basicstudies-144

in case of head and shoulders

name: HeadAndShouldersCP@tv-chart_patterns-26
inputs:

{
    "Source": "ohlc4",
    "Patterns": "All",
    "Price Targets": "All",
    "Trend Height": 50,
    "Minimum required difference": 20,
    "Maximum slope of the neck line": 15,
    "Shoulders height maximum difference": 30,
    "Shoulders width maximum difference": 60,
    "In Progress": true,
    "Color Graph": "rgba(156, 39, 176, 1)",
    "Line Style": "Solid",
    "Width Graph": 2,
    "Color Extend Line": "rgba(156, 39, 176, 1)",
    "Neck Line Style": "Dotted",
    "Width Neck Line": 2,
    "Background": true,
    "Background color": "rgba(156, 39, 176, 0.15)",
    "Labels": true,
    "Label Background color": "rgba(156, 39, 176, 1)",
    "Label Text color": "rgba(255, 255, 255, 1)"
}

so now the question is how to instantiate it and pass to the chart

@mac2000
Copy link
Author

mac2000 commented Oct 26, 2023

heh, so i have ended up facing #202 so far the attempt is:

import TradingView from '@mathieuc/tradingview';

var indicator = new TradingView.BuiltInIndicator('HeadAndShouldersCP@tv-chart_patterns-26');

var client = new TradingView.Client({
  token: '*********' // "sessionId" cookie,
});
var chart = new client.Session.Chart();
chart.setMarket('AMEX:VTI', { timeframe: 'D', range: 252 });

// indicator.setOption('first_bar_time', Date.now() - 10 ** 8); // aka example of how to set options

var study = new chart.Study(indicator)
console.log(`Retrieving ${indicator.description}`)
study.onUpdate(() => {
  console.log(`Retrieved ${indicator.description}`)
  console.log(study.periods)
  console.log(study.graphic)
})

going to check:

  • if we can login via pupeteer like tools
  • if we can listen for socket events

technically issue may be closed, because it seems that I was mistaken and technically example of how to use buildin indicators is present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants