Mathieu2301 / TradingView-API

📈 Get real-time stocks from TradingView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Technicals are being handled differently

Joeo1 opened this issue · comments

commented

Describe the bug
When I call "TradingView.getIndicator(ID)" and as an ID I use "STD;RSI" it's all good. Same with all indicators starting with STD. But when I try to call the function for session volume profile its ID is "VbPSessions@tv-volumebyprice" it's returning "

{"code":404,"message":"pine_facade failed to get pine source, reason: map[code:404 message:Last version of pine_id=VbPSessions@tv-volumebyprice is not found]"}

Am I using the wrong ID here? If so, where can I find the correct one? Or is there a difference between technicals which explains why one is working and the other is not?

To Reproduce

Works

TradingView.getIndicator('STD;Connors_RSI').then(async (indic) => {

        const IND = new chart.Study(indic);

        IND.onUpdate(() => {
                console.log('Prices periods:', chart.periods);
                console.log('Study periods:', IND.periods);
                client.end();
        });
});

Not working

TradingView.getIndicator('VbPSessions@tv-volumebyprice').then(async (indic) => {

        const IND = new chart.Study(indic);

        IND.onUpdate(() => {
                console.log('Prices periods:', chart.periods);
                console.log('Study periods:', IND.periods);
                client.end();
        });
});

Thanks in advance! - Joe

Built-in indicator instances have to be created using the BuiltInIndicator class.
https://github.com/Mathieu2301/TradingView-API/blob/main/examples/BuiltInIndicator.js

commented

Hi Mathieu,

Thanks for the quick response! So how I can I see the difference between built-ins and regular technicals? I would suspect that RSI for example (STD;RSI) would be a built-in. When I search for indicators using the Tradingview GUI both RSI and Session Volume Profile are under the same heading "technicals".

Anyways, using BuiltInIndicator.js like this:

const chart = new client.Session.Chart();
	
chart.setMarket('BYBIT:BTCUSD', {
	  
        timeframe: 'D',
        range: 3,
        to: Date.now(),
});	
	
const volumeProfile = new TradingView.BuiltInIndicator('VbPSessions@tv-volumebyprice-53');
volumeProfile.setOption('extendPocRight', true);
const VOL = new chart.Study(volumeProfile);

VOL.onUpdate(() => {

        VOL.graphic.horizHists.forEach((h) => {
	    	
               console.log(h);
        });
        client.end();
});

I get the following result. I am not sure how to interpret it though. How do I extract bar time from this? And I would expect only 3 results as I set the range to 3. Is there any way to just get RAW indicator results?

{
  id: 64247,
  priceLow: 56656.125,
  priceHigh: 56767.916666666664,
  rate: [ 40398287.61499415, 43130006.510506965 ],
  firstBarTime: undefined,
  lastBarTime: undefined
}
{
  id: 64248,
  priceLow: 56767.916666666664,
  priceHigh: 56879.708333333336,
  rate: [ 68470447.90111232, 59718048.89529505 ],
  firstBarTime: undefined,
  lastBarTime: undefined
}

... and 50.000 rows more

Thank you for your help! It is really appreciated.
Joe

All indicators are identified with a type:

  • Dividends@tv-basicstudies-177
  • Splits@tv-basicstudies-177
  • Earnings@tv-basicstudies-177
  • VbPSessions@tv-volumebyprice
  • Script@tv-scripting-101!
  • etc...

A pine indicator is identified with the Script@tv-scripting-101! type (or StrategyScript@tv-scripting-101! for strategies) and a PineID:

  • USER;XXXXXXX
  • STD;XXXXXXXX
  • PUB;XXXXXXXX

So built-in indicators doesn't have a PineID.

if you get something like:

firstBarTime: undefined,
lastBarTime: undefined,

You should increase the range.

commented

Alright, thanks I am getting there. Could you elaborate on why increasing the range solves this problem? Really trying to understand how it all works!

Also, when I set option extendPocRight to true:

// Required or not, depending on the indicator
volumeProfile.setOption('extendPocRight', true);

it is still returning results saying extendRight: false

{
        id: 40300,
        endIndex: 2,
        extendLeft: false,
        extendRight: false,
        level: 21909.364583333336,
        startIndex: 4,
        t: 1658733935959
}
{
        id: 40518,
        endIndex: 2,
        extendLeft: false,
        extendRight: false,
        level: 21088.125,
        startIndex: 3,
        t: 1658820335959
}

Any thoughts? Thanks, really appreciating your help here!

  • Joe