TradingView-API
TradingView-API copied to clipboard
Alerts feature
Hey first of all thank you very much for this awesome library. I was wondering if you could add the ability to add alerts at specific prices on different symbols and then get notified when they reach that price.
Thanks
you can write custom alert script example in my bot for getting macd cross:
TradingView.getIndicator("STD;MACD").then(async (indic) => {
console.log(`Loading '${indic.description}' study...`);
const STD = new chart.Study(indic);
STD.onUpdate(async () => {
console.log("Prices periods:", chart.periods);
console.log("Study periods:", STD.periods);
const macdData = STD.periods;
let previous_macd, previous_signal, current_macd, current_signal;
previous_macd = macdData[1].MACD;
previous_signal = macdData[1].Signal;
current_macd = macdData[0].MACD;
current_signal = macdData[0].Signal;
let is_hot = false,
is_cold = false;
is_hot = previous_macd < previous_signal && current_macd > current_signal;
is_cold = previous_macd > previous_signal && current_macd < current_signal;
console.log({
current_macd,
current_signal,
previous_macd,
previous_signal,
});
// client.end();
});
});
@mohamad-supangat How to get current price data ?
const TradingView = require('@mathieuc/tradingview')
const run = async () => {
const client = new TradingView.Client()
// quote session
const quoteSession = new client.Session.Quote()
const quoteSessionMarket = new quoteSession.Market('CME_MINI_DL:ES1!')
quoteSessionMarket.onData(async (data) => {
console.log(`Quote: ${data.lp_time} ${data.lp}`)
})
// chart
const chart = new client.Session.Chart()
chart.setMarket('CME_MINI_DL:ES1!', {
timeframe: '1', // 1 minute
range: 100 // 100 minutes
})
chart.onUpdate(() => {
const latestPeriod = chart.periods[0]
console.log(`OHLC: ${latestPeriod.time} ${latestPeriod.open} ${latestPeriod.max} ${latestPeriod.min} ${latestPeriod.close} ${latestPeriod.volume}`)
})
// indicator
const rsiIndicator = await TradingView.getIndicator('STD;RSI')
rsiIndicator.setOption('in_0', 14)
rsiIndicator.setOption('in_1', 'close')
rsiIndicator.setOption('in_2', 'SMA')
rsiIndicator.setOption('in_3', 14)
rsiIndicator.setOption('in_4', 124)
rsiIndicator.setOption('in_5', '')
rsiIndicator.setOption('in_6', true)
// study
const chartStudy = new chart.Study(rsiIndicator)
chartStudy.onUpdate(() => {
const latestPeriod = chartStudy.periods[0]
console.log(`RSI: ${latestPeriod['$time']} ${latestPeriod['RSI']}`)
})
}
run()