TradingView-API icon indicating copy to clipboard operation
TradingView-API copied to clipboard

Alerts feature

Open iosiftalmacel opened this issue 2 years ago • 3 comments

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

iosiftalmacel avatar Mar 17 '22 20:03 iosiftalmacel

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 avatar Mar 20 '22 02:03 mohamad-supangat

@mohamad-supangat How to get current price data ?

revskill10 avatar May 02 '22 19:05 revskill10

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()

brandonros avatar Jun 15 '22 05:06 brandonros